arky-sdk 0.3.70 → 0.3.72

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
@@ -1188,6 +1188,135 @@ var createDatabaseApi = (apiConfig) => {
1188
1188
  };
1189
1189
  };
1190
1190
 
1191
+ // src/api/featureFlags.ts
1192
+ var createFeatureFlagsApi = (apiConfig) => {
1193
+ return {
1194
+ /**
1195
+ * Create a new feature flag
1196
+ */
1197
+ async createFlag(params, options) {
1198
+ return apiConfig.httpClient.post(
1199
+ `/v1/businesses/${apiConfig.businessId}/feature-flags`,
1200
+ params,
1201
+ options
1202
+ );
1203
+ },
1204
+ /**
1205
+ * Get a feature flag by ID
1206
+ */
1207
+ async getFlag(params, options) {
1208
+ return apiConfig.httpClient.get(
1209
+ `/v1/businesses/${apiConfig.businessId}/feature-flags/${params.id}`,
1210
+ options
1211
+ );
1212
+ },
1213
+ /**
1214
+ * List all feature flags for the business
1215
+ */
1216
+ async getFlags(params, options) {
1217
+ return apiConfig.httpClient.get(
1218
+ `/v1/businesses/${apiConfig.businessId}/feature-flags`,
1219
+ {
1220
+ ...options,
1221
+ params
1222
+ }
1223
+ );
1224
+ },
1225
+ /**
1226
+ * Update a feature flag
1227
+ */
1228
+ async updateFlag(params, options) {
1229
+ const { id, ...body } = params;
1230
+ return apiConfig.httpClient.put(
1231
+ `/v1/businesses/${apiConfig.businessId}/feature-flags/${id}`,
1232
+ body,
1233
+ options
1234
+ );
1235
+ },
1236
+ /**
1237
+ * Delete a feature flag
1238
+ */
1239
+ async deleteFlag(params, options) {
1240
+ return apiConfig.httpClient.delete(
1241
+ `/v1/businesses/${apiConfig.businessId}/feature-flags/${params.id}`,
1242
+ options
1243
+ );
1244
+ },
1245
+ /**
1246
+ * Get experiment results for a feature flag
1247
+ */
1248
+ async getResults(params, options) {
1249
+ return apiConfig.httpClient.get(
1250
+ `/v1/businesses/${apiConfig.businessId}/feature-flags/${params.id}/results`,
1251
+ options
1252
+ );
1253
+ },
1254
+ /**
1255
+ * Get the variant assignment for the current user
1256
+ * This is the main method for feature flag evaluation
1257
+ */
1258
+ async getVariant(params, options) {
1259
+ return apiConfig.httpClient.get(
1260
+ `/v1/businesses/${apiConfig.businessId}/feature-flags/key/${params.flagKey}/variant`,
1261
+ options
1262
+ );
1263
+ },
1264
+ /**
1265
+ * Track a conversion event for A/B testing
1266
+ */
1267
+ async trackEvent(params, options) {
1268
+ return apiConfig.httpClient.post(
1269
+ `/v1/businesses/${apiConfig.businessId}/feature-flags/track`,
1270
+ params,
1271
+ options
1272
+ );
1273
+ },
1274
+ // ===== CONVENIENCE METHODS =====
1275
+ /**
1276
+ * Check if a feature is enabled (returns true if variant is not 'control')
1277
+ * Convenience method for simple on/off flags
1278
+ */
1279
+ async isEnabled(flagKey) {
1280
+ try {
1281
+ const response = await this.getVariant({ flagKey });
1282
+ return response.variantKey !== "control";
1283
+ } catch {
1284
+ return false;
1285
+ }
1286
+ },
1287
+ /**
1288
+ * Get variant with payload, returning a default if flag not found
1289
+ * Useful for getting configuration values from variants
1290
+ */
1291
+ async getVariantWithDefault(flagKey, defaultValue) {
1292
+ try {
1293
+ const response = await this.getVariant({ flagKey });
1294
+ return {
1295
+ variantKey: response.variantKey,
1296
+ payload: response.payload ?? defaultValue
1297
+ };
1298
+ } catch {
1299
+ return {
1300
+ variantKey: "control",
1301
+ payload: defaultValue
1302
+ };
1303
+ }
1304
+ },
1305
+ /**
1306
+ * Activate a draft flag
1307
+ */
1308
+ async activateFlag(id) {
1309
+ return this.updateFlag({ id, status: "ACTIVE" });
1310
+ },
1311
+ /**
1312
+ * Archive an active flag
1313
+ */
1314
+ async archiveFlag(id) {
1315
+ return this.updateFlag({ id, status: "ARCHIVED" });
1316
+ }
1317
+ };
1318
+ };
1319
+
1191
1320
  // src/utils/currency.ts
1192
1321
  function getCurrencySymbol(currency) {
1193
1322
  const currencySymbols = {
@@ -1543,7 +1672,7 @@ async function injectSvgIntoElement(mediaObject, targetElement, className) {
1543
1672
  }
1544
1673
 
1545
1674
  // src/index.ts
1546
- var SDK_VERSION = "0.3.66";
1675
+ var SDK_VERSION = "0.3.72";
1547
1676
  var SUPPORTED_FRAMEWORKS = [
1548
1677
  "astro",
1549
1678
  "react",
@@ -1551,7 +1680,7 @@ var SUPPORTED_FRAMEWORKS = [
1551
1680
  "svelte",
1552
1681
  "vanilla"
1553
1682
  ];
1554
- function createArkySDK(config) {
1683
+ async function createArkySDK(config) {
1555
1684
  const locale = config.locale || "en";
1556
1685
  console.log(
1557
1686
  `[Arky SDK v${SDK_VERSION}] Initializing with market: ${config.market}, businessId: ${config.businessId}, locale: ${locale}`
@@ -1568,6 +1697,28 @@ function createArkySDK(config) {
1568
1697
  };
1569
1698
  const userApi = createUserApi(apiConfig);
1570
1699
  const autoGuest = config.autoGuest !== void 0 ? config.autoGuest : true;
1700
+ if (autoGuest) {
1701
+ try {
1702
+ const tokens = await config.getToken();
1703
+ if (!tokens.accessToken && !tokens.refreshToken) {
1704
+ const result = await httpClient.post("/v1/users/login", {
1705
+ provider: "GUEST"
1706
+ });
1707
+ const token = result.accessToken || result.token || "";
1708
+ if (token) {
1709
+ config.setToken(result);
1710
+ }
1711
+ console.log(
1712
+ "[SDK Init] Created guest token:",
1713
+ token ? "Success" : "Failed"
1714
+ );
1715
+ } else {
1716
+ console.log("[SDK Init] Using existing token from storage");
1717
+ }
1718
+ } catch (error) {
1719
+ console.error("[SDK Init] Failed to initialize auth:", error);
1720
+ }
1721
+ }
1571
1722
  const sdk = {
1572
1723
  user: userApi,
1573
1724
  business: createBusinessApi(apiConfig),
@@ -1580,6 +1731,7 @@ function createArkySDK(config) {
1580
1731
  eshop: createEshopApi(apiConfig),
1581
1732
  reservation: createReservationApi(apiConfig),
1582
1733
  database: createDatabaseApi(apiConfig),
1734
+ featureFlags: createFeatureFlagsApi(apiConfig),
1583
1735
  setBusinessId: (businessId) => {
1584
1736
  apiConfig.businessId = businessId;
1585
1737
  },
@@ -1595,6 +1747,8 @@ function createArkySDK(config) {
1595
1747
  isAuthenticated: config.isAuthenticated || (() => false),
1596
1748
  logout: config.logout,
1597
1749
  setToken: config.setToken,
1750
+ // Top-level block utilities for convenience
1751
+ extractBlockValues,
1598
1752
  utils: {
1599
1753
  // Block utilities
1600
1754
  getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock),
@@ -1631,30 +1785,6 @@ function createArkySDK(config) {
1631
1785
  injectSvgIntoElement
1632
1786
  }
1633
1787
  };
1634
- if (autoGuest) {
1635
- Promise.resolve().then(async () => {
1636
- try {
1637
- const tokens = await config.getToken();
1638
- if (!tokens.accessToken && !tokens.refreshToken) {
1639
- const result = await httpClient.post("/v1/users/login", {
1640
- provider: "GUEST"
1641
- });
1642
- const token = result.accessToken || result.token || "";
1643
- if (token) {
1644
- config.setToken(result);
1645
- }
1646
- console.log(
1647
- "[SDK Init] Created guest token:",
1648
- token ? "Success" : "Failed"
1649
- );
1650
- } else {
1651
- console.log("[SDK Init] Using existing token from storage");
1652
- }
1653
- } catch (error) {
1654
- console.error("[SDK Init] Failed to initialize auth:", error);
1655
- }
1656
- });
1657
- }
1658
1788
  return sdk;
1659
1789
  }
1660
1790