arky-sdk 0.3.8 → 0.3.9
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 +232 -2
- 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 +232 -2
- 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/utils.d.cts +2 -44
- package/dist/utils.d.ts +2 -44
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1041,6 +1041,135 @@ var createPaymentApi = (apiConfig) => {
|
|
|
1041
1041
|
};
|
|
1042
1042
|
|
|
1043
1043
|
// src/utils/blocks.ts
|
|
1044
|
+
function getBlockLabel(block, locale = "en") {
|
|
1045
|
+
if (!block) return "";
|
|
1046
|
+
if (block.properties?.label) {
|
|
1047
|
+
if (typeof block.properties.label === "object") {
|
|
1048
|
+
return block.properties.label[locale] || block.properties.label.en || Object.values(block.properties.label)[0] || "";
|
|
1049
|
+
}
|
|
1050
|
+
if (typeof block.properties.label === "string") {
|
|
1051
|
+
return block.properties.label;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
return block.key?.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()) || "";
|
|
1055
|
+
}
|
|
1056
|
+
function formatBlockValue(block) {
|
|
1057
|
+
if (!block || block.value === null || block.value === void 0) {
|
|
1058
|
+
return "";
|
|
1059
|
+
}
|
|
1060
|
+
switch (block.type) {
|
|
1061
|
+
case "BOOLEAN":
|
|
1062
|
+
return block.value ? "Yes" : "No";
|
|
1063
|
+
case "NUMBER":
|
|
1064
|
+
if (block.properties?.variant === "DATE" || block.properties?.variant === "DATE_TIME") {
|
|
1065
|
+
try {
|
|
1066
|
+
return new Date(block.value).toLocaleDateString();
|
|
1067
|
+
} catch (e) {
|
|
1068
|
+
return String(block.value);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
return String(block.value);
|
|
1072
|
+
case "RELATIONSHIP":
|
|
1073
|
+
if (Array.isArray(block.value) && block.value.length > 0) {
|
|
1074
|
+
const firstValue = block.value[0];
|
|
1075
|
+
if (firstValue && firstValue.mimeType) {
|
|
1076
|
+
return firstValue.name || firstValue.id || "Media";
|
|
1077
|
+
}
|
|
1078
|
+
return firstValue.title || firstValue.name || firstValue.id || "Entry";
|
|
1079
|
+
}
|
|
1080
|
+
return String(block.value);
|
|
1081
|
+
default:
|
|
1082
|
+
return String(block.value);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
function prepareBlocksForSubmission(formData) {
|
|
1086
|
+
const preparedBlocks = [];
|
|
1087
|
+
Object.keys(formData).forEach((key) => {
|
|
1088
|
+
if (formData[key] !== null && formData[key] !== void 0) {
|
|
1089
|
+
preparedBlocks.push({
|
|
1090
|
+
key,
|
|
1091
|
+
value: [formData[key]]
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
return preparedBlocks;
|
|
1096
|
+
}
|
|
1097
|
+
function extractBlockValues(blocks) {
|
|
1098
|
+
const values = {};
|
|
1099
|
+
blocks.forEach((block) => {
|
|
1100
|
+
if (block.value && block.value.length > 0) {
|
|
1101
|
+
values[block.key] = block.value[0];
|
|
1102
|
+
} else {
|
|
1103
|
+
values[block.key] = null;
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
return values;
|
|
1107
|
+
}
|
|
1108
|
+
function getBlockTextValue(block, locale = "en") {
|
|
1109
|
+
if (!block || !block.value || block.value.length === 0) return "";
|
|
1110
|
+
const firstValue = block.value[0];
|
|
1111
|
+
if (typeof firstValue === "object" && firstValue !== null) {
|
|
1112
|
+
if (firstValue[locale]) return firstValue[locale];
|
|
1113
|
+
if (firstValue.en) return firstValue.en;
|
|
1114
|
+
const values = Object.values(firstValue);
|
|
1115
|
+
return String(values[0] || "");
|
|
1116
|
+
}
|
|
1117
|
+
return String(firstValue);
|
|
1118
|
+
}
|
|
1119
|
+
var getBlockValue = (entry, blockKey) => {
|
|
1120
|
+
if (!entry || !entry.blocks) return null;
|
|
1121
|
+
const block = entry.blocks.find((f) => f.key === blockKey);
|
|
1122
|
+
if (!block || !block.value || block.value.length === 0) return null;
|
|
1123
|
+
return block.value[0];
|
|
1124
|
+
};
|
|
1125
|
+
var getBlockValues = (entry, blockKey) => {
|
|
1126
|
+
if (!entry || !entry.blocks) return null;
|
|
1127
|
+
const block = entry.blocks.find((f) => f.key === blockKey);
|
|
1128
|
+
if (!block || !block.value || block.value.length === 0) return null;
|
|
1129
|
+
return block.value;
|
|
1130
|
+
};
|
|
1131
|
+
function unwrapBlock(block, locale) {
|
|
1132
|
+
if (!block?.type || block.value === void 0) return block;
|
|
1133
|
+
if (block.type === "BLOCK") {
|
|
1134
|
+
return block.value.map((obj) => {
|
|
1135
|
+
const parsed = {};
|
|
1136
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
1137
|
+
parsed[k] = unwrapBlock(v, locale);
|
|
1138
|
+
}
|
|
1139
|
+
return parsed;
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
const isLocalized = block.type === "TEXT";
|
|
1143
|
+
const isList = block.properties?.ui === "list" || (block.properties?.maxValues ?? 1) > 1 || block.value.length > 1;
|
|
1144
|
+
if (isList) {
|
|
1145
|
+
return isLocalized ? block.value.map((v) => v[locale] || v["en"]) : [...block.value];
|
|
1146
|
+
}
|
|
1147
|
+
return isLocalized ? block.value[0][locale] || block.value[0]["en"] : block.value[0];
|
|
1148
|
+
}
|
|
1149
|
+
var getBlockObjectValues = (entry, blockKey, locale = "en") => {
|
|
1150
|
+
if (!entry) {
|
|
1151
|
+
return [];
|
|
1152
|
+
}
|
|
1153
|
+
const values = getBlockValues(entry, blockKey);
|
|
1154
|
+
const parsed = values.map((obj) => {
|
|
1155
|
+
const res = obj.value.reduce((acc, current) => {
|
|
1156
|
+
acc[current.key] = unwrapBlock(current, locale);
|
|
1157
|
+
return acc;
|
|
1158
|
+
}, {});
|
|
1159
|
+
return res;
|
|
1160
|
+
});
|
|
1161
|
+
return parsed;
|
|
1162
|
+
};
|
|
1163
|
+
var getBlockFromArray = (entry, blockKey, locale = "en") => {
|
|
1164
|
+
if (!entry) {
|
|
1165
|
+
return [];
|
|
1166
|
+
}
|
|
1167
|
+
const values = getBlockValues(entry, blockKey);
|
|
1168
|
+
return values.reduce((acc, current) => {
|
|
1169
|
+
acc[current.key] = unwrapBlock(current, locale);
|
|
1170
|
+
return acc;
|
|
1171
|
+
});
|
|
1172
|
+
};
|
|
1044
1173
|
var getImageUrl = (imageBlock, isBlock = true, storageUrl = "https://storage.arky.io/dev") => {
|
|
1045
1174
|
if (!imageBlock) return null;
|
|
1046
1175
|
const isExternalUrl = (url) => {
|
|
@@ -1362,8 +1491,86 @@ function findTimeZone(groups) {
|
|
|
1362
1491
|
}
|
|
1363
1492
|
}
|
|
1364
1493
|
|
|
1494
|
+
// src/utils/text.ts
|
|
1495
|
+
var locales = ["en", "sr-latn"];
|
|
1496
|
+
var localeMap = {
|
|
1497
|
+
"en": "en-US",
|
|
1498
|
+
"sr-latn": "sr-RS"
|
|
1499
|
+
};
|
|
1500
|
+
function slugify(text) {
|
|
1501
|
+
return text.toString().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
1502
|
+
}
|
|
1503
|
+
function humanize(text) {
|
|
1504
|
+
const slugifiedText = slugify(text);
|
|
1505
|
+
return slugifiedText.replace(/-/g, " ").replace(
|
|
1506
|
+
// upper case first letter of every word, and lower case the rest
|
|
1507
|
+
/\w\S*/g,
|
|
1508
|
+
(w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()
|
|
1509
|
+
);
|
|
1510
|
+
}
|
|
1511
|
+
function categorify(text) {
|
|
1512
|
+
const slugifiedText = slugify(text);
|
|
1513
|
+
return slugifiedText.replace(/-/g, " ").toUpperCase();
|
|
1514
|
+
}
|
|
1515
|
+
function formatDate(date, locale) {
|
|
1516
|
+
let localeString = "en-US";
|
|
1517
|
+
if (locales.includes(locale)) {
|
|
1518
|
+
localeString = localeMap[locale];
|
|
1519
|
+
}
|
|
1520
|
+
return new Date(date).toLocaleDateString(localeString, {
|
|
1521
|
+
timeZone: "UTC",
|
|
1522
|
+
year: "numeric",
|
|
1523
|
+
month: "short",
|
|
1524
|
+
day: "numeric"
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
// src/utils/svg.ts
|
|
1529
|
+
async function fetchSvgContent(mediaObject) {
|
|
1530
|
+
if (!mediaObject) return null;
|
|
1531
|
+
const svgUrl = getImageUrl(mediaObject, false);
|
|
1532
|
+
try {
|
|
1533
|
+
const response = await fetch(svgUrl);
|
|
1534
|
+
if (!response.ok) {
|
|
1535
|
+
console.error(`Failed to fetch SVG: ${response.status} ${response.statusText}`);
|
|
1536
|
+
return null;
|
|
1537
|
+
}
|
|
1538
|
+
const svgContent = await response.text();
|
|
1539
|
+
return svgContent;
|
|
1540
|
+
} catch (error) {
|
|
1541
|
+
console.error("Error fetching SVG:", error);
|
|
1542
|
+
return null;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
async function getSvgContentForAstro(mediaObject) {
|
|
1546
|
+
try {
|
|
1547
|
+
const svgContent = await fetchSvgContent(mediaObject);
|
|
1548
|
+
return svgContent || "";
|
|
1549
|
+
} catch (error) {
|
|
1550
|
+
console.error("Error getting SVG content for Astro:", error);
|
|
1551
|
+
return "";
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
async function injectSvgIntoElement(mediaObject, targetElement, className) {
|
|
1555
|
+
if (!targetElement) return;
|
|
1556
|
+
try {
|
|
1557
|
+
const svgContent = await fetchSvgContent(mediaObject);
|
|
1558
|
+
if (svgContent) {
|
|
1559
|
+
targetElement.innerHTML = svgContent;
|
|
1560
|
+
if (className) {
|
|
1561
|
+
const svgElement = targetElement.querySelector("svg");
|
|
1562
|
+
if (svgElement) {
|
|
1563
|
+
svgElement.classList.add(...className.split(" "));
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
} catch (error) {
|
|
1568
|
+
console.error("Error injecting SVG:", error);
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1365
1572
|
// src/index.ts
|
|
1366
|
-
var SDK_VERSION = "0.3.
|
|
1573
|
+
var SDK_VERSION = "0.3.9";
|
|
1367
1574
|
var SUPPORTED_FRAMEWORKS = [
|
|
1368
1575
|
"astro",
|
|
1369
1576
|
"react",
|
|
@@ -1413,18 +1620,41 @@ function createArkySDK(config) {
|
|
|
1413
1620
|
logout: config.logout,
|
|
1414
1621
|
setToken: config.setToken,
|
|
1415
1622
|
utils: {
|
|
1623
|
+
// Block utilities
|
|
1416
1624
|
getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock, storageUrl),
|
|
1417
1625
|
thumbnailUrl: (service) => thumbnailUrl(service, storageUrl),
|
|
1418
1626
|
getGalleryThumbnail,
|
|
1627
|
+
getBlockValue,
|
|
1628
|
+
getBlockValues,
|
|
1629
|
+
getBlockLabel,
|
|
1630
|
+
getBlockTextValue,
|
|
1631
|
+
getBlockObjectValues,
|
|
1632
|
+
getBlockFromArray,
|
|
1633
|
+
formatBlockValue,
|
|
1634
|
+
prepareBlocksForSubmission,
|
|
1635
|
+
extractBlockValues,
|
|
1636
|
+
// Price utilities
|
|
1419
1637
|
getMarketPrice,
|
|
1420
1638
|
getPriceAmount,
|
|
1421
1639
|
formatPayment,
|
|
1422
1640
|
formatMinor,
|
|
1423
1641
|
createPaymentForCheckout,
|
|
1642
|
+
// Currency utilities
|
|
1424
1643
|
getCurrencySymbol,
|
|
1644
|
+
// Validation utilities
|
|
1425
1645
|
validatePhoneNumber,
|
|
1646
|
+
// Timezone utilities
|
|
1426
1647
|
tzGroups,
|
|
1427
|
-
findTimeZone
|
|
1648
|
+
findTimeZone,
|
|
1649
|
+
// Text utilities
|
|
1650
|
+
slugify,
|
|
1651
|
+
humanize,
|
|
1652
|
+
categorify,
|
|
1653
|
+
formatDate,
|
|
1654
|
+
// SVG utilities
|
|
1655
|
+
getSvgContentForAstro,
|
|
1656
|
+
fetchSvgContent,
|
|
1657
|
+
injectSvgIntoElement
|
|
1428
1658
|
}
|
|
1429
1659
|
};
|
|
1430
1660
|
if (autoGuest) {
|