@brytdesigns/shopify-ajax-cart-api 1.0.23 → 1.0.25
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/effect/index.d.ts +67 -177
- package/dist/effect/schema.js +9 -65
- package/dist/effect/schema.js.map +1 -1
- package/dist/esm/index.js +49 -615
- package/dist/esm/index.js.map +1 -1
- package/dist/main/effect/schema.js +9 -65
- package/dist/main/effect/schema.js.map +1 -1
- package/dist/main/index.d.ts +145 -387
- package/package.json +1 -1
- package/dist/effect/cache.js +0 -39
- package/dist/effect/cache.js.map +0 -1
- package/dist/main/effect/cache.js +0 -39
- package/dist/main/effect/cache.js.map +0 -1
package/dist/effect/index.d.ts
CHANGED
|
@@ -157,12 +157,6 @@ export declare const add: (input?: ({
|
|
|
157
157
|
readonly url: string;
|
|
158
158
|
readonly price: number;
|
|
159
159
|
readonly id: string | number;
|
|
160
|
-
readonly quantity_rule?: {
|
|
161
|
-
readonly min: number;
|
|
162
|
-
readonly max: number | null;
|
|
163
|
-
readonly increment: number;
|
|
164
|
-
} | undefined;
|
|
165
|
-
readonly handle: string;
|
|
166
160
|
readonly properties: {
|
|
167
161
|
readonly [x: string]: string | number | boolean | null;
|
|
168
162
|
};
|
|
@@ -186,14 +180,15 @@ export declare const add: (input?: ({
|
|
|
186
180
|
readonly gift_card: boolean;
|
|
187
181
|
readonly final_line_price: number;
|
|
188
182
|
readonly final_price: number;
|
|
189
|
-
readonly featured_image
|
|
190
|
-
readonly aspect_ratio: number;
|
|
191
|
-
readonly alt: string;
|
|
192
|
-
readonly height: number;
|
|
193
|
-
readonly url: string;
|
|
194
|
-
readonly width: number;
|
|
195
|
-
}
|
|
183
|
+
readonly featured_image: {
|
|
184
|
+
readonly aspect_ratio: number | null;
|
|
185
|
+
readonly alt: string | null;
|
|
186
|
+
readonly height: number | null;
|
|
187
|
+
readonly url: string | null;
|
|
188
|
+
readonly width: number | null;
|
|
189
|
+
};
|
|
196
190
|
readonly image: string;
|
|
191
|
+
readonly handle: string;
|
|
197
192
|
readonly requires_shipping: boolean;
|
|
198
193
|
readonly product_type: string | null;
|
|
199
194
|
readonly product_title: string;
|
|
@@ -218,6 +213,11 @@ export declare const add: (input?: ({
|
|
|
218
213
|
};
|
|
219
214
|
}[];
|
|
220
215
|
readonly line_level_total_discount: number;
|
|
216
|
+
readonly quantity_rule?: {
|
|
217
|
+
readonly min: number;
|
|
218
|
+
readonly max: number | null;
|
|
219
|
+
readonly increment: number;
|
|
220
|
+
} | undefined;
|
|
221
221
|
readonly has_components: boolean;
|
|
222
222
|
readonly unit_price?: number | undefined;
|
|
223
223
|
readonly unit_price_measurement?: {
|
|
@@ -255,28 +255,6 @@ export declare const add: (input?: ({
|
|
|
255
255
|
};
|
|
256
256
|
} | null;
|
|
257
257
|
} & {
|
|
258
|
-
readonly product: {
|
|
259
|
-
readonly title: string;
|
|
260
|
-
readonly id: string | number;
|
|
261
|
-
readonly options: readonly {
|
|
262
|
-
readonly values: readonly string[];
|
|
263
|
-
readonly name: string;
|
|
264
|
-
readonly position: number;
|
|
265
|
-
}[];
|
|
266
|
-
readonly handle: string;
|
|
267
|
-
readonly variants: readonly {
|
|
268
|
-
readonly title: string;
|
|
269
|
-
readonly id: string | number;
|
|
270
|
-
readonly options: readonly string[];
|
|
271
|
-
readonly quantity_rule: {
|
|
272
|
-
readonly min: number | null;
|
|
273
|
-
readonly max: number | null;
|
|
274
|
-
readonly increment: number;
|
|
275
|
-
};
|
|
276
|
-
}[];
|
|
277
|
-
readonly tags: readonly string[];
|
|
278
|
-
readonly available: boolean;
|
|
279
|
-
};
|
|
280
258
|
readonly properties_array: readonly {
|
|
281
259
|
readonly key: string;
|
|
282
260
|
readonly value: string | number | boolean | null;
|
|
@@ -348,12 +326,6 @@ export declare const change: (input?: ({
|
|
|
348
326
|
readonly url: string;
|
|
349
327
|
readonly price: number;
|
|
350
328
|
readonly id: string | number;
|
|
351
|
-
readonly quantity_rule?: {
|
|
352
|
-
readonly min: number;
|
|
353
|
-
readonly max: number | null;
|
|
354
|
-
readonly increment: number;
|
|
355
|
-
} | undefined;
|
|
356
|
-
readonly handle: string;
|
|
357
329
|
readonly properties: {
|
|
358
330
|
readonly [x: string]: string | number | boolean | null;
|
|
359
331
|
};
|
|
@@ -377,14 +349,15 @@ export declare const change: (input?: ({
|
|
|
377
349
|
readonly gift_card: boolean;
|
|
378
350
|
readonly final_line_price: number;
|
|
379
351
|
readonly final_price: number;
|
|
380
|
-
readonly featured_image
|
|
381
|
-
readonly aspect_ratio: number;
|
|
382
|
-
readonly alt: string;
|
|
383
|
-
readonly height: number;
|
|
384
|
-
readonly url: string;
|
|
385
|
-
readonly width: number;
|
|
386
|
-
}
|
|
352
|
+
readonly featured_image: {
|
|
353
|
+
readonly aspect_ratio: number | null;
|
|
354
|
+
readonly alt: string | null;
|
|
355
|
+
readonly height: number | null;
|
|
356
|
+
readonly url: string | null;
|
|
357
|
+
readonly width: number | null;
|
|
358
|
+
};
|
|
387
359
|
readonly image: string;
|
|
360
|
+
readonly handle: string;
|
|
388
361
|
readonly requires_shipping: boolean;
|
|
389
362
|
readonly product_type: string | null;
|
|
390
363
|
readonly product_title: string;
|
|
@@ -409,6 +382,11 @@ export declare const change: (input?: ({
|
|
|
409
382
|
};
|
|
410
383
|
}[];
|
|
411
384
|
readonly line_level_total_discount: number;
|
|
385
|
+
readonly quantity_rule?: {
|
|
386
|
+
readonly min: number;
|
|
387
|
+
readonly max: number | null;
|
|
388
|
+
readonly increment: number;
|
|
389
|
+
} | undefined;
|
|
412
390
|
readonly has_components: boolean;
|
|
413
391
|
readonly unit_price?: number | undefined;
|
|
414
392
|
readonly unit_price_measurement?: {
|
|
@@ -446,28 +424,6 @@ export declare const change: (input?: ({
|
|
|
446
424
|
};
|
|
447
425
|
} | null;
|
|
448
426
|
} & {
|
|
449
|
-
readonly product: {
|
|
450
|
-
readonly title: string;
|
|
451
|
-
readonly id: string | number;
|
|
452
|
-
readonly options: readonly {
|
|
453
|
-
readonly values: readonly string[];
|
|
454
|
-
readonly name: string;
|
|
455
|
-
readonly position: number;
|
|
456
|
-
}[];
|
|
457
|
-
readonly handle: string;
|
|
458
|
-
readonly variants: readonly {
|
|
459
|
-
readonly title: string;
|
|
460
|
-
readonly id: string | number;
|
|
461
|
-
readonly options: readonly string[];
|
|
462
|
-
readonly quantity_rule: {
|
|
463
|
-
readonly min: number | null;
|
|
464
|
-
readonly max: number | null;
|
|
465
|
-
readonly increment: number;
|
|
466
|
-
};
|
|
467
|
-
}[];
|
|
468
|
-
readonly tags: readonly string[];
|
|
469
|
-
readonly available: boolean;
|
|
470
|
-
};
|
|
471
427
|
readonly properties_array: readonly {
|
|
472
428
|
readonly key: string;
|
|
473
429
|
readonly value: string | number | boolean | null;
|
|
@@ -551,12 +507,6 @@ export declare const clear: (input?: {
|
|
|
551
507
|
readonly url: string;
|
|
552
508
|
readonly price: number;
|
|
553
509
|
readonly id: string | number;
|
|
554
|
-
readonly quantity_rule?: {
|
|
555
|
-
readonly min: number;
|
|
556
|
-
readonly max: number | null;
|
|
557
|
-
readonly increment: number;
|
|
558
|
-
} | undefined;
|
|
559
|
-
readonly handle: string;
|
|
560
510
|
readonly properties: {
|
|
561
511
|
readonly [x: string]: string | number | boolean | null;
|
|
562
512
|
};
|
|
@@ -580,14 +530,15 @@ export declare const clear: (input?: {
|
|
|
580
530
|
readonly gift_card: boolean;
|
|
581
531
|
readonly final_line_price: number;
|
|
582
532
|
readonly final_price: number;
|
|
583
|
-
readonly featured_image
|
|
584
|
-
readonly aspect_ratio: number;
|
|
585
|
-
readonly alt: string;
|
|
586
|
-
readonly height: number;
|
|
587
|
-
readonly url: string;
|
|
588
|
-
readonly width: number;
|
|
589
|
-
}
|
|
533
|
+
readonly featured_image: {
|
|
534
|
+
readonly aspect_ratio: number | null;
|
|
535
|
+
readonly alt: string | null;
|
|
536
|
+
readonly height: number | null;
|
|
537
|
+
readonly url: string | null;
|
|
538
|
+
readonly width: number | null;
|
|
539
|
+
};
|
|
590
540
|
readonly image: string;
|
|
541
|
+
readonly handle: string;
|
|
591
542
|
readonly requires_shipping: boolean;
|
|
592
543
|
readonly product_type: string | null;
|
|
593
544
|
readonly product_title: string;
|
|
@@ -612,6 +563,11 @@ export declare const clear: (input?: {
|
|
|
612
563
|
};
|
|
613
564
|
}[];
|
|
614
565
|
readonly line_level_total_discount: number;
|
|
566
|
+
readonly quantity_rule?: {
|
|
567
|
+
readonly min: number;
|
|
568
|
+
readonly max: number | null;
|
|
569
|
+
readonly increment: number;
|
|
570
|
+
} | undefined;
|
|
615
571
|
readonly has_components: boolean;
|
|
616
572
|
readonly unit_price?: number | undefined;
|
|
617
573
|
readonly unit_price_measurement?: {
|
|
@@ -649,28 +605,6 @@ export declare const clear: (input?: {
|
|
|
649
605
|
};
|
|
650
606
|
} | null;
|
|
651
607
|
} & {
|
|
652
|
-
readonly product: {
|
|
653
|
-
readonly title: string;
|
|
654
|
-
readonly id: string | number;
|
|
655
|
-
readonly options: readonly {
|
|
656
|
-
readonly values: readonly string[];
|
|
657
|
-
readonly name: string;
|
|
658
|
-
readonly position: number;
|
|
659
|
-
}[];
|
|
660
|
-
readonly handle: string;
|
|
661
|
-
readonly variants: readonly {
|
|
662
|
-
readonly title: string;
|
|
663
|
-
readonly id: string | number;
|
|
664
|
-
readonly options: readonly string[];
|
|
665
|
-
readonly quantity_rule: {
|
|
666
|
-
readonly min: number | null;
|
|
667
|
-
readonly max: number | null;
|
|
668
|
-
readonly increment: number;
|
|
669
|
-
};
|
|
670
|
-
}[];
|
|
671
|
-
readonly tags: readonly string[];
|
|
672
|
-
readonly available: boolean;
|
|
673
|
-
};
|
|
674
608
|
readonly properties_array: readonly {
|
|
675
609
|
readonly key: string;
|
|
676
610
|
readonly value: string | number | boolean | null;
|
|
@@ -754,12 +688,6 @@ export declare const get: (input?: {
|
|
|
754
688
|
readonly url: string;
|
|
755
689
|
readonly price: number;
|
|
756
690
|
readonly id: string | number;
|
|
757
|
-
readonly quantity_rule?: {
|
|
758
|
-
readonly min: number;
|
|
759
|
-
readonly max: number | null;
|
|
760
|
-
readonly increment: number;
|
|
761
|
-
} | undefined;
|
|
762
|
-
readonly handle: string;
|
|
763
691
|
readonly properties: {
|
|
764
692
|
readonly [x: string]: string | number | boolean | null;
|
|
765
693
|
};
|
|
@@ -783,14 +711,15 @@ export declare const get: (input?: {
|
|
|
783
711
|
readonly gift_card: boolean;
|
|
784
712
|
readonly final_line_price: number;
|
|
785
713
|
readonly final_price: number;
|
|
786
|
-
readonly featured_image
|
|
787
|
-
readonly aspect_ratio: number;
|
|
788
|
-
readonly alt: string;
|
|
789
|
-
readonly height: number;
|
|
790
|
-
readonly url: string;
|
|
791
|
-
readonly width: number;
|
|
792
|
-
}
|
|
714
|
+
readonly featured_image: {
|
|
715
|
+
readonly aspect_ratio: number | null;
|
|
716
|
+
readonly alt: string | null;
|
|
717
|
+
readonly height: number | null;
|
|
718
|
+
readonly url: string | null;
|
|
719
|
+
readonly width: number | null;
|
|
720
|
+
};
|
|
793
721
|
readonly image: string;
|
|
722
|
+
readonly handle: string;
|
|
794
723
|
readonly requires_shipping: boolean;
|
|
795
724
|
readonly product_type: string | null;
|
|
796
725
|
readonly product_title: string;
|
|
@@ -815,6 +744,11 @@ export declare const get: (input?: {
|
|
|
815
744
|
};
|
|
816
745
|
}[];
|
|
817
746
|
readonly line_level_total_discount: number;
|
|
747
|
+
readonly quantity_rule?: {
|
|
748
|
+
readonly min: number;
|
|
749
|
+
readonly max: number | null;
|
|
750
|
+
readonly increment: number;
|
|
751
|
+
} | undefined;
|
|
818
752
|
readonly has_components: boolean;
|
|
819
753
|
readonly unit_price?: number | undefined;
|
|
820
754
|
readonly unit_price_measurement?: {
|
|
@@ -852,28 +786,6 @@ export declare const get: (input?: {
|
|
|
852
786
|
};
|
|
853
787
|
} | null;
|
|
854
788
|
} & {
|
|
855
|
-
readonly product: {
|
|
856
|
-
readonly title: string;
|
|
857
|
-
readonly id: string | number;
|
|
858
|
-
readonly options: readonly {
|
|
859
|
-
readonly values: readonly string[];
|
|
860
|
-
readonly name: string;
|
|
861
|
-
readonly position: number;
|
|
862
|
-
}[];
|
|
863
|
-
readonly handle: string;
|
|
864
|
-
readonly variants: readonly {
|
|
865
|
-
readonly title: string;
|
|
866
|
-
readonly id: string | number;
|
|
867
|
-
readonly options: readonly string[];
|
|
868
|
-
readonly quantity_rule: {
|
|
869
|
-
readonly min: number | null;
|
|
870
|
-
readonly max: number | null;
|
|
871
|
-
readonly increment: number;
|
|
872
|
-
};
|
|
873
|
-
}[];
|
|
874
|
-
readonly tags: readonly string[];
|
|
875
|
-
readonly available: boolean;
|
|
876
|
-
};
|
|
877
789
|
readonly properties_array: readonly {
|
|
878
790
|
readonly key: string;
|
|
879
791
|
readonly value: string | number | boolean | null;
|
|
@@ -933,9 +845,9 @@ export declare const update: (input?: ({
|
|
|
933
845
|
readonly attributes?: {
|
|
934
846
|
readonly [x: string]: string | number | boolean | null;
|
|
935
847
|
} | undefined;
|
|
936
|
-
readonly updates?:
|
|
848
|
+
readonly updates?: {
|
|
937
849
|
readonly [x: string]: number;
|
|
938
|
-
} | undefined;
|
|
850
|
+
} | readonly number[] | undefined;
|
|
939
851
|
readonly discount?: readonly string[] | undefined;
|
|
940
852
|
} & {
|
|
941
853
|
readonly sections?: string | undefined;
|
|
@@ -966,12 +878,6 @@ export declare const update: (input?: ({
|
|
|
966
878
|
readonly url: string;
|
|
967
879
|
readonly price: number;
|
|
968
880
|
readonly id: string | number;
|
|
969
|
-
readonly quantity_rule?: {
|
|
970
|
-
readonly min: number;
|
|
971
|
-
readonly max: number | null;
|
|
972
|
-
readonly increment: number;
|
|
973
|
-
} | undefined;
|
|
974
|
-
readonly handle: string;
|
|
975
881
|
readonly properties: {
|
|
976
882
|
readonly [x: string]: string | number | boolean | null;
|
|
977
883
|
};
|
|
@@ -995,14 +901,15 @@ export declare const update: (input?: ({
|
|
|
995
901
|
readonly gift_card: boolean;
|
|
996
902
|
readonly final_line_price: number;
|
|
997
903
|
readonly final_price: number;
|
|
998
|
-
readonly featured_image
|
|
999
|
-
readonly aspect_ratio: number;
|
|
1000
|
-
readonly alt: string;
|
|
1001
|
-
readonly height: number;
|
|
1002
|
-
readonly url: string;
|
|
1003
|
-
readonly width: number;
|
|
1004
|
-
}
|
|
904
|
+
readonly featured_image: {
|
|
905
|
+
readonly aspect_ratio: number | null;
|
|
906
|
+
readonly alt: string | null;
|
|
907
|
+
readonly height: number | null;
|
|
908
|
+
readonly url: string | null;
|
|
909
|
+
readonly width: number | null;
|
|
910
|
+
};
|
|
1005
911
|
readonly image: string;
|
|
912
|
+
readonly handle: string;
|
|
1006
913
|
readonly requires_shipping: boolean;
|
|
1007
914
|
readonly product_type: string | null;
|
|
1008
915
|
readonly product_title: string;
|
|
@@ -1027,6 +934,11 @@ export declare const update: (input?: ({
|
|
|
1027
934
|
};
|
|
1028
935
|
}[];
|
|
1029
936
|
readonly line_level_total_discount: number;
|
|
937
|
+
readonly quantity_rule?: {
|
|
938
|
+
readonly min: number;
|
|
939
|
+
readonly max: number | null;
|
|
940
|
+
readonly increment: number;
|
|
941
|
+
} | undefined;
|
|
1030
942
|
readonly has_components: boolean;
|
|
1031
943
|
readonly unit_price?: number | undefined;
|
|
1032
944
|
readonly unit_price_measurement?: {
|
|
@@ -1064,28 +976,6 @@ export declare const update: (input?: ({
|
|
|
1064
976
|
};
|
|
1065
977
|
} | null;
|
|
1066
978
|
} & {
|
|
1067
|
-
readonly product: {
|
|
1068
|
-
readonly title: string;
|
|
1069
|
-
readonly id: string | number;
|
|
1070
|
-
readonly options: readonly {
|
|
1071
|
-
readonly values: readonly string[];
|
|
1072
|
-
readonly name: string;
|
|
1073
|
-
readonly position: number;
|
|
1074
|
-
}[];
|
|
1075
|
-
readonly handle: string;
|
|
1076
|
-
readonly variants: readonly {
|
|
1077
|
-
readonly title: string;
|
|
1078
|
-
readonly id: string | number;
|
|
1079
|
-
readonly options: readonly string[];
|
|
1080
|
-
readonly quantity_rule: {
|
|
1081
|
-
readonly min: number | null;
|
|
1082
|
-
readonly max: number | null;
|
|
1083
|
-
readonly increment: number;
|
|
1084
|
-
};
|
|
1085
|
-
}[];
|
|
1086
|
-
readonly tags: readonly string[];
|
|
1087
|
-
readonly available: boolean;
|
|
1088
|
-
};
|
|
1089
979
|
readonly properties_array: readonly {
|
|
1090
980
|
readonly key: string;
|
|
1091
981
|
readonly value: string | number | boolean | null;
|
package/dist/effect/schema.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import * as Schema from 'effect/Schema';
|
|
2
2
|
import * as Array from 'effect/Array';
|
|
3
3
|
import * as Record from 'effect/Record';
|
|
4
|
-
import * as Effect from 'effect/Effect';
|
|
5
|
-
import * as ParseResult from 'effect/ParseResult';
|
|
6
4
|
import { Resource, Ajax } from '@brytdesigns/shopify-utils/effect';
|
|
7
5
|
import { pipe, identity } from 'effect';
|
|
8
|
-
import * as Cache from './cache';
|
|
9
6
|
|
|
10
7
|
const BaseAttributeValue = Schema.Union(
|
|
11
8
|
Schema.Null,
|
|
@@ -34,11 +31,11 @@ const BaseAttributesArray = Schema.transform(
|
|
|
34
31
|
}
|
|
35
32
|
);
|
|
36
33
|
const BasePrivateAttributes = Schema.transform(BaseAttributes, BaseAttributes, {
|
|
37
|
-
decode: Record.filter((
|
|
34
|
+
decode: Record.filter((_, key) => key.startsWith("_")),
|
|
38
35
|
encode: identity
|
|
39
36
|
});
|
|
40
37
|
const BasePublicAttributes = Schema.transform(BaseAttributes, BaseAttributes, {
|
|
41
|
-
decode: Record.filter((
|
|
38
|
+
decode: Record.filter((_, key) => !key.startsWith("_")),
|
|
42
39
|
encode: identity
|
|
43
40
|
});
|
|
44
41
|
const BasePrivateAttributesArray = Schema.transform(
|
|
@@ -112,11 +109,11 @@ const Discount = Schema.Struct({
|
|
|
112
109
|
});
|
|
113
110
|
const CurrencyCode = Schema.String;
|
|
114
111
|
const Image = Schema.Struct({
|
|
115
|
-
aspect_ratio: Schema.Number,
|
|
116
|
-
alt: Schema.String,
|
|
117
|
-
height: Schema.Number,
|
|
118
|
-
url: Schema.String,
|
|
119
|
-
width: Schema.Number
|
|
112
|
+
aspect_ratio: Schema.NullOr(Schema.Number),
|
|
113
|
+
alt: Schema.NullOr(Schema.String),
|
|
114
|
+
height: Schema.NullOr(Schema.Number),
|
|
115
|
+
url: Schema.NullOr(Schema.String),
|
|
116
|
+
width: Schema.NullOr(Schema.Number)
|
|
120
117
|
});
|
|
121
118
|
const OptionWithValue = Schema.Struct({
|
|
122
119
|
name: Schema.String,
|
|
@@ -190,60 +187,9 @@ const UnitPriceMeasurement = Schema.Struct({
|
|
|
190
187
|
reference_unit: Schema.String,
|
|
191
188
|
reference_value: Schema.Number
|
|
192
189
|
});
|
|
193
|
-
const VariantQuantityRule = Schema.Struct({
|
|
194
|
-
min: Schema.NullOr(Schema.Number),
|
|
195
|
-
max: Schema.NullOr(Schema.Number),
|
|
196
|
-
increment: Schema.Number
|
|
197
|
-
});
|
|
198
190
|
const VariantOptions = Schema.optionalWith(Schema.Array(Schema.String), {
|
|
199
191
|
default: () => []
|
|
200
192
|
});
|
|
201
|
-
const BaseVariant = Schema.Struct({
|
|
202
|
-
id: Resource.ID,
|
|
203
|
-
title: Schema.String,
|
|
204
|
-
options: VariantOptions,
|
|
205
|
-
quantity_rule: VariantQuantityRule
|
|
206
|
-
});
|
|
207
|
-
const ProductOption = Schema.Struct({
|
|
208
|
-
name: Schema.String,
|
|
209
|
-
position: Schema.Number,
|
|
210
|
-
values: Schema.Array(Schema.String)
|
|
211
|
-
});
|
|
212
|
-
const BaseProduct = Schema.Struct({
|
|
213
|
-
id: Resource.ID,
|
|
214
|
-
title: Schema.String,
|
|
215
|
-
handle: Schema.String,
|
|
216
|
-
variants: Schema.Array(BaseVariant),
|
|
217
|
-
options: Schema.Array(ProductOption),
|
|
218
|
-
tags: Schema.Array(Schema.String),
|
|
219
|
-
available: Schema.Boolean
|
|
220
|
-
});
|
|
221
|
-
const get = (url) => Effect.tryPromise({
|
|
222
|
-
try: () => fetch(url).then((res) => {
|
|
223
|
-
if (res.ok) {
|
|
224
|
-
return res.json();
|
|
225
|
-
}
|
|
226
|
-
throw new Error(String(res.status));
|
|
227
|
-
}),
|
|
228
|
-
catch: (e) => new Error(String(e))
|
|
229
|
-
});
|
|
230
|
-
const cachedGet = (url) => Effect.gen(function* () {
|
|
231
|
-
const cacheKey = `shopify-ajax-cart-api:${url}`;
|
|
232
|
-
const cachedValue = yield* Cache.get(cacheKey);
|
|
233
|
-
if (cachedValue) return cachedValue;
|
|
234
|
-
const value = yield* get(url);
|
|
235
|
-
yield* Cache.set(cacheKey, value, "60 minutes");
|
|
236
|
-
return value;
|
|
237
|
-
});
|
|
238
|
-
const Product = Schema.transformOrFail(Schema.String, BaseProduct, {
|
|
239
|
-
decode(handle, _, ast) {
|
|
240
|
-
return Effect.mapBoth(cachedGet(`/products/${handle}.js`), {
|
|
241
|
-
onFailure: (e) => new ParseResult.Type(ast, handle, e.message),
|
|
242
|
-
onSuccess: (product) => product
|
|
243
|
-
});
|
|
244
|
-
},
|
|
245
|
-
encode: (product) => ParseResult.succeed(product.handle)
|
|
246
|
-
});
|
|
247
193
|
const BaseLineItem = Schema.Struct({
|
|
248
194
|
id: Resource.ID,
|
|
249
195
|
properties: BaseAttributes,
|
|
@@ -268,7 +214,7 @@ const BaseLineItem = Schema.Struct({
|
|
|
268
214
|
final_line_price: Schema.Number,
|
|
269
215
|
final_price: Schema.Number,
|
|
270
216
|
url: Schema.String,
|
|
271
|
-
featured_image:
|
|
217
|
+
featured_image: Image,
|
|
272
218
|
image: Schema.String,
|
|
273
219
|
handle: Schema.String,
|
|
274
220
|
requires_shipping: Schema.Boolean,
|
|
@@ -294,7 +240,6 @@ const LineItem = Schema.transform(
|
|
|
294
240
|
Schema.extend(
|
|
295
241
|
BaseLineItem,
|
|
296
242
|
Schema.Struct({
|
|
297
|
-
product: Product,
|
|
298
243
|
properties_array: Schema.optionalWith(BaseAttributesArray, {
|
|
299
244
|
default: () => []
|
|
300
245
|
}),
|
|
@@ -330,8 +275,7 @@ const LineItem = Schema.transform(
|
|
|
330
275
|
Record.remove("private_properties"),
|
|
331
276
|
Record.remove("private_properties_array"),
|
|
332
277
|
Record.remove("public_properties"),
|
|
333
|
-
Record.remove("public_properties_array")
|
|
334
|
-
Record.remove("product")
|
|
278
|
+
Record.remove("public_properties_array")
|
|
335
279
|
)
|
|
336
280
|
}
|
|
337
281
|
);
|