arky-sdk 0.3.2 → 0.3.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.cjs +10 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -28
- package/dist/index.d.ts +26 -28
- package/dist/index.js +10 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -3,6 +3,30 @@ export { ApiResponse, ApplyPromoCodeParams, Block, Business, BusinessConfig, Bus
|
|
|
3
3
|
import { g as getGalleryThumbnail, a as getMarketPrice, b as getPriceAmount, f as formatPayment, c as formatMinor, d as createPaymentForCheckout, e as getCurrencySymbol, v as validatePhoneNumber, h as findTimeZone } from './index-DOEos-hV.cjs';
|
|
4
4
|
export { C as Collection, i as CollectionEntry, E as ERROR_CODES, x as ERROR_CONSTANTS, R as RequestError, S as SYMBOL_AFTER_CURRENCIES, y as ServerError, V as ValidationError, U as ValidationResult, P as categorify, D as convertServerErrorToRequestError, G as convertToMajor, H as convertToMinor, F as errors, l as extractBlockValues, K as fetchSvgContent, k as formatBlockValue, J as formatCurrencyAmount, Q as formatDate, r as getBlockFromArray, j as getBlockLabel, q as getBlockObjectValues, m as getBlockTextValue, n as getBlockValue, o as getBlockValues, I as getCurrencyFromMarket, z as getErrorMessage, s as getImageUrl, L as getSvgContentForAstro, O as humanize, M as injectSvgIntoElement, A as isErrorCode, w as isSymbolAfterCurrency, p as prepareBlocksForSubmission, N as slugify, t as thumbnailUrl, B as transformErrors, u as translateMap, T as tzGroups, W as validateEmail, Y as validateRequired, X as validateVerificationCode } from './index-DOEos-hV.cjs';
|
|
5
5
|
|
|
6
|
+
interface AuthTokens {
|
|
7
|
+
accessToken: string;
|
|
8
|
+
refreshToken?: string;
|
|
9
|
+
provider?: string;
|
|
10
|
+
expiresAt?: number;
|
|
11
|
+
userId?: string;
|
|
12
|
+
}
|
|
13
|
+
interface HttpClientConfig {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
storageUrl?: string;
|
|
16
|
+
businessId: string;
|
|
17
|
+
getToken: () => Promise<AuthTokens> | AuthTokens;
|
|
18
|
+
setToken: (tokens: AuthTokens) => void;
|
|
19
|
+
autoGuest?: boolean;
|
|
20
|
+
logout: () => void;
|
|
21
|
+
navigate?: (path: string) => void;
|
|
22
|
+
loginFallbackPath?: string;
|
|
23
|
+
notify?: (opts: {
|
|
24
|
+
message: string;
|
|
25
|
+
type: 'error' | 'success';
|
|
26
|
+
}) => void;
|
|
27
|
+
isAuthenticated?: () => boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
6
30
|
declare const createCmsApi: (apiConfig: ApiConfig) => {
|
|
7
31
|
createCollection(params: CreateCollectionParams, options?: RequestOptions): Promise<any>;
|
|
8
32
|
updateCollection(params: UpdateCollectionParams, options?: RequestOptions): Promise<any>;
|
|
@@ -190,33 +214,7 @@ declare function buildQueryString(params: QueryParams): string;
|
|
|
190
214
|
*/
|
|
191
215
|
declare function appendQueryString(url: string, params: QueryParams): string;
|
|
192
216
|
|
|
193
|
-
|
|
194
|
-
accessToken: string;
|
|
195
|
-
refreshToken?: string;
|
|
196
|
-
provider?: string;
|
|
197
|
-
expiresAt?: number;
|
|
198
|
-
userId?: string;
|
|
199
|
-
}
|
|
200
|
-
interface HttpClientConfig {
|
|
201
|
-
baseUrl: string;
|
|
202
|
-
storageUrl?: string;
|
|
203
|
-
businessId: string;
|
|
204
|
-
getTokens: () => Promise<AuthTokens> | AuthTokens;
|
|
205
|
-
setTokens: (tokens: AuthTokens) => void;
|
|
206
|
-
autoGuest?: boolean;
|
|
207
|
-
onAuthFailure: () => void;
|
|
208
|
-
navigate?: (path: string) => void;
|
|
209
|
-
loginFallbackPath?: string;
|
|
210
|
-
notify?: (opts: {
|
|
211
|
-
message: string;
|
|
212
|
-
type: 'error' | 'success';
|
|
213
|
-
}) => void;
|
|
214
|
-
isAuthenticated?: () => boolean;
|
|
215
|
-
logout?: () => void;
|
|
216
|
-
setUserToken?: (userToken: any) => void;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
declare const SDK_VERSION = "0.3.2";
|
|
217
|
+
declare const SDK_VERSION = "0.3.4";
|
|
220
218
|
declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
|
|
221
219
|
interface ApiConfig {
|
|
222
220
|
httpClient: any;
|
|
@@ -384,7 +382,7 @@ declare function createArkySDK(config: HttpClientConfig & {
|
|
|
384
382
|
getBusinessId: () => string;
|
|
385
383
|
isAuthenticated: () => boolean;
|
|
386
384
|
logout: () => void;
|
|
387
|
-
|
|
385
|
+
setToken: (tokens: AuthTokens) => void;
|
|
388
386
|
utils: {
|
|
389
387
|
getImageUrl: (imageBlock: any, isBlock?: boolean) => any;
|
|
390
388
|
thumbnailUrl: (service: any) => string;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,30 @@ export { ApiResponse, ApplyPromoCodeParams, Block, Business, BusinessConfig, Bus
|
|
|
3
3
|
import { g as getGalleryThumbnail, a as getMarketPrice, b as getPriceAmount, f as formatPayment, c as formatMinor, d as createPaymentForCheckout, e as getCurrencySymbol, v as validatePhoneNumber, h as findTimeZone } from './index-DEmVFs0E.js';
|
|
4
4
|
export { C as Collection, i as CollectionEntry, E as ERROR_CODES, x as ERROR_CONSTANTS, R as RequestError, S as SYMBOL_AFTER_CURRENCIES, y as ServerError, V as ValidationError, U as ValidationResult, P as categorify, D as convertServerErrorToRequestError, G as convertToMajor, H as convertToMinor, F as errors, l as extractBlockValues, K as fetchSvgContent, k as formatBlockValue, J as formatCurrencyAmount, Q as formatDate, r as getBlockFromArray, j as getBlockLabel, q as getBlockObjectValues, m as getBlockTextValue, n as getBlockValue, o as getBlockValues, I as getCurrencyFromMarket, z as getErrorMessage, s as getImageUrl, L as getSvgContentForAstro, O as humanize, M as injectSvgIntoElement, A as isErrorCode, w as isSymbolAfterCurrency, p as prepareBlocksForSubmission, N as slugify, t as thumbnailUrl, B as transformErrors, u as translateMap, T as tzGroups, W as validateEmail, Y as validateRequired, X as validateVerificationCode } from './index-DEmVFs0E.js';
|
|
5
5
|
|
|
6
|
+
interface AuthTokens {
|
|
7
|
+
accessToken: string;
|
|
8
|
+
refreshToken?: string;
|
|
9
|
+
provider?: string;
|
|
10
|
+
expiresAt?: number;
|
|
11
|
+
userId?: string;
|
|
12
|
+
}
|
|
13
|
+
interface HttpClientConfig {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
storageUrl?: string;
|
|
16
|
+
businessId: string;
|
|
17
|
+
getToken: () => Promise<AuthTokens> | AuthTokens;
|
|
18
|
+
setToken: (tokens: AuthTokens) => void;
|
|
19
|
+
autoGuest?: boolean;
|
|
20
|
+
logout: () => void;
|
|
21
|
+
navigate?: (path: string) => void;
|
|
22
|
+
loginFallbackPath?: string;
|
|
23
|
+
notify?: (opts: {
|
|
24
|
+
message: string;
|
|
25
|
+
type: 'error' | 'success';
|
|
26
|
+
}) => void;
|
|
27
|
+
isAuthenticated?: () => boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
6
30
|
declare const createCmsApi: (apiConfig: ApiConfig) => {
|
|
7
31
|
createCollection(params: CreateCollectionParams, options?: RequestOptions): Promise<any>;
|
|
8
32
|
updateCollection(params: UpdateCollectionParams, options?: RequestOptions): Promise<any>;
|
|
@@ -190,33 +214,7 @@ declare function buildQueryString(params: QueryParams): string;
|
|
|
190
214
|
*/
|
|
191
215
|
declare function appendQueryString(url: string, params: QueryParams): string;
|
|
192
216
|
|
|
193
|
-
|
|
194
|
-
accessToken: string;
|
|
195
|
-
refreshToken?: string;
|
|
196
|
-
provider?: string;
|
|
197
|
-
expiresAt?: number;
|
|
198
|
-
userId?: string;
|
|
199
|
-
}
|
|
200
|
-
interface HttpClientConfig {
|
|
201
|
-
baseUrl: string;
|
|
202
|
-
storageUrl?: string;
|
|
203
|
-
businessId: string;
|
|
204
|
-
getTokens: () => Promise<AuthTokens> | AuthTokens;
|
|
205
|
-
setTokens: (tokens: AuthTokens) => void;
|
|
206
|
-
autoGuest?: boolean;
|
|
207
|
-
onAuthFailure: () => void;
|
|
208
|
-
navigate?: (path: string) => void;
|
|
209
|
-
loginFallbackPath?: string;
|
|
210
|
-
notify?: (opts: {
|
|
211
|
-
message: string;
|
|
212
|
-
type: 'error' | 'success';
|
|
213
|
-
}) => void;
|
|
214
|
-
isAuthenticated?: () => boolean;
|
|
215
|
-
logout?: () => void;
|
|
216
|
-
setUserToken?: (userToken: any) => void;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
declare const SDK_VERSION = "0.3.2";
|
|
217
|
+
declare const SDK_VERSION = "0.3.4";
|
|
220
218
|
declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
|
|
221
219
|
interface ApiConfig {
|
|
222
220
|
httpClient: any;
|
|
@@ -384,7 +382,7 @@ declare function createArkySDK(config: HttpClientConfig & {
|
|
|
384
382
|
getBusinessId: () => string;
|
|
385
383
|
isAuthenticated: () => boolean;
|
|
386
384
|
logout: () => void;
|
|
387
|
-
|
|
385
|
+
setToken: (tokens: AuthTokens) => void;
|
|
388
386
|
utils: {
|
|
389
387
|
getImageUrl: (imageBlock: any, isBlock?: boolean) => any;
|
|
390
388
|
thumbnailUrl: (service: any) => string;
|
package/dist/index.js
CHANGED
|
@@ -1627,7 +1627,7 @@ function createHttpClient(cfg) {
|
|
|
1627
1627
|
"Content-Type": "application/json",
|
|
1628
1628
|
...options?.headers || {}
|
|
1629
1629
|
};
|
|
1630
|
-
let { accessToken, refreshToken, provider, expiresAt } = await cfg.
|
|
1630
|
+
let { accessToken, refreshToken, provider, expiresAt } = await cfg.getToken();
|
|
1631
1631
|
const nowSec = Date.now() / 1e3;
|
|
1632
1632
|
if (expiresAt && nowSec > expiresAt) {
|
|
1633
1633
|
if (refreshToken) {
|
|
@@ -1638,23 +1638,17 @@ function createHttpClient(cfg) {
|
|
|
1638
1638
|
});
|
|
1639
1639
|
if (refRes.ok) {
|
|
1640
1640
|
const data2 = await refRes.json();
|
|
1641
|
-
cfg.
|
|
1641
|
+
cfg.setToken(data2);
|
|
1642
1642
|
accessToken = data2.accessToken;
|
|
1643
1643
|
} else {
|
|
1644
|
-
cfg.
|
|
1645
|
-
if (cfg.loginFallbackPath) {
|
|
1646
|
-
cfg.navigate?.(cfg.loginFallbackPath);
|
|
1647
|
-
}
|
|
1644
|
+
cfg.logout();
|
|
1648
1645
|
const err = new Error("Error refreshing token");
|
|
1649
1646
|
err.name = "ApiError";
|
|
1650
1647
|
err.statusCode = 401;
|
|
1651
1648
|
throw err;
|
|
1652
1649
|
}
|
|
1653
1650
|
} else {
|
|
1654
|
-
cfg.
|
|
1655
|
-
if (cfg.loginFallbackPath) {
|
|
1656
|
-
cfg.navigate?.(cfg.loginFallbackPath);
|
|
1657
|
-
}
|
|
1651
|
+
cfg.logout();
|
|
1658
1652
|
const err = new Error("No refresh token");
|
|
1659
1653
|
err.name = "ApiError";
|
|
1660
1654
|
err.statusCode = 401;
|
|
@@ -1707,7 +1701,7 @@ function createHttpClient(cfg) {
|
|
|
1707
1701
|
}
|
|
1708
1702
|
|
|
1709
1703
|
// src/index.ts
|
|
1710
|
-
var SDK_VERSION = "0.3.
|
|
1704
|
+
var SDK_VERSION = "0.3.4";
|
|
1711
1705
|
var SUPPORTED_FRAMEWORKS = ["astro", "react", "vue", "svelte", "vanilla"];
|
|
1712
1706
|
function createArkySDK(config) {
|
|
1713
1707
|
const httpClient = createHttpClient(config);
|
|
@@ -1718,8 +1712,8 @@ function createArkySDK(config) {
|
|
|
1718
1712
|
storageUrl,
|
|
1719
1713
|
baseUrl: config.baseUrl,
|
|
1720
1714
|
market: config.market || "US",
|
|
1721
|
-
setTokens: config.
|
|
1722
|
-
getTokens: config.
|
|
1715
|
+
setTokens: config.setToken,
|
|
1716
|
+
getTokens: config.getToken
|
|
1723
1717
|
};
|
|
1724
1718
|
const userApi = createUserApi(apiConfig);
|
|
1725
1719
|
const autoGuest = config.autoGuest !== void 0 ? config.autoGuest : true;
|
|
@@ -1741,9 +1735,8 @@ function createArkySDK(config) {
|
|
|
1741
1735
|
},
|
|
1742
1736
|
getBusinessId: () => apiConfig.businessId,
|
|
1743
1737
|
isAuthenticated: config.isAuthenticated || (() => false),
|
|
1744
|
-
logout: config.logout
|
|
1745
|
-
|
|
1746
|
-
}),
|
|
1738
|
+
logout: config.logout,
|
|
1739
|
+
setToken: config.setToken,
|
|
1747
1740
|
utils: {
|
|
1748
1741
|
getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock, storageUrl),
|
|
1749
1742
|
thumbnailUrl: (service) => thumbnailUrl(service, storageUrl),
|
|
@@ -1762,7 +1755,7 @@ function createArkySDK(config) {
|
|
|
1762
1755
|
if (autoGuest) {
|
|
1763
1756
|
Promise.resolve().then(async () => {
|
|
1764
1757
|
try {
|
|
1765
|
-
const tokens = await config.
|
|
1758
|
+
const tokens = await config.getToken();
|
|
1766
1759
|
if (!tokens.accessToken && !tokens.refreshToken) {
|
|
1767
1760
|
const guestToken = await userApi.getGuestToken({});
|
|
1768
1761
|
console.log("[SDK Init] Created guest token:", guestToken ? "Success" : "Failed");
|