arky-sdk 0.4.27 → 0.4.28
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 +47 -117
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -5
- package/dist/index.d.ts +2 -5
- package/dist/index.js +47 -117
- 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,47 @@ 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
|
-
if (!block || !block.value || block.value.length === 0) return null;
|
|
650
|
-
return block.value[0];
|
|
651
|
-
};
|
|
652
|
-
var getBlockValues = (entry, blockKey) => {
|
|
653
|
-
if (!entry || !entry.blocks) return null;
|
|
654
|
-
const block = entry.blocks.find((f) => f.key === blockKey);
|
|
655
|
-
if (!block || !block.value || block.value.length === 0) return null;
|
|
656
|
-
return block.value;
|
|
612
|
+
const block = entry?.blocks?.find((f) => f.key === blockKey);
|
|
613
|
+
return block?.value ?? null;
|
|
657
614
|
};
|
|
658
615
|
function unwrapBlock(block, locale) {
|
|
659
616
|
if (!block?.type || block.value === void 0) return block;
|
|
@@ -666,72 +623,47 @@ function unwrapBlock(block, locale) {
|
|
|
666
623
|
return parsed;
|
|
667
624
|
});
|
|
668
625
|
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
626
|
+
if (block.type === "TEXT_FILTER" || block.type === "NUMBER_FILTER") {
|
|
627
|
+
return block.value;
|
|
628
|
+
}
|
|
629
|
+
if (block.type === "LOCALIZED_TEXT" || block.type === "MARKDOWN") {
|
|
630
|
+
return block.value?.[locale];
|
|
673
631
|
}
|
|
674
|
-
return
|
|
632
|
+
return block.value;
|
|
675
633
|
}
|
|
676
634
|
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) => {
|
|
635
|
+
const block = entry?.blocks?.find((f) => f.key === blockKey);
|
|
636
|
+
if (!block || block.type !== "BLOCK" || !Array.isArray(block.value)) return [];
|
|
637
|
+
return block.value.map((obj) => {
|
|
638
|
+
if (!obj?.value || !Array.isArray(obj.value)) return {};
|
|
639
|
+
return obj.value.reduce((acc, current) => {
|
|
689
640
|
acc[current.key] = unwrapBlock(current, locale);
|
|
690
641
|
return acc;
|
|
691
642
|
}, {});
|
|
692
|
-
return res;
|
|
693
643
|
});
|
|
694
|
-
return parsed;
|
|
695
644
|
};
|
|
696
645
|
var getBlockFromArray = (entry, blockKey, locale = "en") => {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
646
|
+
const block = entry?.blocks?.find((f) => f.key === blockKey);
|
|
647
|
+
if (!block) return {};
|
|
648
|
+
if (block.type === "BLOCK" && Array.isArray(block.value)) {
|
|
649
|
+
return block.value.reduce((acc, current) => {
|
|
650
|
+
acc[current.key] = unwrapBlock(current, locale);
|
|
651
|
+
return acc;
|
|
652
|
+
}, {});
|
|
703
653
|
}
|
|
704
|
-
return
|
|
705
|
-
acc[current.key] = unwrapBlock(current, locale);
|
|
706
|
-
return acc;
|
|
707
|
-
}, {});
|
|
654
|
+
return { [block.key]: unwrapBlock(block, locale) };
|
|
708
655
|
};
|
|
709
656
|
var getImageUrl = (imageBlock, isBlock = true) => {
|
|
710
657
|
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;
|
|
658
|
+
if (imageBlock.type === "RELATIONSHIP_MEDIA") {
|
|
659
|
+
const mediaValue = imageBlock.value;
|
|
660
|
+
return mediaValue?.resolutions?.original?.url || mediaValue?.url || null;
|
|
722
661
|
}
|
|
723
662
|
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;
|
|
663
|
+
if (typeof imageBlock === "string") return imageBlock;
|
|
664
|
+
if (imageBlock.url) return imageBlock.url;
|
|
733
665
|
}
|
|
734
|
-
return null;
|
|
666
|
+
return imageBlock.resolutions?.original?.url || null;
|
|
735
667
|
};
|
|
736
668
|
|
|
737
669
|
// src/api/cms.ts
|
|
@@ -1745,9 +1677,7 @@ async function createArkySDK(config) {
|
|
|
1745
1677
|
utils: {
|
|
1746
1678
|
getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock),
|
|
1747
1679
|
getBlockValue,
|
|
1748
|
-
getBlockValues,
|
|
1749
1680
|
getBlockLabel,
|
|
1750
|
-
getBlockTextValue,
|
|
1751
1681
|
getBlockObjectValues,
|
|
1752
1682
|
getBlockFromArray,
|
|
1753
1683
|
formatBlockValue,
|