@microcosmmoney/auth-core 1.0.2 → 1.0.3

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.
@@ -5,5 +5,6 @@ export declare class ApiClient {
5
5
  fetch<T>(path: string, options?: RequestInit): Promise<T>;
6
6
  get<T>(path: string): Promise<T>;
7
7
  post<T>(path: string, body: unknown): Promise<T>;
8
+ put<T>(path: string, body: unknown): Promise<T>;
8
9
  patch<T>(path: string, body: unknown): Promise<T>;
9
10
  }
@@ -47,6 +47,12 @@ class ApiClient {
47
47
  body: JSON.stringify(body),
48
48
  });
49
49
  }
50
+ async put(path, body) {
51
+ return this.fetch(path, {
52
+ method: 'PUT',
53
+ body: JSON.stringify(body),
54
+ });
55
+ }
50
56
  async patch(path, body) {
51
57
  return this.fetch(path, {
52
58
  method: 'PATCH',
package/dist/index.d.ts CHANGED
@@ -4,4 +4,4 @@ export { Storage, STORAGE_KEYS } from './storage';
4
4
  export { ApiClient } from './api-client';
5
5
  export { MicrocosmAPI } from './open-api';
6
6
  export type { MicrocosmAPIConfig } from './open-api';
7
- export type { MicrocosmAuthConfig, ResolvedConfig, User, TokenData, AuthState, LoginOptions, TokenExchangeResponse, UserProfileResponse, ApiResponse, MCDBalance, MCCBalance, MCCPrice, Wallet, TokenPortfolio, MCCLock, MiningRatio, MiningDistribution, BuybackQuote, BuybackRecord, Territory, TerritorySummary, TerritoryStats, TerritoryMember, Proposal, ProposalDetail, VoteResult, VotePower, AuctionBid, MCDTransaction, MCDReward, } from './types';
7
+ export type { MicrocosmAuthConfig, ResolvedConfig, User, TokenData, AuthState, LoginOptions, TokenExchangeResponse, UserProfileResponse, ApiResponse, MCDBalance, MCCBalance, MCCPrice, Wallet, TokenPortfolio, MCCLock, MiningRatio, MiningDistribution, BuybackQuote, BuybackRecord, Territory, TerritorySummary, TerritoryStats, TerritoryMember, Proposal, ProposalDetail, VoteResult, VotePower, AuctionBid, MCDTransaction, MCDReward, MiningRequest, MiningConfirmData, MiningRequestResult, MiningConfig, BuybackRecordInput, ReincarnationConfig, MCCHistoryRecord, CycleHistory, AuctionHistory, } from './types';
@@ -15,6 +15,15 @@ export declare class MicrocosmAPI {
15
15
  getBalance: (token: string) => Promise<ApiRes<any>>;
16
16
  getBalanceByAddress: (address: string) => Promise<ApiRes<any>>;
17
17
  getLocks: (token: string) => Promise<ApiRes<any>>;
18
+ getTransactions: (token: string, params?: {
19
+ page?: number;
20
+ page_size?: number;
21
+ }) => Promise<ApiRes<any>>;
22
+ getHistory: (token: string, params?: {
23
+ tx_type?: string;
24
+ page?: number;
25
+ page_size?: number;
26
+ }) => Promise<ApiRes<any>>;
18
27
  getHolders: () => Promise<ApiRes<any>>;
19
28
  getMiningHistory: (days?: number) => Promise<ApiRes<any>>;
20
29
  };
@@ -45,6 +54,18 @@ export declare class MicrocosmAPI {
45
54
  page?: number;
46
55
  page_size?: number;
47
56
  }) => Promise<ApiRes<any>>;
57
+ record: (token: string, data: {
58
+ tx_signature: string;
59
+ wallet_address: string;
60
+ mcc_amount: number;
61
+ usdc_amount: number;
62
+ stablecoin?: string;
63
+ }) => Promise<ApiRes<any>>;
64
+ getConfig: () => Promise<ApiRes<any>>;
65
+ getCycleHistory: (params?: {
66
+ page?: number;
67
+ page_size?: number;
68
+ }) => Promise<ApiRes<any>>;
48
69
  };
49
70
  readonly mining: {
50
71
  getRecords: (token: string, params?: {
@@ -58,6 +79,32 @@ export declare class MicrocosmAPI {
58
79
  page?: number;
59
80
  page_size?: number;
60
81
  }) => Promise<ApiRes<any>>;
82
+ createRequest: (token: string, data: {
83
+ mcc_amount: number;
84
+ stablecoin?: string;
85
+ wallet_address: string;
86
+ }) => Promise<ApiRes<any>>;
87
+ confirm: (token: string, data: {
88
+ request_id: string;
89
+ tx_signature: string;
90
+ mcc_amount: number;
91
+ usdc_amount: number;
92
+ stablecoin_type?: string;
93
+ }) => Promise<ApiRes<any>>;
94
+ publicRequest: (data: {
95
+ wallet_address: string;
96
+ mcc_amount: number;
97
+ stablecoin?: string;
98
+ }) => Promise<ApiRes<any>>;
99
+ publicVerify: (data: {
100
+ request_id: string;
101
+ tx_signature: string;
102
+ }) => Promise<ApiRes<any>>;
103
+ getHistory: (token: string, params?: {
104
+ limit?: number;
105
+ offset?: number;
106
+ }) => Promise<ApiRes<any>>;
107
+ getConfig: () => Promise<ApiRes<any>>;
61
108
  };
62
109
  readonly users: {
63
110
  getProfile: (token: string) => Promise<ApiRes<any>>;
@@ -91,6 +138,12 @@ export declare class MicrocosmAPI {
91
138
  page?: number;
92
139
  page_size?: number;
93
140
  }) => Promise<ApiRes<any>>;
141
+ update: (token: string, id: string, data: {
142
+ unit_name?: string;
143
+ description?: string;
144
+ image_url?: string;
145
+ }) => Promise<ApiRes<any>>;
146
+ updateName: (token: string, id: string, name: string, force?: boolean) => Promise<ApiRes<any>>;
94
147
  };
95
148
  readonly territory: {
96
149
  getCollection: () => Promise<ApiRes<any>>;
@@ -122,8 +175,15 @@ export declare class MicrocosmAPI {
122
175
  getActive: () => Promise<ApiRes<any>>;
123
176
  getDetails: (id: number) => Promise<ApiRes<any>>;
124
177
  getBids: (id: number) => Promise<ApiRes<any>>;
178
+ getUserBids: (wallet: string) => Promise<ApiRes<any>>;
179
+ getUserAuctions: (wallet: string) => Promise<ApiRes<any>>;
125
180
  getMyBids: (token: string) => Promise<ApiRes<any>>;
126
181
  placeBid: (token: string, auctionId: number, bidAmount: number) => Promise<ApiRes<any>>;
182
+ prepareCancelBid: (token: string, auctionId: number) => Promise<ApiRes<any>>;
183
+ getHistory: (params?: {
184
+ page?: number;
185
+ page_size?: number;
186
+ }) => Promise<ApiRes<any>>;
127
187
  };
128
188
  readonly techTree: {
129
189
  getConfig: () => Promise<ApiRes<any>>;
package/dist/open-api.js CHANGED
@@ -18,7 +18,7 @@ async function request(baseUrl, path, token) {
18
18
  throw new Error(data.detail || `API error ${res.status}`);
19
19
  return data;
20
20
  }
21
- async function postRequest(baseUrl, path, body, token) {
21
+ async function mutateRequest(baseUrl, method, path, body, token) {
22
22
  const headers = {
23
23
  'Accept': 'application/json',
24
24
  'Content-Type': 'application/json',
@@ -26,7 +26,7 @@ async function postRequest(baseUrl, path, body, token) {
26
26
  if (token)
27
27
  headers['Authorization'] = `Bearer ${token}`;
28
28
  const res = await fetch(`${baseUrl}${path}`, {
29
- method: 'POST',
29
+ method,
30
30
  headers,
31
31
  body: JSON.stringify(body),
32
32
  });
@@ -35,6 +35,12 @@ async function postRequest(baseUrl, path, body, token) {
35
35
  throw new Error(data.detail || `API error ${res.status}`);
36
36
  return data;
37
37
  }
38
+ async function postRequest(baseUrl, path, body, token) {
39
+ return mutateRequest(baseUrl, 'POST', path, body, token);
40
+ }
41
+ async function putRequest(baseUrl, path, body, token) {
42
+ return mutateRequest(baseUrl, 'PUT', path, body, token);
43
+ }
38
44
  class MicrocosmAPI {
39
45
  constructor(config) {
40
46
  this.mcc = {
@@ -43,6 +49,17 @@ class MicrocosmAPI {
43
49
  getBalance: (token) => request(this.base, '/mcc/balance', token),
44
50
  getBalanceByAddress: (address) => request(this.base, `/mcc/balance/${address}`),
45
51
  getLocks: (token) => request(this.base, '/mcc/locks', token),
52
+ getTransactions: (token, params) => {
53
+ const p = params || {};
54
+ return request(this.base, `/mcc/transactions?page=${p.page || 1}&page_size=${p.page_size || 20}`, token);
55
+ },
56
+ getHistory: (token, params) => {
57
+ const p = params || {};
58
+ let qs = `?page=${p.page || 1}&page_size=${p.page_size || 20}`;
59
+ if (p.tx_type)
60
+ qs += `&tx_type=${p.tx_type}`;
61
+ return request(this.base, `/mcc/history${qs}`, token);
62
+ },
46
63
  getHolders: () => request(this.base, '/reincarnation/holders'),
47
64
  getMiningHistory: (days = 30) => request(this.base, `/reincarnation/mining-history?days=${days}`),
48
65
  };
@@ -78,6 +95,12 @@ class MicrocosmAPI {
78
95
  const p = params || {};
79
96
  return request(this.base, `/reincarnation/user-history?page=${p.page || 1}&page_size=${p.page_size || 20}`, token);
80
97
  },
98
+ record: (token, data) => postRequest(this.base, '/reincarnation/record', data, token),
99
+ getConfig: () => request(this.base, '/reincarnation/config'),
100
+ getCycleHistory: (params) => {
101
+ const p = params || {};
102
+ return request(this.base, `/reincarnation/cycle-history?page=${p.page || 1}&page_size=${p.page_size || 20}`);
103
+ },
81
104
  };
82
105
  this.mining = {
83
106
  getRecords: (token, params) => {
@@ -91,6 +114,15 @@ class MicrocosmAPI {
91
114
  const p = params || {};
92
115
  return request(this.base, `/mining/distribution?page=${p.page || 1}&page_size=${p.page_size || 20}`, token);
93
116
  },
117
+ createRequest: (token, data) => postRequest(this.base, '/mining/request', data, token),
118
+ confirm: (token, data) => postRequest(this.base, '/mining/confirm', data, token),
119
+ publicRequest: (data) => postRequest(this.base, '/mining/public/request', data),
120
+ publicVerify: (data) => postRequest(this.base, '/mining/public/verify', data),
121
+ getHistory: (token, params) => {
122
+ const p = params || {};
123
+ return request(this.base, `/mining/history?limit=${p.limit || 20}&offset=${p.offset || 0}`, token);
124
+ },
125
+ getConfig: () => request(this.base, '/mining/config'),
94
126
  };
95
127
  this.users = {
96
128
  getProfile: (token) => request(this.base, '/users/me', token),
@@ -127,6 +159,8 @@ class MicrocosmAPI {
127
159
  const p = params || {};
128
160
  return request(this.base, `/territories/${id}/member-ranking?page=${p.page || 1}&page_size=${p.page_size || 20}`, token);
129
161
  },
162
+ update: (token, id, data) => putRequest(this.base, `/territories/${id}`, data, token),
163
+ updateName: (token, id, name, force = false) => putRequest(this.base, `/territories/${id}/name${force ? '?force=true' : ''}`, { name }, token),
130
164
  };
131
165
  this.territory = {
132
166
  getCollection: () => request(this.base, '/territory/collection'),
@@ -151,8 +185,15 @@ class MicrocosmAPI {
151
185
  getActive: () => request(this.base, '/auction-solana/active'),
152
186
  getDetails: (id) => request(this.base, `/auction-solana/auction/${id}`),
153
187
  getBids: (id) => request(this.base, `/auction-solana/auction/${id}/bids`),
188
+ getUserBids: (wallet) => request(this.base, `/auction-solana/bids/${wallet}`),
189
+ getUserAuctions: (wallet) => request(this.base, `/auction-solana/auctions/${wallet}`),
154
190
  getMyBids: (token) => request(this.base, '/auction-solana/my-bids', token),
155
191
  placeBid: (token, auctionId, bidAmount) => postRequest(this.base, `/auction-solana/auction/${auctionId}/bid`, { bid_amount: bidAmount }, token),
192
+ prepareCancelBid: (token, auctionId) => postRequest(this.base, '/auction-solana/bid/cancel/prepare', { auction_id: auctionId }, token),
193
+ getHistory: (params) => {
194
+ const p = params || {};
195
+ return request(this.base, `/auction-solana/history?page=${p.page || 1}&page_size=${p.page_size || 20}`);
196
+ },
156
197
  };
157
198
  this.techTree = {
158
199
  getConfig: () => request(this.base, '/tech-tree/config'),
package/dist/types.d.ts CHANGED
@@ -218,3 +218,75 @@ export interface MCDReward {
218
218
  mcd_received: number;
219
219
  created_at: string;
220
220
  }
221
+ export interface MiningRequest {
222
+ mcc_amount: number;
223
+ stablecoin?: string;
224
+ wallet_address: string;
225
+ }
226
+ export interface MiningConfirmData {
227
+ request_id: string;
228
+ tx_signature: string;
229
+ mcc_amount: number;
230
+ usdc_amount: number;
231
+ stablecoin_type?: string;
232
+ }
233
+ export interface MiningRequestResult {
234
+ request_id: string;
235
+ mcc_amount: number;
236
+ usdc_amount: number;
237
+ mining_price: number;
238
+ stablecoin: string;
239
+ payment_address: string;
240
+ expires_at: string;
241
+ }
242
+ export interface MiningConfig {
243
+ program_id: string;
244
+ pool_address: string;
245
+ mcc_mint: string;
246
+ usdt_mint: string;
247
+ usdc_mint: string;
248
+ distribution_ratios: Record<string, number>;
249
+ min_amount: number;
250
+ max_amount: number;
251
+ }
252
+ export interface BuybackRecordInput {
253
+ tx_signature: string;
254
+ wallet_address: string;
255
+ mcc_amount: number;
256
+ usdc_amount: number;
257
+ stablecoin?: string;
258
+ }
259
+ export interface ReincarnationConfig {
260
+ program_id: string;
261
+ pool_address: string;
262
+ mcc_vault: string;
263
+ usdc_vault: string;
264
+ usdt_vault: string;
265
+ min_buyback: number;
266
+ max_buyback: number;
267
+ premium_rate: number;
268
+ }
269
+ export interface MCCHistoryRecord {
270
+ mcc_amount: number;
271
+ stablecoin_amount: number;
272
+ stablecoin: string;
273
+ tx_signature: string;
274
+ type: string;
275
+ wallet_address?: string;
276
+ created_at: string;
277
+ }
278
+ export interface CycleHistory {
279
+ cycle_id: number;
280
+ executed_at: string;
281
+ mcc_returned: number;
282
+ mcd_returned: number;
283
+ status: string;
284
+ }
285
+ export interface AuctionHistory {
286
+ auction_id: number;
287
+ unit_name: string;
288
+ winner_wallet?: string;
289
+ winning_bid?: number;
290
+ status: string;
291
+ ended_at: string;
292
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microcosmmoney/auth-core",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Microcosm OAuth 2.0 authentication core library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",