@echoxyz/sonar-core 0.2.1 → 0.4.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @echoxyz/sonar-core
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1ccce38: Remove redundant saleUUID from constructor/Provider
8
+
9
+ ## 0.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - c032c29: Strip EntityType param from API requests
14
+
3
15
  ## 0.2.1
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -13,14 +13,14 @@ pnpm add @echoxyz/sonar-core
13
13
  The default client targets Echo’s hosted API and reads the auth token from `localStorage` under the `sonar:auth-token` key.
14
14
 
15
15
  ```ts
16
- import { createClient, buildAuthorizationUrl, generatePKCEParams, EntityType } from "@echoxyz/sonar-core";
16
+ import { createClient, buildAuthorizationUrl, generatePKCEParams } from "@echoxyz/sonar-core";
17
17
 
18
18
  // Configure once at app startup
19
19
  const saleUUID = "<your-sale-uuid>";
20
20
  const clientUUID = "<your-oauth-client-id>";
21
21
  const redirectURI = window.location.origin + "/oauth/callback";
22
22
 
23
- const client = createClient({ saleUUID });
23
+ const client = createClient();
24
24
 
25
25
  // Start OAuth login (e.g. on a button click)
26
26
  export async function login() {
@@ -30,7 +30,6 @@ export async function login() {
30
30
  sessionStorage.setItem("sonar:oauth:verifier", codeVerifier);
31
31
 
32
32
  const url = buildAuthorizationUrl({
33
- saleUUID,
34
33
  clientUUID,
35
34
  redirectURI,
36
35
  state,
@@ -79,7 +78,6 @@ export async function exampleCalls() {
79
78
  const pre = await client.prePurchaseCheck({
80
79
  saleUUID,
81
80
  entityUUID: Entity.EntityUUID,
82
- entityType: EntityType.USER, // or EntityType.ORGANIZATION
83
81
  walletAddress: "0x1234...abcd" as `0x${string}`,
84
82
  });
85
83
 
@@ -88,7 +86,6 @@ export async function exampleCalls() {
88
86
  const permit = await client.generatePurchasePermit({
89
87
  saleUUID,
90
88
  entityUUID: Entity.EntityUUID,
91
- entityType: EntityType.USER,
92
89
  walletAddress: "0x1234...abcd" as `0x${string}`,
93
90
  });
94
91
  console.log(permit.Signature, permit.Permit);
@@ -108,7 +105,6 @@ export async function exampleCalls() {
108
105
  import { AuthSession, buildAuthorizationUrl, createClient, createMemoryStorage } from "@echoxyz/sonar-core";
109
106
 
110
107
  const client = createClient({
111
- saleUUID: "<sale-uuid>",
112
108
  apiURL: "https://api.echo.xyz",
113
109
  fetch: customFetchImplementation,
114
110
  auth: new AuthSession({
@@ -119,13 +115,11 @@ const client = createClient({
119
115
 
120
116
  // or let the factory create the session but tweak defaults
121
117
  const clientWithCallbacks = createClient({
122
- saleUUID: "<sale-uuid>",
123
118
  onTokenChange: (token) => console.log("token updated", token),
124
119
  onExpire: () => console.log("session expired"),
125
120
  });
126
121
 
127
122
  const oauthURL = buildAuthorizationUrl({
128
- saleUUID: "<sale-uuid>",
129
123
  clientUUID: "<client-id>",
130
124
  redirectURI: "https://example.com/oauth/callback",
131
125
  state: "opaque-state",
package/dist/index.cjs CHANGED
@@ -45,7 +45,7 @@ function safeDecodeExp(token) {
45
45
  return void 0;
46
46
  }
47
47
  try {
48
- let base64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
48
+ const base64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
49
49
  const payload = JSON.parse(atob(base64));
50
50
  const exp = payload == null ? void 0 : payload.exp;
51
51
  if (typeof exp === "number" && isFinite(exp)) {
@@ -278,7 +278,6 @@ var SonarClient = class {
278
278
  return this.postJSON("/externalapi.PrePurchaseCheck", {
279
279
  SaleUUID: args.saleUUID,
280
280
  EntityUUID: args.entityUUID,
281
- EntityType: args.entityType,
282
281
  PurchasingWalletAddress: args.walletAddress
283
282
  });
284
283
  }
@@ -286,7 +285,6 @@ var SonarClient = class {
286
285
  return this.postJSON("/externalapi.GenerateSalePurchasePermit", {
287
286
  SaleUUID: args.saleUUID,
288
287
  EntityUUID: args.entityUUID,
289
- EntityType: args.entityType,
290
288
  PurchasingWalletAddress: args.walletAddress
291
289
  });
292
290
  }
@@ -320,7 +318,6 @@ var APIError = class extends Error {
320
318
  // src/oauth.ts
321
319
  var DEFAULT_FRONTEND_URL = "https://app.echo.xyz";
322
320
  function buildAuthorizationUrl({
323
- saleUUID,
324
321
  clientUUID,
325
322
  redirectURI,
326
323
  state,
@@ -333,7 +330,6 @@ function buildAuthorizationUrl({
333
330
  url.searchParams.set("response_type", "code");
334
331
  url.searchParams.set("state", state);
335
332
  url.searchParams.set("code_challenge", codeChallenge);
336
- url.searchParams.set("saleUUID", saleUUID);
337
333
  return url;
338
334
  }
339
335
 
@@ -415,7 +411,7 @@ var InvestingRegion = /* @__PURE__ */ ((InvestingRegion2) => {
415
411
  // src/index.ts
416
412
  var DEFAULT_API_URL = "https://api.echo.xyz";
417
413
  function createClient(options) {
418
- const { saleUUID, apiURL = DEFAULT_API_URL, auth, fetch, tokenKey, onExpire, onTokenChange } = options;
414
+ const { apiURL = DEFAULT_API_URL, auth, fetch, tokenKey, onExpire, onTokenChange } = options ?? {};
419
415
  const authSession = auth ?? new AuthSession({
420
416
  storage: createWebStorage(),
421
417
  tokenKey,
package/dist/index.d.cts CHANGED
@@ -135,13 +135,11 @@ declare class SonarClient {
135
135
  prePurchaseCheck(args: {
136
136
  saleUUID: string;
137
137
  entityUUID: string;
138
- entityType: EntityType;
139
138
  walletAddress: string;
140
139
  }): Promise<PrePurchaseCheckResponse>;
141
140
  generatePurchasePermit(args: {
142
141
  saleUUID: string;
143
142
  entityUUID: string;
144
- entityType: EntityType;
145
143
  walletAddress: string;
146
144
  }): Promise<GeneratePurchasePermitResponse>;
147
145
  fetchAllocation(args: {
@@ -161,14 +159,13 @@ declare class APIError extends Error {
161
159
  }
162
160
 
163
161
  type BuildAuthorizationUrlArgs = {
164
- saleUUID: string;
165
162
  clientUUID: string;
166
163
  redirectURI: string;
167
164
  state: string;
168
165
  codeChallenge: string;
169
166
  frontendURL?: string;
170
167
  };
171
- declare function buildAuthorizationUrl({ saleUUID, clientUUID, redirectURI, state, codeChallenge, frontendURL, }: BuildAuthorizationUrlArgs): URL;
168
+ declare function buildAuthorizationUrl({ clientUUID, redirectURI, state, codeChallenge, frontendURL, }: BuildAuthorizationUrlArgs): URL;
172
169
 
173
170
  type PKCEParams = {
174
171
  codeVerifier: string;
@@ -178,7 +175,6 @@ type PKCEParams = {
178
175
  declare function generatePKCEParams(): Promise<PKCEParams>;
179
176
 
180
177
  type CreateClientOptions = {
181
- saleUUID: string;
182
178
  apiURL?: string;
183
179
  auth?: AuthSession;
184
180
  fetch?: FetchLike;
@@ -186,6 +182,6 @@ type CreateClientOptions = {
186
182
  onExpire?: () => void;
187
183
  onTokenChange?: (token?: string) => void;
188
184
  };
189
- declare function createClient(options: CreateClientOptions): SonarClient;
185
+ declare function createClient(options?: CreateClientOptions): SonarClient;
190
186
 
191
187
  export { APIError, type AllocationPermit, type AllocationResponse, type BasicPermit, type BuildAuthorizationUrlArgs, type ClientOptions, type CreateClientOptions, type EntityDetails, EntitySetupState, EntityType, type FetchLike, type GeneratePurchasePermitResponse, type Hex, InvestingRegion, type PrePurchaseCheckResponse, PrePurchaseFailureReason, type PurchasePermit, PurchasePermitType, type ReadEntityResponse, SaleEligibility, SonarClient, type StorageLike, buildAuthorizationUrl, createClient, createMemoryStorage, createWebStorage, generatePKCEParams };
package/dist/index.d.ts CHANGED
@@ -135,13 +135,11 @@ declare class SonarClient {
135
135
  prePurchaseCheck(args: {
136
136
  saleUUID: string;
137
137
  entityUUID: string;
138
- entityType: EntityType;
139
138
  walletAddress: string;
140
139
  }): Promise<PrePurchaseCheckResponse>;
141
140
  generatePurchasePermit(args: {
142
141
  saleUUID: string;
143
142
  entityUUID: string;
144
- entityType: EntityType;
145
143
  walletAddress: string;
146
144
  }): Promise<GeneratePurchasePermitResponse>;
147
145
  fetchAllocation(args: {
@@ -161,14 +159,13 @@ declare class APIError extends Error {
161
159
  }
162
160
 
163
161
  type BuildAuthorizationUrlArgs = {
164
- saleUUID: string;
165
162
  clientUUID: string;
166
163
  redirectURI: string;
167
164
  state: string;
168
165
  codeChallenge: string;
169
166
  frontendURL?: string;
170
167
  };
171
- declare function buildAuthorizationUrl({ saleUUID, clientUUID, redirectURI, state, codeChallenge, frontendURL, }: BuildAuthorizationUrlArgs): URL;
168
+ declare function buildAuthorizationUrl({ clientUUID, redirectURI, state, codeChallenge, frontendURL, }: BuildAuthorizationUrlArgs): URL;
172
169
 
173
170
  type PKCEParams = {
174
171
  codeVerifier: string;
@@ -178,7 +175,6 @@ type PKCEParams = {
178
175
  declare function generatePKCEParams(): Promise<PKCEParams>;
179
176
 
180
177
  type CreateClientOptions = {
181
- saleUUID: string;
182
178
  apiURL?: string;
183
179
  auth?: AuthSession;
184
180
  fetch?: FetchLike;
@@ -186,6 +182,6 @@ type CreateClientOptions = {
186
182
  onExpire?: () => void;
187
183
  onTokenChange?: (token?: string) => void;
188
184
  };
189
- declare function createClient(options: CreateClientOptions): SonarClient;
185
+ declare function createClient(options?: CreateClientOptions): SonarClient;
190
186
 
191
187
  export { APIError, type AllocationPermit, type AllocationResponse, type BasicPermit, type BuildAuthorizationUrlArgs, type ClientOptions, type CreateClientOptions, type EntityDetails, EntitySetupState, EntityType, type FetchLike, type GeneratePurchasePermitResponse, type Hex, InvestingRegion, type PrePurchaseCheckResponse, PrePurchaseFailureReason, type PurchasePermit, PurchasePermitType, type ReadEntityResponse, SaleEligibility, SonarClient, type StorageLike, buildAuthorizationUrl, createClient, createMemoryStorage, createWebStorage, generatePKCEParams };
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ function safeDecodeExp(token) {
8
8
  return void 0;
9
9
  }
10
10
  try {
11
- let base64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
11
+ const base64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
12
12
  const payload = JSON.parse(atob(base64));
13
13
  const exp = payload == null ? void 0 : payload.exp;
14
14
  if (typeof exp === "number" && isFinite(exp)) {
@@ -241,7 +241,6 @@ var SonarClient = class {
241
241
  return this.postJSON("/externalapi.PrePurchaseCheck", {
242
242
  SaleUUID: args.saleUUID,
243
243
  EntityUUID: args.entityUUID,
244
- EntityType: args.entityType,
245
244
  PurchasingWalletAddress: args.walletAddress
246
245
  });
247
246
  }
@@ -249,7 +248,6 @@ var SonarClient = class {
249
248
  return this.postJSON("/externalapi.GenerateSalePurchasePermit", {
250
249
  SaleUUID: args.saleUUID,
251
250
  EntityUUID: args.entityUUID,
252
- EntityType: args.entityType,
253
251
  PurchasingWalletAddress: args.walletAddress
254
252
  });
255
253
  }
@@ -283,7 +281,6 @@ var APIError = class extends Error {
283
281
  // src/oauth.ts
284
282
  var DEFAULT_FRONTEND_URL = "https://app.echo.xyz";
285
283
  function buildAuthorizationUrl({
286
- saleUUID,
287
284
  clientUUID,
288
285
  redirectURI,
289
286
  state,
@@ -296,7 +293,6 @@ function buildAuthorizationUrl({
296
293
  url.searchParams.set("response_type", "code");
297
294
  url.searchParams.set("state", state);
298
295
  url.searchParams.set("code_challenge", codeChallenge);
299
- url.searchParams.set("saleUUID", saleUUID);
300
296
  return url;
301
297
  }
302
298
 
@@ -378,7 +374,7 @@ var InvestingRegion = /* @__PURE__ */ ((InvestingRegion2) => {
378
374
  // src/index.ts
379
375
  var DEFAULT_API_URL = "https://api.echo.xyz";
380
376
  function createClient(options) {
381
- const { saleUUID, apiURL = DEFAULT_API_URL, auth, fetch, tokenKey, onExpire, onTokenChange } = options;
377
+ const { apiURL = DEFAULT_API_URL, auth, fetch, tokenKey, onExpire, onTokenChange } = options ?? {};
382
378
  const authSession = auth ?? new AuthSession({
383
379
  storage: createWebStorage(),
384
380
  tokenKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@echoxyz/sonar-core",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",