arky-sdk 0.4.27 → 0.4.29
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/README.md +1 -3
- package/dist/index.cjs +64 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +64 -114
- package/dist/index.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +3 -9
- package/dist/types.d.ts +3 -9
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -291,10 +291,8 @@ The SDK includes helpful utilities accessible via `arky.utils`:
|
|
|
291
291
|
// Get image URL from block
|
|
292
292
|
const url = arky.utils.getImageUrl(imageBlock)
|
|
293
293
|
|
|
294
|
-
// Get block
|
|
294
|
+
// Get block value
|
|
295
295
|
const value = arky.utils.getBlockValue(entry, 'title')
|
|
296
|
-
const values = arky.utils.getBlockValues(entry, 'gallery')
|
|
297
|
-
const text = arky.utils.getBlockTextValue(block, 'en')
|
|
298
296
|
|
|
299
297
|
// Format blocks
|
|
300
298
|
const formatted = arky.utils.formatBlockValue(block)
|
package/dist/index.cjs
CHANGED
|
@@ -570,90 +570,65 @@ var createPromoCodeApi = (apiConfig) => {
|
|
|
570
570
|
// src/utils/blocks.ts
|
|
571
571
|
function getBlockLabel(block, locale = "en") {
|
|
572
572
|
if (!block) return "";
|
|
573
|
-
if (block.properties?.label)
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
}
|
|
577
|
-
if (typeof block.properties.label === "string") {
|
|
578
|
-
return block.properties.label;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
return block.key?.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()) || "";
|
|
573
|
+
if (typeof block.properties?.label === "string") return block.properties.label;
|
|
574
|
+
if (typeof block.properties?.label === "object") return block.properties.label[locale];
|
|
575
|
+
return block.key?.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase());
|
|
582
576
|
}
|
|
583
577
|
function formatBlockValue(block) {
|
|
584
|
-
if (!block || block.value === null || block.value === void 0)
|
|
585
|
-
|
|
586
|
-
}
|
|
578
|
+
if (!block || block.value === null || block.value === void 0) return "";
|
|
579
|
+
const value = block.value;
|
|
587
580
|
switch (block.type) {
|
|
588
581
|
case "BOOLEAN":
|
|
589
|
-
return
|
|
582
|
+
return value ? "Yes" : "No";
|
|
590
583
|
case "NUMBER":
|
|
591
584
|
if (block.properties?.variant === "DATE" || block.properties?.variant === "DATE_TIME") {
|
|
592
|
-
|
|
593
|
-
return new Date(block.value).toLocaleDateString();
|
|
594
|
-
} catch (e) {
|
|
595
|
-
return String(block.value);
|
|
596
|
-
}
|
|
585
|
+
return new Date(value).toLocaleDateString();
|
|
597
586
|
}
|
|
598
|
-
return String(
|
|
599
|
-
case "
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
return firstValue.name || firstValue.id || "Media";
|
|
604
|
-
}
|
|
605
|
-
return firstValue.title || firstValue.name || firstValue.id || "Entry";
|
|
587
|
+
return String(value);
|
|
588
|
+
case "RELATIONSHIP_ENTRY":
|
|
589
|
+
case "RELATIONSHIP_MEDIA":
|
|
590
|
+
if (value && typeof value === "object") {
|
|
591
|
+
return value.mimeType ? value.name || value.id : value.title || value.name || value.id;
|
|
606
592
|
}
|
|
607
|
-
return String(
|
|
593
|
+
return String(value);
|
|
608
594
|
default:
|
|
609
|
-
return String(
|
|
595
|
+
return String(value);
|
|
610
596
|
}
|
|
611
597
|
}
|
|
612
|
-
function prepareBlocksForSubmission(formData) {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
key,
|
|
618
|
-
value: [formData[key]]
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
});
|
|
622
|
-
return preparedBlocks;
|
|
598
|
+
function prepareBlocksForSubmission(formData, blockTypes) {
|
|
599
|
+
return Object.keys(formData).filter((key) => formData[key] !== null && formData[key] !== void 0).map((key) => ({
|
|
600
|
+
key,
|
|
601
|
+
value: blockTypes?.[key] === "BLOCK" && !Array.isArray(formData[key]) ? [formData[key]] : formData[key]
|
|
602
|
+
}));
|
|
623
603
|
}
|
|
624
604
|
function extractBlockValues(blocks) {
|
|
625
605
|
const values = {};
|
|
626
606
|
blocks.forEach((block) => {
|
|
627
|
-
|
|
628
|
-
values[block.key] = block.value[0];
|
|
629
|
-
} else {
|
|
630
|
-
values[block.key] = null;
|
|
631
|
-
}
|
|
607
|
+
values[block.key] = block.value ?? null;
|
|
632
608
|
});
|
|
633
609
|
return values;
|
|
634
610
|
}
|
|
635
|
-
function getBlockTextValue(block, locale = "en") {
|
|
636
|
-
if (!block || !block.value || block.value.length === 0) return "";
|
|
637
|
-
const firstValue = block.value[0];
|
|
638
|
-
if (typeof firstValue === "object" && firstValue !== null) {
|
|
639
|
-
if (firstValue[locale]) return firstValue[locale];
|
|
640
|
-
if (firstValue.en) return firstValue.en;
|
|
641
|
-
const values = Object.values(firstValue);
|
|
642
|
-
return String(values[0] || "");
|
|
643
|
-
}
|
|
644
|
-
return String(firstValue);
|
|
645
|
-
}
|
|
646
611
|
var getBlockValue = (entry, blockKey) => {
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
612
|
+
const block = entry?.blocks?.find((f) => f.key === blockKey);
|
|
613
|
+
return block?.value ?? null;
|
|
614
|
+
};
|
|
615
|
+
var getBlockTextValue = (block, locale = "en") => {
|
|
616
|
+
if (!block || block.value === null || block.value === void 0) return "";
|
|
617
|
+
if (block.type === "LOCALIZED_TEXT" || block.type === "MARKDOWN") {
|
|
618
|
+
if (typeof block.value === "object" && block.value !== null) {
|
|
619
|
+
return block.value[locale] ?? block.value["en"] ?? "";
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
if (typeof block.value === "string") return block.value;
|
|
623
|
+
return String(block.value ?? "");
|
|
651
624
|
};
|
|
652
625
|
var getBlockValues = (entry, blockKey) => {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
if (
|
|
656
|
-
|
|
626
|
+
const block = entry?.blocks?.find((f) => f.key === blockKey);
|
|
627
|
+
if (!block) return [];
|
|
628
|
+
if (block.type === "BLOCK" && Array.isArray(block.value)) {
|
|
629
|
+
return block.value;
|
|
630
|
+
}
|
|
631
|
+
return [];
|
|
657
632
|
};
|
|
658
633
|
function unwrapBlock(block, locale) {
|
|
659
634
|
if (!block?.type || block.value === void 0) return block;
|
|
@@ -666,72 +641,47 @@ function unwrapBlock(block, locale) {
|
|
|
666
641
|
return parsed;
|
|
667
642
|
});
|
|
668
643
|
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
if (isList) {
|
|
672
|
-
return isLocalized ? block.value.map((v) => v[locale] || v["en"]) : [...block.value];
|
|
644
|
+
if (block.type === "TEXT_FILTER" || block.type === "NUMBER_FILTER") {
|
|
645
|
+
return block.value;
|
|
673
646
|
}
|
|
674
|
-
|
|
647
|
+
if (block.type === "LOCALIZED_TEXT" || block.type === "MARKDOWN") {
|
|
648
|
+
return block.value?.[locale];
|
|
649
|
+
}
|
|
650
|
+
return block.value;
|
|
675
651
|
}
|
|
676
652
|
var getBlockObjectValues = (entry, blockKey, locale = "en") => {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
return [];
|
|
683
|
-
}
|
|
684
|
-
const parsed = values.map((obj) => {
|
|
685
|
-
if (!obj || !obj.value || !Array.isArray(obj.value)) {
|
|
686
|
-
return {};
|
|
687
|
-
}
|
|
688
|
-
const res = obj.value.reduce((acc, current) => {
|
|
653
|
+
const block = entry?.blocks?.find((f) => f.key === blockKey);
|
|
654
|
+
if (!block || block.type !== "BLOCK" || !Array.isArray(block.value)) return [];
|
|
655
|
+
return block.value.map((obj) => {
|
|
656
|
+
if (!obj?.value || !Array.isArray(obj.value)) return {};
|
|
657
|
+
return obj.value.reduce((acc, current) => {
|
|
689
658
|
acc[current.key] = unwrapBlock(current, locale);
|
|
690
659
|
return acc;
|
|
691
660
|
}, {});
|
|
692
|
-
return res;
|
|
693
661
|
});
|
|
694
|
-
return parsed;
|
|
695
662
|
};
|
|
696
663
|
var getBlockFromArray = (entry, blockKey, locale = "en") => {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
664
|
+
const block = entry?.blocks?.find((f) => f.key === blockKey);
|
|
665
|
+
if (!block) return {};
|
|
666
|
+
if (block.type === "BLOCK" && Array.isArray(block.value)) {
|
|
667
|
+
return block.value.reduce((acc, current) => {
|
|
668
|
+
acc[current.key] = unwrapBlock(current, locale);
|
|
669
|
+
return acc;
|
|
670
|
+
}, {});
|
|
703
671
|
}
|
|
704
|
-
return
|
|
705
|
-
acc[current.key] = unwrapBlock(current, locale);
|
|
706
|
-
return acc;
|
|
707
|
-
}, {});
|
|
672
|
+
return { [block.key]: unwrapBlock(block, locale) };
|
|
708
673
|
};
|
|
709
674
|
var getImageUrl = (imageBlock, isBlock = true) => {
|
|
710
675
|
if (!imageBlock) return null;
|
|
711
|
-
if (imageBlock.type === "RELATIONSHIP_MEDIA"
|
|
712
|
-
const mediaValue = imageBlock.value
|
|
713
|
-
|
|
714
|
-
if (mediaValue.resolutions && mediaValue.resolutions.original && mediaValue.resolutions.original.url) {
|
|
715
|
-
return mediaValue.resolutions.original.url;
|
|
716
|
-
}
|
|
717
|
-
if (mediaValue.url) {
|
|
718
|
-
return mediaValue.url;
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
return null;
|
|
676
|
+
if (imageBlock.type === "RELATIONSHIP_MEDIA") {
|
|
677
|
+
const mediaValue = imageBlock.value;
|
|
678
|
+
return mediaValue?.resolutions?.original?.url || mediaValue?.url || null;
|
|
722
679
|
}
|
|
723
680
|
if (isBlock) {
|
|
724
|
-
if (typeof imageBlock === "string")
|
|
725
|
-
|
|
726
|
-
}
|
|
727
|
-
if (imageBlock.url) {
|
|
728
|
-
return imageBlock.url;
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
if (imageBlock.resolutions && imageBlock.resolutions.original && imageBlock.resolutions.original.url) {
|
|
732
|
-
return imageBlock.resolutions.original.url;
|
|
681
|
+
if (typeof imageBlock === "string") return imageBlock;
|
|
682
|
+
if (imageBlock.url) return imageBlock.url;
|
|
733
683
|
}
|
|
734
|
-
return null;
|
|
684
|
+
return imageBlock.resolutions?.original?.url || null;
|
|
735
685
|
};
|
|
736
686
|
|
|
737
687
|
// src/api/cms.ts
|
|
@@ -1745,9 +1695,9 @@ async function createArkySDK(config) {
|
|
|
1745
1695
|
utils: {
|
|
1746
1696
|
getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock),
|
|
1747
1697
|
getBlockValue,
|
|
1698
|
+
getBlockTextValue,
|
|
1748
1699
|
getBlockValues,
|
|
1749
1700
|
getBlockLabel,
|
|
1750
|
-
getBlockTextValue,
|
|
1751
1701
|
getBlockObjectValues,
|
|
1752
1702
|
getBlockFromArray,
|
|
1753
1703
|
formatBlockValue,
|