arky-sdk 0.3.152 → 0.3.154

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 CHANGED
@@ -10,9 +10,10 @@ var PaymentMethodType = /* @__PURE__ */ ((PaymentMethodType2) => {
10
10
 
11
11
  // src/utils/errors.ts
12
12
  var convertServerErrorToRequestError = (serverError, renameRules) => {
13
+ const validationErrors = serverError?.validationErrors ?? [];
13
14
  return {
14
15
  ...serverError,
15
- validationErrors: serverError.validationErrors.map((validationError) => {
16
+ validationErrors: validationErrors.map((validationError) => {
16
17
  const field = validationError.field;
17
18
  return {
18
19
  field,
@@ -46,14 +47,14 @@ function buildQueryString(params) {
46
47
 
47
48
  // src/services/createHttpClient.ts
48
49
  function createHttpClient(cfg) {
49
- const refreshEndpoint = `${cfg.baseUrl}/v1/accounts/refresh-access-token`;
50
+ const refreshEndpoint = `${cfg.baseUrl}/v1/auth/refresh`;
50
51
  let refreshPromise = null;
51
52
  async function ensureFreshToken() {
52
53
  if (refreshPromise) {
53
54
  return refreshPromise;
54
55
  }
55
56
  refreshPromise = (async () => {
56
- const { refreshToken, provider } = await cfg.getToken();
57
+ const { refreshToken } = await cfg.getToken();
57
58
  if (!refreshToken) {
58
59
  cfg.logout();
59
60
  const err = new Error("No refresh token available");
@@ -64,7 +65,7 @@ function createHttpClient(cfg) {
64
65
  const refRes = await fetch(refreshEndpoint, {
65
66
  method: "POST",
66
67
  headers: { Accept: "application/json", "Content-Type": "application/json" },
67
- body: JSON.stringify({ provider, refreshToken })
68
+ body: JSON.stringify({ refreshToken })
68
69
  });
69
70
  if (!refRes.ok) {
70
71
  cfg.logout();
@@ -247,20 +248,6 @@ var createAccountApi = (apiConfig) => {
247
248
  async setRole(params, options) {
248
249
  return apiConfig.httpClient.put("/v1/accounts/set-role", params, options);
249
250
  },
250
- // ===== AUTHENTICATION =====
251
- async login(params, options) {
252
- return apiConfig.httpClient.post("/v1/accounts/login", params, options);
253
- },
254
- async logout(params, options) {
255
- return apiConfig.httpClient.post("/v1/accounts/logout", {}, options);
256
- },
257
- // ===== MAGIC LINK =====
258
- async requestMagicLink(params, options) {
259
- return apiConfig.httpClient.post("/v1/accounts/magic-link/request", params, options);
260
- },
261
- async verifyMagicLink(params, options) {
262
- return apiConfig.httpClient.post("/v1/accounts/magic-link/verify", params, options);
263
- },
264
251
  // ===== SUBSCRIPTION =====
265
252
  async subscribe(params, options) {
266
253
  return apiConfig.httpClient.post("/v1/accounts/subscribe", params, options);
@@ -268,6 +255,40 @@ var createAccountApi = (apiConfig) => {
268
255
  };
269
256
  };
270
257
 
258
+ // src/api/auth.ts
259
+ var createAuthApi = (apiConfig) => {
260
+ return {
261
+ /**
262
+ * Create a guest session (anonymous user)
263
+ * POST /auth/session
264
+ */
265
+ async session(options) {
266
+ return apiConfig.httpClient.post("/v1/auth/session", {}, options);
267
+ },
268
+ /**
269
+ * Request a magic link to be sent to email
270
+ * POST /auth/magic-link
271
+ */
272
+ async magicLink(params, options) {
273
+ return apiConfig.httpClient.post("/v1/auth/magic-link", params, options);
274
+ },
275
+ /**
276
+ * Verify magic link token and get auth tokens
277
+ * POST /auth/verify
278
+ */
279
+ async verify(params, options) {
280
+ return apiConfig.httpClient.post("/v1/auth/verify", params, options);
281
+ },
282
+ /**
283
+ * Refresh access token
284
+ * POST /auth/refresh
285
+ */
286
+ async refresh(params, options) {
287
+ return apiConfig.httpClient.post("/v1/auth/refresh", params, options);
288
+ }
289
+ };
290
+ };
291
+
271
292
  // src/api/business.ts
272
293
  var createBusinessApi = (apiConfig) => {
273
294
  return {
@@ -1899,7 +1920,7 @@ function nameToKey(name) {
1899
1920
  }
1900
1921
 
1901
1922
  // src/index.ts
1902
- var SDK_VERSION = "0.3.145";
1923
+ var SDK_VERSION = "0.3.154";
1903
1924
  var SUPPORTED_FRAMEWORKS = [
1904
1925
  "astro",
1905
1926
  "react",
@@ -1920,14 +1941,13 @@ async function createArkySDK(config) {
1920
1941
  getToken: config.getToken
1921
1942
  };
1922
1943
  const accountApi = createAccountApi(apiConfig);
1944
+ const authApi = createAuthApi(apiConfig);
1923
1945
  const autoGuest = config.autoGuest !== void 0 ? config.autoGuest : true;
1924
1946
  if (autoGuest) {
1925
1947
  try {
1926
1948
  const tokens = await config.getToken();
1927
1949
  if (!tokens.accessToken && !tokens.refreshToken) {
1928
- const result = await httpClient.post("/v1/accounts/login", {
1929
- provider: "GUEST"
1930
- });
1950
+ const result = await httpClient.post("/v1/auth/session", {});
1931
1951
  const token = result.accessToken || result.token || "";
1932
1952
  if (token) {
1933
1953
  config.setToken(result);
@@ -1937,6 +1957,7 @@ async function createArkySDK(config) {
1937
1957
  }
1938
1958
  }
1939
1959
  const sdk = {
1960
+ auth: authApi,
1940
1961
  account: accountApi,
1941
1962
  business: createBusinessApi(apiConfig),
1942
1963
  media: createMediaApi(apiConfig),