arky-sdk 0.3.8 → 0.3.10
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 +246 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +246 -18
- package/dist/index.js.map +1 -1
- package/dist/{timezone-Cnh6zsAn.d.ts → svg-BhIM4HZW.d.ts} +43 -1
- package/dist/{timezone-Ctc3v4hK.d.cts → svg-CFjyTGXu.d.cts} +43 -1
- package/dist/types.d.cts +0 -71
- package/dist/types.d.ts +0 -71
- package/dist/utils.d.cts +2 -44
- package/dist/utils.d.ts +2 -44
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UpdateUserProfileParams, RequestOptions, UpdateProfilePhoneParams, VerifyPhoneCodeParams, GetUsersParams, SetRoleParams, LoginUserParams, RegisterUserParams, ConfirmUserParams, GetLoginUrlParams, ForgotPasswordParams, ResetForgotPasswordParams, ResetPasswordParams, CreateBusinessParams, UpdateBusinessParams, DeleteBusinessParams, GetBusinessParams, GetBusinessParentsParams, TriggerBuildsParams, GetSubscriptionParams, CreateSubscriptionParams, UpdateSubscriptionParams, CancelSubscriptionParams, ReactivateSubscriptionParams, CreatePortalSessionParams, InviteUserParams, HandleInvitationParams, TestWebhookParams, UploadBusinessMediaParams, DeleteBusinessMediaParams, GetBusinessMediaParams, CreateRoleParams, UpdateRoleParams, DeleteRoleParams, GetRoleParams, GetRolesParams, GetNotificationsParams, TrackEmailOpenParams, GetDeliveryStatsParams, CreatePromoCodeParams, UpdatePromoCodeParams, DeletePromoCodeParams, GetPromoCodeParams, GetPromoCodesParams, GetAnalyticsParams, GetAnalyticsHealthParams, SetupAnalyticsParams, CreateCollectionParams, UpdateCollectionParams, DeleteCollectionParams, GetCollectionParams, GetCollectionsParams, GetEntriesParams, CreateEntryParams, UpdateEntryParams, DeleteCollectionEntryParams, GetCollectionEntryParams, SendEntryParams, GetVariableMetadataParams, CreateProductParams, UpdateProductParams, GetProductParams, GetProductsParams, CreateOrderParams, UpdateOrderParams, GetOrderParams, GetOrdersParams, UpdateOrderStatusParams, UpdateOrderPaymentStatusParams, GetQuoteParams, CheckoutParams, CreateReservationParams, UpdateReservationParams, ReservationCheckoutParams, GetReservationParams, GetReservationPartsParams, SearchReservationsParams, SearchMyReservationsParams, GetReservationQuoteParams, CreateServiceParams, UpdateServiceParams, DeleteServiceParams, GetServiceParams, GetServicesParams, GetAvailableSlotsParams, CreateProviderParams, UpdateProviderParams, DeleteProviderParams, GetProviderParams, GetProvidersParams, GetBusinessServiceWorkingTimeParams, NewsletterFindParams, NewsletterGetParams, CreateNewsletterParams, UpdateNewsletterParams, DeleteNewsletterParams, GetSubscribersParams, NewsletterSubscribeParams, UnsubscribeParams, HandleStripeWebhookParams, GetBusinessMarketsParams, GetBusinessMarketParams } from './types.cjs';
|
|
2
2
|
export { ApiResponse, Block, Business, EshopCartItem, EshopStoreState, Price, ReservationCartPart, ReservationStoreState } from './types.cjs';
|
|
3
|
-
import { g as getGalleryThumbnail, a as
|
|
3
|
+
import { g as getGalleryThumbnail, a as getBlockLabel, b as getBlockTextValue, f as formatBlockValue, p as prepareBlocksForSubmission, e as extractBlockValues, c as getMarketPrice, d as getPriceAmount, h as formatPayment, i as formatMinor, j as createPaymentForCheckout, k as getCurrencySymbol, v as validatePhoneNumber, l as findTimeZone, s as slugify, m as humanize, n as categorify, o as formatDate, q as getSvgContentForAstro, r as fetchSvgContent, t as injectSvgIntoElement } from './svg-CFjyTGXu.cjs';
|
|
4
4
|
|
|
5
5
|
interface AuthTokens {
|
|
6
6
|
accessToken: string;
|
|
@@ -26,7 +26,7 @@ interface HttpClientConfig {
|
|
|
26
26
|
isAuthenticated?: () => boolean;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
declare const SDK_VERSION = "0.3.
|
|
29
|
+
declare const SDK_VERSION = "0.3.9";
|
|
30
30
|
declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
|
|
31
31
|
interface ApiConfig {
|
|
32
32
|
httpClient: any;
|
|
@@ -200,6 +200,15 @@ declare function createArkySDK(config: HttpClientConfig & {
|
|
|
200
200
|
getImageUrl: (imageBlock: any, isBlock?: boolean) => any;
|
|
201
201
|
thumbnailUrl: (service: any) => string;
|
|
202
202
|
getGalleryThumbnail: typeof getGalleryThumbnail;
|
|
203
|
+
getBlockValue: (entry: any, blockKey: string) => any;
|
|
204
|
+
getBlockValues: (entry: any, blockKey: string) => any;
|
|
205
|
+
getBlockLabel: typeof getBlockLabel;
|
|
206
|
+
getBlockTextValue: typeof getBlockTextValue;
|
|
207
|
+
getBlockObjectValues: (entry: any, blockKey: string, locale?: string) => any;
|
|
208
|
+
getBlockFromArray: (entry: any, blockKey: string, locale?: string) => any;
|
|
209
|
+
formatBlockValue: typeof formatBlockValue;
|
|
210
|
+
prepareBlocksForSubmission: typeof prepareBlocksForSubmission;
|
|
211
|
+
extractBlockValues: typeof extractBlockValues;
|
|
203
212
|
getMarketPrice: typeof getMarketPrice;
|
|
204
213
|
getPriceAmount: typeof getPriceAmount;
|
|
205
214
|
formatPayment: typeof formatPayment;
|
|
@@ -215,6 +224,13 @@ declare function createArkySDK(config: HttpClientConfig & {
|
|
|
215
224
|
}[];
|
|
216
225
|
}[];
|
|
217
226
|
findTimeZone: typeof findTimeZone;
|
|
227
|
+
slugify: typeof slugify;
|
|
228
|
+
humanize: typeof humanize;
|
|
229
|
+
categorify: typeof categorify;
|
|
230
|
+
formatDate: typeof formatDate;
|
|
231
|
+
getSvgContentForAstro: typeof getSvgContentForAstro;
|
|
232
|
+
fetchSvgContent: typeof fetchSvgContent;
|
|
233
|
+
injectSvgIntoElement: typeof injectSvgIntoElement;
|
|
218
234
|
};
|
|
219
235
|
};
|
|
220
236
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UpdateUserProfileParams, RequestOptions, UpdateProfilePhoneParams, VerifyPhoneCodeParams, GetUsersParams, SetRoleParams, LoginUserParams, RegisterUserParams, ConfirmUserParams, GetLoginUrlParams, ForgotPasswordParams, ResetForgotPasswordParams, ResetPasswordParams, CreateBusinessParams, UpdateBusinessParams, DeleteBusinessParams, GetBusinessParams, GetBusinessParentsParams, TriggerBuildsParams, GetSubscriptionParams, CreateSubscriptionParams, UpdateSubscriptionParams, CancelSubscriptionParams, ReactivateSubscriptionParams, CreatePortalSessionParams, InviteUserParams, HandleInvitationParams, TestWebhookParams, UploadBusinessMediaParams, DeleteBusinessMediaParams, GetBusinessMediaParams, CreateRoleParams, UpdateRoleParams, DeleteRoleParams, GetRoleParams, GetRolesParams, GetNotificationsParams, TrackEmailOpenParams, GetDeliveryStatsParams, CreatePromoCodeParams, UpdatePromoCodeParams, DeletePromoCodeParams, GetPromoCodeParams, GetPromoCodesParams, GetAnalyticsParams, GetAnalyticsHealthParams, SetupAnalyticsParams, CreateCollectionParams, UpdateCollectionParams, DeleteCollectionParams, GetCollectionParams, GetCollectionsParams, GetEntriesParams, CreateEntryParams, UpdateEntryParams, DeleteCollectionEntryParams, GetCollectionEntryParams, SendEntryParams, GetVariableMetadataParams, CreateProductParams, UpdateProductParams, GetProductParams, GetProductsParams, CreateOrderParams, UpdateOrderParams, GetOrderParams, GetOrdersParams, UpdateOrderStatusParams, UpdateOrderPaymentStatusParams, GetQuoteParams, CheckoutParams, CreateReservationParams, UpdateReservationParams, ReservationCheckoutParams, GetReservationParams, GetReservationPartsParams, SearchReservationsParams, SearchMyReservationsParams, GetReservationQuoteParams, CreateServiceParams, UpdateServiceParams, DeleteServiceParams, GetServiceParams, GetServicesParams, GetAvailableSlotsParams, CreateProviderParams, UpdateProviderParams, DeleteProviderParams, GetProviderParams, GetProvidersParams, GetBusinessServiceWorkingTimeParams, NewsletterFindParams, NewsletterGetParams, CreateNewsletterParams, UpdateNewsletterParams, DeleteNewsletterParams, GetSubscribersParams, NewsletterSubscribeParams, UnsubscribeParams, HandleStripeWebhookParams, GetBusinessMarketsParams, GetBusinessMarketParams } from './types.js';
|
|
2
2
|
export { ApiResponse, Block, Business, EshopCartItem, EshopStoreState, Price, ReservationCartPart, ReservationStoreState } from './types.js';
|
|
3
|
-
import { g as getGalleryThumbnail, a as
|
|
3
|
+
import { g as getGalleryThumbnail, a as getBlockLabel, b as getBlockTextValue, f as formatBlockValue, p as prepareBlocksForSubmission, e as extractBlockValues, c as getMarketPrice, d as getPriceAmount, h as formatPayment, i as formatMinor, j as createPaymentForCheckout, k as getCurrencySymbol, v as validatePhoneNumber, l as findTimeZone, s as slugify, m as humanize, n as categorify, o as formatDate, q as getSvgContentForAstro, r as fetchSvgContent, t as injectSvgIntoElement } from './svg-BhIM4HZW.js';
|
|
4
4
|
|
|
5
5
|
interface AuthTokens {
|
|
6
6
|
accessToken: string;
|
|
@@ -26,7 +26,7 @@ interface HttpClientConfig {
|
|
|
26
26
|
isAuthenticated?: () => boolean;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
declare const SDK_VERSION = "0.3.
|
|
29
|
+
declare const SDK_VERSION = "0.3.9";
|
|
30
30
|
declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
|
|
31
31
|
interface ApiConfig {
|
|
32
32
|
httpClient: any;
|
|
@@ -200,6 +200,15 @@ declare function createArkySDK(config: HttpClientConfig & {
|
|
|
200
200
|
getImageUrl: (imageBlock: any, isBlock?: boolean) => any;
|
|
201
201
|
thumbnailUrl: (service: any) => string;
|
|
202
202
|
getGalleryThumbnail: typeof getGalleryThumbnail;
|
|
203
|
+
getBlockValue: (entry: any, blockKey: string) => any;
|
|
204
|
+
getBlockValues: (entry: any, blockKey: string) => any;
|
|
205
|
+
getBlockLabel: typeof getBlockLabel;
|
|
206
|
+
getBlockTextValue: typeof getBlockTextValue;
|
|
207
|
+
getBlockObjectValues: (entry: any, blockKey: string, locale?: string) => any;
|
|
208
|
+
getBlockFromArray: (entry: any, blockKey: string, locale?: string) => any;
|
|
209
|
+
formatBlockValue: typeof formatBlockValue;
|
|
210
|
+
prepareBlocksForSubmission: typeof prepareBlocksForSubmission;
|
|
211
|
+
extractBlockValues: typeof extractBlockValues;
|
|
203
212
|
getMarketPrice: typeof getMarketPrice;
|
|
204
213
|
getPriceAmount: typeof getPriceAmount;
|
|
205
214
|
formatPayment: typeof formatPayment;
|
|
@@ -215,6 +224,13 @@ declare function createArkySDK(config: HttpClientConfig & {
|
|
|
215
224
|
}[];
|
|
216
225
|
}[];
|
|
217
226
|
findTimeZone: typeof findTimeZone;
|
|
227
|
+
slugify: typeof slugify;
|
|
228
|
+
humanize: typeof humanize;
|
|
229
|
+
categorify: typeof categorify;
|
|
230
|
+
formatDate: typeof formatDate;
|
|
231
|
+
getSvgContentForAstro: typeof getSvgContentForAstro;
|
|
232
|
+
fetchSvgContent: typeof fetchSvgContent;
|
|
233
|
+
injectSvgIntoElement: typeof injectSvgIntoElement;
|
|
218
234
|
};
|
|
219
235
|
};
|
|
220
236
|
|
package/dist/index.js
CHANGED
|
@@ -266,7 +266,7 @@ var createBusinessApi = (apiConfig) => {
|
|
|
266
266
|
return apiConfig.httpClient.get(`/v1/businesses`, options);
|
|
267
267
|
},
|
|
268
268
|
async getBusinessParents(params, options) {
|
|
269
|
-
return apiConfig.httpClient.get(`/v1/businesses/${
|
|
269
|
+
return apiConfig.httpClient.get(`/v1/businesses/${apiConfig.businessId}/parents`, options);
|
|
270
270
|
},
|
|
271
271
|
async triggerBuilds(params, options) {
|
|
272
272
|
return apiConfig.httpClient.post(`/v1/businesses/${params.id}/trigger-builds`, {}, options);
|
|
@@ -275,61 +275,59 @@ var createBusinessApi = (apiConfig) => {
|
|
|
275
275
|
return apiConfig.httpClient.get("/v1/businesses/plans", options);
|
|
276
276
|
},
|
|
277
277
|
async getSubscription(params, options) {
|
|
278
|
-
return apiConfig.httpClient.get(`/v1/businesses/${
|
|
278
|
+
return apiConfig.httpClient.get(`/v1/businesses/${apiConfig.businessId}/subscription`, options);
|
|
279
279
|
},
|
|
280
280
|
async createSubscription(params, options) {
|
|
281
281
|
return apiConfig.httpClient.post(
|
|
282
|
-
`/v1/businesses/${
|
|
282
|
+
`/v1/businesses/${apiConfig.businessId}/subscription`,
|
|
283
283
|
params,
|
|
284
284
|
options
|
|
285
285
|
);
|
|
286
286
|
},
|
|
287
287
|
async updateSubscription(params, options) {
|
|
288
288
|
return apiConfig.httpClient.put(
|
|
289
|
-
`/v1/businesses/${
|
|
289
|
+
`/v1/businesses/${apiConfig.businessId}/subscription`,
|
|
290
290
|
params,
|
|
291
291
|
options
|
|
292
292
|
);
|
|
293
293
|
},
|
|
294
294
|
async cancelSubscription(params, options) {
|
|
295
|
-
return apiConfig.httpClient.delete(`/v1/businesses/${
|
|
295
|
+
return apiConfig.httpClient.delete(`/v1/businesses/${apiConfig.businessId}/subscription`, {
|
|
296
296
|
...options,
|
|
297
297
|
params: { immediately: params.immediately || false }
|
|
298
298
|
});
|
|
299
299
|
},
|
|
300
300
|
async reactivateSubscription(params, options) {
|
|
301
301
|
return apiConfig.httpClient.post(
|
|
302
|
-
`/v1/businesses/${
|
|
302
|
+
`/v1/businesses/${apiConfig.businessId}/subscription/reactivate`,
|
|
303
303
|
params,
|
|
304
304
|
options
|
|
305
305
|
);
|
|
306
306
|
},
|
|
307
307
|
async createPortalSession(params, options) {
|
|
308
308
|
return apiConfig.httpClient.post(
|
|
309
|
-
`/v1/businesses/${
|
|
309
|
+
`/v1/businesses/${apiConfig.businessId}/subscription/portal`,
|
|
310
310
|
params,
|
|
311
311
|
options
|
|
312
312
|
);
|
|
313
313
|
},
|
|
314
314
|
async inviteUser(params, options) {
|
|
315
|
-
const { businessId, ...payload } = params;
|
|
316
315
|
return apiConfig.httpClient.post(
|
|
317
|
-
`/v1/businesses/${businessId}/invitation`,
|
|
318
|
-
|
|
316
|
+
`/v1/businesses/${apiConfig.businessId}/invitation`,
|
|
317
|
+
params,
|
|
319
318
|
options
|
|
320
319
|
);
|
|
321
320
|
},
|
|
322
321
|
async handleInvitation(params, options) {
|
|
323
|
-
const { businessId, ...payload } = params;
|
|
324
322
|
return apiConfig.httpClient.put(
|
|
325
|
-
`/v1/businesses/${businessId}/invitation`,
|
|
326
|
-
|
|
323
|
+
`/v1/businesses/${apiConfig.businessId}/invitation`,
|
|
324
|
+
params,
|
|
327
325
|
options
|
|
328
326
|
);
|
|
329
327
|
},
|
|
330
328
|
async testWebhook(params, options) {
|
|
331
329
|
return apiConfig.httpClient.post(
|
|
332
|
-
`/v1/businesses/${
|
|
330
|
+
`/v1/businesses/${apiConfig.businessId}/webhooks/test`,
|
|
333
331
|
params.webhook,
|
|
334
332
|
options
|
|
335
333
|
);
|
|
@@ -802,7 +800,7 @@ var createReservationApi = (apiConfig) => {
|
|
|
802
800
|
async getReservation(params, options) {
|
|
803
801
|
return apiConfig.httpClient.get(`/v1/reservations/${params.id}`, {
|
|
804
802
|
...options,
|
|
805
|
-
params:
|
|
803
|
+
params: { businessId: apiConfig.businessId }
|
|
806
804
|
});
|
|
807
805
|
},
|
|
808
806
|
async getReservationParts(params, options) {
|
|
@@ -971,7 +969,7 @@ var createNewsletterApi = (apiConfig) => {
|
|
|
971
969
|
async find(params, options) {
|
|
972
970
|
return apiConfig.httpClient.get(`/v1/newsletters`, {
|
|
973
971
|
...options,
|
|
974
|
-
params: { businessId:
|
|
972
|
+
params: { businessId: apiConfig.businessId }
|
|
975
973
|
});
|
|
976
974
|
},
|
|
977
975
|
async get(params, options) {
|
|
@@ -1039,6 +1037,135 @@ var createPaymentApi = (apiConfig) => {
|
|
|
1039
1037
|
};
|
|
1040
1038
|
|
|
1041
1039
|
// src/utils/blocks.ts
|
|
1040
|
+
function getBlockLabel(block, locale = "en") {
|
|
1041
|
+
if (!block) return "";
|
|
1042
|
+
if (block.properties?.label) {
|
|
1043
|
+
if (typeof block.properties.label === "object") {
|
|
1044
|
+
return block.properties.label[locale] || block.properties.label.en || Object.values(block.properties.label)[0] || "";
|
|
1045
|
+
}
|
|
1046
|
+
if (typeof block.properties.label === "string") {
|
|
1047
|
+
return block.properties.label;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
return block.key?.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()) || "";
|
|
1051
|
+
}
|
|
1052
|
+
function formatBlockValue(block) {
|
|
1053
|
+
if (!block || block.value === null || block.value === void 0) {
|
|
1054
|
+
return "";
|
|
1055
|
+
}
|
|
1056
|
+
switch (block.type) {
|
|
1057
|
+
case "BOOLEAN":
|
|
1058
|
+
return block.value ? "Yes" : "No";
|
|
1059
|
+
case "NUMBER":
|
|
1060
|
+
if (block.properties?.variant === "DATE" || block.properties?.variant === "DATE_TIME") {
|
|
1061
|
+
try {
|
|
1062
|
+
return new Date(block.value).toLocaleDateString();
|
|
1063
|
+
} catch (e) {
|
|
1064
|
+
return String(block.value);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
return String(block.value);
|
|
1068
|
+
case "RELATIONSHIP":
|
|
1069
|
+
if (Array.isArray(block.value) && block.value.length > 0) {
|
|
1070
|
+
const firstValue = block.value[0];
|
|
1071
|
+
if (firstValue && firstValue.mimeType) {
|
|
1072
|
+
return firstValue.name || firstValue.id || "Media";
|
|
1073
|
+
}
|
|
1074
|
+
return firstValue.title || firstValue.name || firstValue.id || "Entry";
|
|
1075
|
+
}
|
|
1076
|
+
return String(block.value);
|
|
1077
|
+
default:
|
|
1078
|
+
return String(block.value);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
function prepareBlocksForSubmission(formData) {
|
|
1082
|
+
const preparedBlocks = [];
|
|
1083
|
+
Object.keys(formData).forEach((key) => {
|
|
1084
|
+
if (formData[key] !== null && formData[key] !== void 0) {
|
|
1085
|
+
preparedBlocks.push({
|
|
1086
|
+
key,
|
|
1087
|
+
value: [formData[key]]
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
1091
|
+
return preparedBlocks;
|
|
1092
|
+
}
|
|
1093
|
+
function extractBlockValues(blocks) {
|
|
1094
|
+
const values = {};
|
|
1095
|
+
blocks.forEach((block) => {
|
|
1096
|
+
if (block.value && block.value.length > 0) {
|
|
1097
|
+
values[block.key] = block.value[0];
|
|
1098
|
+
} else {
|
|
1099
|
+
values[block.key] = null;
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
return values;
|
|
1103
|
+
}
|
|
1104
|
+
function getBlockTextValue(block, locale = "en") {
|
|
1105
|
+
if (!block || !block.value || block.value.length === 0) return "";
|
|
1106
|
+
const firstValue = block.value[0];
|
|
1107
|
+
if (typeof firstValue === "object" && firstValue !== null) {
|
|
1108
|
+
if (firstValue[locale]) return firstValue[locale];
|
|
1109
|
+
if (firstValue.en) return firstValue.en;
|
|
1110
|
+
const values = Object.values(firstValue);
|
|
1111
|
+
return String(values[0] || "");
|
|
1112
|
+
}
|
|
1113
|
+
return String(firstValue);
|
|
1114
|
+
}
|
|
1115
|
+
var getBlockValue = (entry, blockKey) => {
|
|
1116
|
+
if (!entry || !entry.blocks) return null;
|
|
1117
|
+
const block = entry.blocks.find((f) => f.key === blockKey);
|
|
1118
|
+
if (!block || !block.value || block.value.length === 0) return null;
|
|
1119
|
+
return block.value[0];
|
|
1120
|
+
};
|
|
1121
|
+
var getBlockValues = (entry, blockKey) => {
|
|
1122
|
+
if (!entry || !entry.blocks) return null;
|
|
1123
|
+
const block = entry.blocks.find((f) => f.key === blockKey);
|
|
1124
|
+
if (!block || !block.value || block.value.length === 0) return null;
|
|
1125
|
+
return block.value;
|
|
1126
|
+
};
|
|
1127
|
+
function unwrapBlock(block, locale) {
|
|
1128
|
+
if (!block?.type || block.value === void 0) return block;
|
|
1129
|
+
if (block.type === "BLOCK") {
|
|
1130
|
+
return block.value.map((obj) => {
|
|
1131
|
+
const parsed = {};
|
|
1132
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
1133
|
+
parsed[k] = unwrapBlock(v, locale);
|
|
1134
|
+
}
|
|
1135
|
+
return parsed;
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
const isLocalized = block.type === "TEXT";
|
|
1139
|
+
const isList = block.properties?.ui === "list" || (block.properties?.maxValues ?? 1) > 1 || block.value.length > 1;
|
|
1140
|
+
if (isList) {
|
|
1141
|
+
return isLocalized ? block.value.map((v) => v[locale] || v["en"]) : [...block.value];
|
|
1142
|
+
}
|
|
1143
|
+
return isLocalized ? block.value[0][locale] || block.value[0]["en"] : block.value[0];
|
|
1144
|
+
}
|
|
1145
|
+
var getBlockObjectValues = (entry, blockKey, locale = "en") => {
|
|
1146
|
+
if (!entry) {
|
|
1147
|
+
return [];
|
|
1148
|
+
}
|
|
1149
|
+
const values = getBlockValues(entry, blockKey);
|
|
1150
|
+
const parsed = values.map((obj) => {
|
|
1151
|
+
const res = obj.value.reduce((acc, current) => {
|
|
1152
|
+
acc[current.key] = unwrapBlock(current, locale);
|
|
1153
|
+
return acc;
|
|
1154
|
+
}, {});
|
|
1155
|
+
return res;
|
|
1156
|
+
});
|
|
1157
|
+
return parsed;
|
|
1158
|
+
};
|
|
1159
|
+
var getBlockFromArray = (entry, blockKey, locale = "en") => {
|
|
1160
|
+
if (!entry) {
|
|
1161
|
+
return [];
|
|
1162
|
+
}
|
|
1163
|
+
const values = getBlockValues(entry, blockKey);
|
|
1164
|
+
return values.reduce((acc, current) => {
|
|
1165
|
+
acc[current.key] = unwrapBlock(current, locale);
|
|
1166
|
+
return acc;
|
|
1167
|
+
});
|
|
1168
|
+
};
|
|
1042
1169
|
var getImageUrl = (imageBlock, isBlock = true, storageUrl = "https://storage.arky.io/dev") => {
|
|
1043
1170
|
if (!imageBlock) return null;
|
|
1044
1171
|
const isExternalUrl = (url) => {
|
|
@@ -1360,8 +1487,86 @@ function findTimeZone(groups) {
|
|
|
1360
1487
|
}
|
|
1361
1488
|
}
|
|
1362
1489
|
|
|
1490
|
+
// src/utils/text.ts
|
|
1491
|
+
var locales = ["en", "sr-latn"];
|
|
1492
|
+
var localeMap = {
|
|
1493
|
+
"en": "en-US",
|
|
1494
|
+
"sr-latn": "sr-RS"
|
|
1495
|
+
};
|
|
1496
|
+
function slugify(text) {
|
|
1497
|
+
return text.toString().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
1498
|
+
}
|
|
1499
|
+
function humanize(text) {
|
|
1500
|
+
const slugifiedText = slugify(text);
|
|
1501
|
+
return slugifiedText.replace(/-/g, " ").replace(
|
|
1502
|
+
// upper case first letter of every word, and lower case the rest
|
|
1503
|
+
/\w\S*/g,
|
|
1504
|
+
(w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()
|
|
1505
|
+
);
|
|
1506
|
+
}
|
|
1507
|
+
function categorify(text) {
|
|
1508
|
+
const slugifiedText = slugify(text);
|
|
1509
|
+
return slugifiedText.replace(/-/g, " ").toUpperCase();
|
|
1510
|
+
}
|
|
1511
|
+
function formatDate(date, locale) {
|
|
1512
|
+
let localeString = "en-US";
|
|
1513
|
+
if (locales.includes(locale)) {
|
|
1514
|
+
localeString = localeMap[locale];
|
|
1515
|
+
}
|
|
1516
|
+
return new Date(date).toLocaleDateString(localeString, {
|
|
1517
|
+
timeZone: "UTC",
|
|
1518
|
+
year: "numeric",
|
|
1519
|
+
month: "short",
|
|
1520
|
+
day: "numeric"
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
// src/utils/svg.ts
|
|
1525
|
+
async function fetchSvgContent(mediaObject) {
|
|
1526
|
+
if (!mediaObject) return null;
|
|
1527
|
+
const svgUrl = getImageUrl(mediaObject, false);
|
|
1528
|
+
try {
|
|
1529
|
+
const response = await fetch(svgUrl);
|
|
1530
|
+
if (!response.ok) {
|
|
1531
|
+
console.error(`Failed to fetch SVG: ${response.status} ${response.statusText}`);
|
|
1532
|
+
return null;
|
|
1533
|
+
}
|
|
1534
|
+
const svgContent = await response.text();
|
|
1535
|
+
return svgContent;
|
|
1536
|
+
} catch (error) {
|
|
1537
|
+
console.error("Error fetching SVG:", error);
|
|
1538
|
+
return null;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
async function getSvgContentForAstro(mediaObject) {
|
|
1542
|
+
try {
|
|
1543
|
+
const svgContent = await fetchSvgContent(mediaObject);
|
|
1544
|
+
return svgContent || "";
|
|
1545
|
+
} catch (error) {
|
|
1546
|
+
console.error("Error getting SVG content for Astro:", error);
|
|
1547
|
+
return "";
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
async function injectSvgIntoElement(mediaObject, targetElement, className) {
|
|
1551
|
+
if (!targetElement) return;
|
|
1552
|
+
try {
|
|
1553
|
+
const svgContent = await fetchSvgContent(mediaObject);
|
|
1554
|
+
if (svgContent) {
|
|
1555
|
+
targetElement.innerHTML = svgContent;
|
|
1556
|
+
if (className) {
|
|
1557
|
+
const svgElement = targetElement.querySelector("svg");
|
|
1558
|
+
if (svgElement) {
|
|
1559
|
+
svgElement.classList.add(...className.split(" "));
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
} catch (error) {
|
|
1564
|
+
console.error("Error injecting SVG:", error);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1363
1568
|
// src/index.ts
|
|
1364
|
-
var SDK_VERSION = "0.3.
|
|
1569
|
+
var SDK_VERSION = "0.3.9";
|
|
1365
1570
|
var SUPPORTED_FRAMEWORKS = [
|
|
1366
1571
|
"astro",
|
|
1367
1572
|
"react",
|
|
@@ -1411,18 +1616,41 @@ function createArkySDK(config) {
|
|
|
1411
1616
|
logout: config.logout,
|
|
1412
1617
|
setToken: config.setToken,
|
|
1413
1618
|
utils: {
|
|
1619
|
+
// Block utilities
|
|
1414
1620
|
getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock, storageUrl),
|
|
1415
1621
|
thumbnailUrl: (service) => thumbnailUrl(service, storageUrl),
|
|
1416
1622
|
getGalleryThumbnail,
|
|
1623
|
+
getBlockValue,
|
|
1624
|
+
getBlockValues,
|
|
1625
|
+
getBlockLabel,
|
|
1626
|
+
getBlockTextValue,
|
|
1627
|
+
getBlockObjectValues,
|
|
1628
|
+
getBlockFromArray,
|
|
1629
|
+
formatBlockValue,
|
|
1630
|
+
prepareBlocksForSubmission,
|
|
1631
|
+
extractBlockValues,
|
|
1632
|
+
// Price utilities
|
|
1417
1633
|
getMarketPrice,
|
|
1418
1634
|
getPriceAmount,
|
|
1419
1635
|
formatPayment,
|
|
1420
1636
|
formatMinor,
|
|
1421
1637
|
createPaymentForCheckout,
|
|
1638
|
+
// Currency utilities
|
|
1422
1639
|
getCurrencySymbol,
|
|
1640
|
+
// Validation utilities
|
|
1423
1641
|
validatePhoneNumber,
|
|
1642
|
+
// Timezone utilities
|
|
1424
1643
|
tzGroups,
|
|
1425
|
-
findTimeZone
|
|
1644
|
+
findTimeZone,
|
|
1645
|
+
// Text utilities
|
|
1646
|
+
slugify,
|
|
1647
|
+
humanize,
|
|
1648
|
+
categorify,
|
|
1649
|
+
formatDate,
|
|
1650
|
+
// SVG utilities
|
|
1651
|
+
getSvgContentForAstro,
|
|
1652
|
+
fetchSvgContent,
|
|
1653
|
+
injectSvgIntoElement
|
|
1426
1654
|
}
|
|
1427
1655
|
};
|
|
1428
1656
|
if (autoGuest) {
|