@pear-protocol/core-sdk 1.12.2 → 1.14.0

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.
@@ -2610,6 +2610,28 @@ declare class Core {
2610
2610
  nextCursor?: string | undefined;
2611
2611
  }>;
2612
2612
  };
2613
+ referrals: {
2614
+ /** Issue an immutable referral code to the authenticated user. */
2615
+ create: (body: HttpTypes.CreateReferralCode, headers?: ClientHeaders) => Promise<void>;
2616
+ /** Permanently bind the authenticated user to an existing referral code. */
2617
+ bind: (body: HttpTypes.BindReferralCode, headers?: ClientHeaders) => Promise<void>;
2618
+ /** Return referral codes owned by the authenticated user and their referrer. */
2619
+ status: (headers?: ClientHeaders) => Promise<{
2620
+ ownedCodes: string[];
2621
+ referrerCode?: string | undefined;
2622
+ }>;
2623
+ /** List users permanently bound to the authenticated referrer. */
2624
+ referees: (query?: HttpTypes.ReferralRefereeListParamsInput, headers?: ClientHeaders) => Promise<{
2625
+ limit: number;
2626
+ count: number;
2627
+ referees: {
2628
+ tradeCount: number;
2629
+ address?: `0x${string}` | undefined;
2630
+ referredAt?: number | undefined;
2631
+ }[];
2632
+ nextCursor?: string | undefined;
2633
+ }>;
2634
+ };
2613
2635
  savedBaskets: {
2614
2636
  list: (headers?: ClientHeaders) => Promise<{
2615
2637
  baskets: {
@@ -352,6 +352,39 @@ class Core {
352
352
  });
353
353
  }
354
354
  };
355
+ referrals = {
356
+ /** Issue an immutable referral code to the authenticated user. */
357
+ create: async (body, headers) => {
358
+ return await this.client.fetch(`/referrals/create`, {
359
+ method: "POST",
360
+ headers,
361
+ body
362
+ });
363
+ },
364
+ /** Permanently bind the authenticated user to an existing referral code. */
365
+ bind: async (body, headers) => {
366
+ return await this.client.fetch(`/referrals/bind`, {
367
+ method: "POST",
368
+ headers,
369
+ body
370
+ });
371
+ },
372
+ /** Return referral codes owned by the authenticated user and their referrer. */
373
+ status: async (headers) => {
374
+ return await this.client.fetch(`/referrals/status`, {
375
+ method: "GET",
376
+ headers
377
+ });
378
+ },
379
+ /** List users permanently bound to the authenticated referrer. */
380
+ referees: async (query, headers) => {
381
+ return await this.client.fetch(`/referrals/referees`, {
382
+ method: "GET",
383
+ headers,
384
+ query
385
+ });
386
+ }
387
+ };
355
388
  savedBaskets = {
356
389
  list: async (headers) => {
357
390
  return await this.client.fetch(`/saved-baskets`, {
package/dist/utils.d.ts CHANGED
@@ -4,7 +4,7 @@ import '@pear-protocol/utils';
4
4
 
5
5
  declare function getBaseUrl(passedBaseUrl: string): string;
6
6
  declare function normalizeRequest(init: FetchArgs | undefined, headers: Headers, authMode: AuthMode): RequestInit | undefined;
7
- declare function normalizeResponseData(resp: Response, reqHeaders: Headers): Promise<any>;
7
+ declare function normalizeResponseData(resp: Response, reqHeaders: Headers): Promise<unknown>;
8
8
  declare class FetchError extends Error {
9
9
  status: number | undefined;
10
10
  statusText: string | undefined;
package/dist/utils.js CHANGED
@@ -33,7 +33,14 @@ async function normalizeResponseData(resp, reqHeaders) {
33
33
  return null;
34
34
  }
35
35
  const isJsonRequest = reqHeaders.get("accept")?.includes("application/json");
36
- return isJsonRequest ? await resp.json() : resp;
36
+ if (!isJsonRequest) {
37
+ return resp;
38
+ }
39
+ const responseText = await resp.text();
40
+ if (responseText.length === 0) {
41
+ return null;
42
+ }
43
+ return JSON.parse(responseText);
37
44
  }
38
45
  class FetchError extends Error {
39
46
  status;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/core-sdk",
3
- "version": "1.12.2",
3
+ "version": "1.14.0",
4
4
  "description": "Pear Protocol Core SDK",
5
5
  "private": false,
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  "typecheck": "tsc --noEmit"
26
26
  },
27
27
  "dependencies": {
28
- "@pear-protocol/types": "^1.17.0",
28
+ "@pear-protocol/types": "^1.19.0",
29
29
  "@pear-protocol/utils": "^0.5.0",
30
30
  "qs": "^6.14.0"
31
31
  },