@echoxyz/sonar-core 0.3.0 → 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 +6 -0
- package/README.md +1 -5
- package/dist/index.cjs +2 -4
- package/dist/index.d.cts +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ 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(
|
|
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,
|
|
@@ -106,7 +105,6 @@ export async function exampleCalls() {
|
|
|
106
105
|
import { AuthSession, buildAuthorizationUrl, createClient, createMemoryStorage } from "@echoxyz/sonar-core";
|
|
107
106
|
|
|
108
107
|
const client = createClient({
|
|
109
|
-
saleUUID: "<sale-uuid>",
|
|
110
108
|
apiURL: "https://api.echo.xyz",
|
|
111
109
|
fetch: customFetchImplementation,
|
|
112
110
|
auth: new AuthSession({
|
|
@@ -117,13 +115,11 @@ const client = createClient({
|
|
|
117
115
|
|
|
118
116
|
// or let the factory create the session but tweak defaults
|
|
119
117
|
const clientWithCallbacks = createClient({
|
|
120
|
-
saleUUID: "<sale-uuid>",
|
|
121
118
|
onTokenChange: (token) => console.log("token updated", token),
|
|
122
119
|
onExpire: () => console.log("session expired"),
|
|
123
120
|
});
|
|
124
121
|
|
|
125
122
|
const oauthURL = buildAuthorizationUrl({
|
|
126
|
-
saleUUID: "<sale-uuid>",
|
|
127
123
|
clientUUID: "<client-id>",
|
|
128
124
|
redirectURI: "https://example.com/oauth/callback",
|
|
129
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
|
-
|
|
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)) {
|
|
@@ -318,7 +318,6 @@ var APIError = class extends Error {
|
|
|
318
318
|
// src/oauth.ts
|
|
319
319
|
var DEFAULT_FRONTEND_URL = "https://app.echo.xyz";
|
|
320
320
|
function buildAuthorizationUrl({
|
|
321
|
-
saleUUID,
|
|
322
321
|
clientUUID,
|
|
323
322
|
redirectURI,
|
|
324
323
|
state,
|
|
@@ -331,7 +330,6 @@ function buildAuthorizationUrl({
|
|
|
331
330
|
url.searchParams.set("response_type", "code");
|
|
332
331
|
url.searchParams.set("state", state);
|
|
333
332
|
url.searchParams.set("code_challenge", codeChallenge);
|
|
334
|
-
url.searchParams.set("saleUUID", saleUUID);
|
|
335
333
|
return url;
|
|
336
334
|
}
|
|
337
335
|
|
|
@@ -413,7 +411,7 @@ var InvestingRegion = /* @__PURE__ */ ((InvestingRegion2) => {
|
|
|
413
411
|
// src/index.ts
|
|
414
412
|
var DEFAULT_API_URL = "https://api.echo.xyz";
|
|
415
413
|
function createClient(options) {
|
|
416
|
-
const {
|
|
414
|
+
const { apiURL = DEFAULT_API_URL, auth, fetch, tokenKey, onExpire, onTokenChange } = options ?? {};
|
|
417
415
|
const authSession = auth ?? new AuthSession({
|
|
418
416
|
storage: createWebStorage(),
|
|
419
417
|
tokenKey,
|
package/dist/index.d.cts
CHANGED
|
@@ -159,14 +159,13 @@ declare class APIError extends Error {
|
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
type BuildAuthorizationUrlArgs = {
|
|
162
|
-
saleUUID: string;
|
|
163
162
|
clientUUID: string;
|
|
164
163
|
redirectURI: string;
|
|
165
164
|
state: string;
|
|
166
165
|
codeChallenge: string;
|
|
167
166
|
frontendURL?: string;
|
|
168
167
|
};
|
|
169
|
-
declare function buildAuthorizationUrl({
|
|
168
|
+
declare function buildAuthorizationUrl({ clientUUID, redirectURI, state, codeChallenge, frontendURL, }: BuildAuthorizationUrlArgs): URL;
|
|
170
169
|
|
|
171
170
|
type PKCEParams = {
|
|
172
171
|
codeVerifier: string;
|
|
@@ -176,7 +175,6 @@ type PKCEParams = {
|
|
|
176
175
|
declare function generatePKCEParams(): Promise<PKCEParams>;
|
|
177
176
|
|
|
178
177
|
type CreateClientOptions = {
|
|
179
|
-
saleUUID: string;
|
|
180
178
|
apiURL?: string;
|
|
181
179
|
auth?: AuthSession;
|
|
182
180
|
fetch?: FetchLike;
|
|
@@ -184,6 +182,6 @@ type CreateClientOptions = {
|
|
|
184
182
|
onExpire?: () => void;
|
|
185
183
|
onTokenChange?: (token?: string) => void;
|
|
186
184
|
};
|
|
187
|
-
declare function createClient(options
|
|
185
|
+
declare function createClient(options?: CreateClientOptions): SonarClient;
|
|
188
186
|
|
|
189
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
|
@@ -159,14 +159,13 @@ declare class APIError extends Error {
|
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
type BuildAuthorizationUrlArgs = {
|
|
162
|
-
saleUUID: string;
|
|
163
162
|
clientUUID: string;
|
|
164
163
|
redirectURI: string;
|
|
165
164
|
state: string;
|
|
166
165
|
codeChallenge: string;
|
|
167
166
|
frontendURL?: string;
|
|
168
167
|
};
|
|
169
|
-
declare function buildAuthorizationUrl({
|
|
168
|
+
declare function buildAuthorizationUrl({ clientUUID, redirectURI, state, codeChallenge, frontendURL, }: BuildAuthorizationUrlArgs): URL;
|
|
170
169
|
|
|
171
170
|
type PKCEParams = {
|
|
172
171
|
codeVerifier: string;
|
|
@@ -176,7 +175,6 @@ type PKCEParams = {
|
|
|
176
175
|
declare function generatePKCEParams(): Promise<PKCEParams>;
|
|
177
176
|
|
|
178
177
|
type CreateClientOptions = {
|
|
179
|
-
saleUUID: string;
|
|
180
178
|
apiURL?: string;
|
|
181
179
|
auth?: AuthSession;
|
|
182
180
|
fetch?: FetchLike;
|
|
@@ -184,6 +182,6 @@ type CreateClientOptions = {
|
|
|
184
182
|
onExpire?: () => void;
|
|
185
183
|
onTokenChange?: (token?: string) => void;
|
|
186
184
|
};
|
|
187
|
-
declare function createClient(options
|
|
185
|
+
declare function createClient(options?: CreateClientOptions): SonarClient;
|
|
188
186
|
|
|
189
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
|
-
|
|
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)) {
|
|
@@ -281,7 +281,6 @@ var APIError = class extends Error {
|
|
|
281
281
|
// src/oauth.ts
|
|
282
282
|
var DEFAULT_FRONTEND_URL = "https://app.echo.xyz";
|
|
283
283
|
function buildAuthorizationUrl({
|
|
284
|
-
saleUUID,
|
|
285
284
|
clientUUID,
|
|
286
285
|
redirectURI,
|
|
287
286
|
state,
|
|
@@ -294,7 +293,6 @@ function buildAuthorizationUrl({
|
|
|
294
293
|
url.searchParams.set("response_type", "code");
|
|
295
294
|
url.searchParams.set("state", state);
|
|
296
295
|
url.searchParams.set("code_challenge", codeChallenge);
|
|
297
|
-
url.searchParams.set("saleUUID", saleUUID);
|
|
298
296
|
return url;
|
|
299
297
|
}
|
|
300
298
|
|
|
@@ -376,7 +374,7 @@ var InvestingRegion = /* @__PURE__ */ ((InvestingRegion2) => {
|
|
|
376
374
|
// src/index.ts
|
|
377
375
|
var DEFAULT_API_URL = "https://api.echo.xyz";
|
|
378
376
|
function createClient(options) {
|
|
379
|
-
const {
|
|
377
|
+
const { apiURL = DEFAULT_API_URL, auth, fetch, tokenKey, onExpire, onTokenChange } = options ?? {};
|
|
380
378
|
const authSession = auth ?? new AuthSession({
|
|
381
379
|
storage: createWebStorage(),
|
|
382
380
|
tokenKey,
|