@wix/headless-gift-voucher 0.0.1

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.
Files changed (69) hide show
  1. package/cjs/dist/__mocks__/gift-card.d.ts +14 -0
  2. package/cjs/dist/__mocks__/gift-card.d.ts.map +1 -0
  3. package/cjs/dist/__mocks__/gift-card.js +49 -0
  4. package/cjs/dist/enums/index.d.ts +52 -0
  5. package/cjs/dist/enums/index.d.ts.map +1 -0
  6. package/cjs/dist/enums/index.js +52 -0
  7. package/cjs/dist/react/GiftCard.d.ts +1318 -0
  8. package/cjs/dist/react/GiftCard.d.ts.map +1 -0
  9. package/cjs/dist/react/GiftCard.js +1126 -0
  10. package/cjs/dist/react/core/GiftCard.d.ts +863 -0
  11. package/cjs/dist/react/core/GiftCard.d.ts.map +1 -0
  12. package/cjs/dist/react/core/GiftCard.js +737 -0
  13. package/cjs/dist/react/index.d.ts +2 -0
  14. package/cjs/dist/react/index.d.ts.map +1 -0
  15. package/cjs/dist/react/index.js +1 -0
  16. package/cjs/dist/services/gift-card-checkout-service.d.ts +133 -0
  17. package/cjs/dist/services/gift-card-checkout-service.d.ts.map +1 -0
  18. package/cjs/dist/services/gift-card-checkout-service.js +159 -0
  19. package/cjs/dist/services/gift-card-service.d.ts +102 -0
  20. package/cjs/dist/services/gift-card-service.d.ts.map +1 -0
  21. package/cjs/dist/services/gift-card-service.js +165 -0
  22. package/cjs/dist/services/index.d.ts +3 -0
  23. package/cjs/dist/services/index.d.ts.map +1 -0
  24. package/cjs/dist/services/index.js +2 -0
  25. package/cjs/dist/utils/formatting-utils.d.ts +13 -0
  26. package/cjs/dist/utils/formatting-utils.d.ts.map +1 -0
  27. package/cjs/dist/utils/formatting-utils.js +38 -0
  28. package/cjs/dist/utils/gift-card-utils.d.ts +18 -0
  29. package/cjs/dist/utils/gift-card-utils.d.ts.map +1 -0
  30. package/cjs/dist/utils/gift-card-utils.js +118 -0
  31. package/cjs/dist/utils/validation-utils.d.ts +10 -0
  32. package/cjs/dist/utils/validation-utils.d.ts.map +1 -0
  33. package/cjs/dist/utils/validation-utils.js +24 -0
  34. package/dist/__mocks__/gift-card.d.ts +14 -0
  35. package/dist/__mocks__/gift-card.d.ts.map +1 -0
  36. package/dist/__mocks__/gift-card.js +49 -0
  37. package/dist/enums/index.d.ts +52 -0
  38. package/dist/enums/index.d.ts.map +1 -0
  39. package/dist/enums/index.js +52 -0
  40. package/dist/react/GiftCard.d.ts +1318 -0
  41. package/dist/react/GiftCard.d.ts.map +1 -0
  42. package/dist/react/GiftCard.js +1126 -0
  43. package/dist/react/core/GiftCard.d.ts +863 -0
  44. package/dist/react/core/GiftCard.d.ts.map +1 -0
  45. package/dist/react/core/GiftCard.js +737 -0
  46. package/dist/react/index.d.ts +2 -0
  47. package/dist/react/index.d.ts.map +1 -0
  48. package/dist/react/index.js +1 -0
  49. package/dist/services/gift-card-checkout-service.d.ts +133 -0
  50. package/dist/services/gift-card-checkout-service.d.ts.map +1 -0
  51. package/dist/services/gift-card-checkout-service.js +159 -0
  52. package/dist/services/gift-card-service.d.ts +102 -0
  53. package/dist/services/gift-card-service.d.ts.map +1 -0
  54. package/dist/services/gift-card-service.js +165 -0
  55. package/dist/services/index.d.ts +3 -0
  56. package/dist/services/index.d.ts.map +1 -0
  57. package/dist/services/index.js +2 -0
  58. package/dist/utils/formatting-utils.d.ts +13 -0
  59. package/dist/utils/formatting-utils.d.ts.map +1 -0
  60. package/dist/utils/formatting-utils.js +38 -0
  61. package/dist/utils/gift-card-utils.d.ts +18 -0
  62. package/dist/utils/gift-card-utils.d.ts.map +1 -0
  63. package/dist/utils/gift-card-utils.js +118 -0
  64. package/dist/utils/validation-utils.d.ts +10 -0
  65. package/dist/utils/validation-utils.d.ts.map +1 -0
  66. package/dist/utils/validation-utils.js +24 -0
  67. package/package.json +72 -0
  68. package/react/package.json +4 -0
  69. package/services/package.json +4 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gift-card-utils.d.ts","sourceRoot":"","sources":["../../src/utils/gift-card-utils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAEhB,QAAQ,EACT,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAKnE,wBAAgB,eAAe,CAC7B,OAAO,EAAE,eAAe,GAAG,SAAS,EACpC,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAC/B,MAAM,GAAG,IAAI,CAef;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,eAAe,GAAG,SAAS,EACpC,iBAAiB,EAAE,MAAM,GAAG,IAAI,EAChC,YAAY,EAAE,MAAM,GACnB,gBAAgB,GAAG,IAAI,CA+BzB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,eAAe,GAAG,SAAS,GACnC,gBAAgB,CAclB;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,eAAe,GAAG,SAAS,EACpC,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,cAAc,EAAE,OAAO,EACvB,wBAAwB,EAAE,OAAO,EACjC,0BAA0B,EAAE,OAAO,GAClC,OAAO,CAMT;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,eAAe,GAAG,SAAS,EACpC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,OAAO,EACvB,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,IAAI,EACf,gBAAgB,EAAE,MAAM,GACvB,QAAQ,EAAE,CAiDZ"}
@@ -0,0 +1,118 @@
1
+ import { CUSTOM_VARIANT_ID, RISE_APP_ID } from '../enums/index.js';
2
+ /*
3
+ * Gets the image for the currently selected variant, or falls back to product image.
4
+ */
5
+ export function getCurrentImage(product, selectedVariantId) {
6
+ if (!product) {
7
+ return null;
8
+ }
9
+ if (selectedVariantId && selectedVariantId !== CUSTOM_VARIANT_ID) {
10
+ const selectedVariant = product.presetVariants?.find((v) => v._id === selectedVariantId);
11
+ if (selectedVariant?.image) {
12
+ return selectedVariant.image;
13
+ }
14
+ }
15
+ return product.image ?? null;
16
+ }
17
+ /**
18
+ * Gets the current price data based on the selected variant.
19
+ * Returns raw numeric amounts - use Money component for formatting.
20
+ */
21
+ export function getCurrentPriceData(product, selectedVariantId, customAmount) {
22
+ if (!product) {
23
+ return null;
24
+ }
25
+ if (selectedVariantId === CUSTOM_VARIANT_ID) {
26
+ return {
27
+ price: customAmount,
28
+ value: customAmount,
29
+ hasDiscount: false,
30
+ };
31
+ }
32
+ let selectedVariant = product.presetVariants?.find((v) => v._id === selectedVariantId) ??
33
+ product.presetVariants?.[0];
34
+ if (selectedVariant) {
35
+ const price = parseFloat(selectedVariant.price?.amount ?? '0');
36
+ const value = parseFloat(selectedVariant.value?.amount ?? selectedVariant.price?.amount ?? '0');
37
+ return {
38
+ price,
39
+ value,
40
+ hasDiscount: price < value,
41
+ };
42
+ }
43
+ return null;
44
+ }
45
+ /**
46
+ * Gets the min/max values for custom amount validation from the product.
47
+ */
48
+ export function getCustomAmountData(product) {
49
+ const customVariant = product?.customVariant;
50
+ if (!customVariant) {
51
+ return { min: null, max: null };
52
+ }
53
+ return {
54
+ min: customVariant.minValue?.amount
55
+ ? parseFloat(customVariant.minValue.amount)
56
+ : 1,
57
+ max: customVariant.maxValue?.amount
58
+ ? parseFloat(customVariant.maxValue.amount)
59
+ : null,
60
+ };
61
+ }
62
+ export function canAddToCartCheck(product, variantId, isGiftPurchase, isCustomAmountValidCheck, isRecipientEmailValidCheck) {
63
+ if (!product || !variantId)
64
+ return false;
65
+ if (variantId === CUSTOM_VARIANT_ID && !isCustomAmountValidCheck)
66
+ return false;
67
+ if (isGiftPurchase && !isRecipientEmailValidCheck)
68
+ return false;
69
+ return true;
70
+ }
71
+ /**
72
+ * Converts the product data to line items for the cart API.
73
+ */
74
+ export function productToLineItems(product, currency, variantId, customAmount, qty, isGiftPurchase, recipientEmail, recipientName, deliverAt, recipientMessage) {
75
+ if (!product || !product._id || !variantId)
76
+ return [];
77
+ const options = {
78
+ quantity: qty,
79
+ currency,
80
+ wixGiftCardsAppNewCatalog: true,
81
+ };
82
+ // Variant or custom amount
83
+ if (variantId === CUSTOM_VARIANT_ID) {
84
+ options.customAmount = customAmount;
85
+ }
86
+ else {
87
+ options.variantId = variantId;
88
+ }
89
+ // Gifting info (only when isGift)
90
+ if (isGiftPurchase) {
91
+ const nameParts = recipientName.split(' ').filter(Boolean);
92
+ const firstName = nameParts[0] || '';
93
+ const lastName = nameParts.slice(1).join(' ');
94
+ options.giftingInfo = {
95
+ recipientInfo: {
96
+ firstName,
97
+ lastName,
98
+ email: recipientEmail,
99
+ },
100
+ };
101
+ if (recipientMessage && recipientMessage.length > 0) {
102
+ options.giftingInfo.greetingMessage = recipientMessage;
103
+ }
104
+ if (deliverAt) {
105
+ options.giftingInfo.deliverAt = deliverAt;
106
+ }
107
+ }
108
+ return [
109
+ {
110
+ quantity: qty,
111
+ catalogReference: {
112
+ appId: RISE_APP_ID,
113
+ catalogItemId: product._id,
114
+ options,
115
+ },
116
+ },
117
+ ];
118
+ }
@@ -0,0 +1,10 @@
1
+ import { CustomAmountData } from '../services/gift-card-checkout-service.js';
2
+ /**
3
+ * Validates if the custom amount is within the allowed range.
4
+ */
5
+ export declare function validateCustomAmount(amount: number, customAmountData: CustomAmountData): boolean;
6
+ /**
7
+ * Validates if an email address is valid using a simple regex pattern.
8
+ */
9
+ export declare function validateEmail(email: string): boolean;
10
+ //# sourceMappingURL=validation-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation-utils.d.ts","sourceRoot":"","sources":["../../src/utils/validation-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAE7E;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,gBAAgB,GACjC,OAAO,CAYT;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAOpD"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Validates if the custom amount is within the allowed range.
3
+ */
4
+ export function validateCustomAmount(amount, customAmountData) {
5
+ const { min, max } = customAmountData;
6
+ if (min !== null && amount < min) {
7
+ return false;
8
+ }
9
+ if (max !== null && amount > max) {
10
+ return false;
11
+ }
12
+ return amount >= 1;
13
+ }
14
+ /**
15
+ * Validates if an email address is valid using a simple regex pattern.
16
+ */
17
+ export function validateEmail(email) {
18
+ if (!email || email.trim() === '') {
19
+ return false;
20
+ }
21
+ // Simple email regex pattern
22
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
23
+ return emailRegex.test(email.trim());
24
+ }
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@wix/headless-gift-voucher",
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "scripts": {
7
+ "prebuild": "cd ../utils && yarn build && cd ../media && yarn build",
8
+ "build": "npm run build:esm && npm run build:cjs",
9
+ "build:esm": "tsc -p tsconfig.json",
10
+ "build:cjs": "tsc -p tsconfig.cjs.json",
11
+ "test": "vitest",
12
+ "lint:fix": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md}\"",
13
+ "lint:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,json,md}\""
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "cjs",
18
+ "react",
19
+ "services",
20
+ "enums"
21
+ ],
22
+ "exports": {
23
+ "./react": {
24
+ "types": "./dist/react/index.d.ts",
25
+ "import": "./dist/react/index.js",
26
+ "require": "./cjs/dist/react/index.js"
27
+ },
28
+ "./services": {
29
+ "types": "./dist/services/index.d.ts",
30
+ "import": "./dist/services/index.js",
31
+ "require": "./cjs/dist/services/index.js"
32
+ }
33
+ },
34
+ "devDependencies": {
35
+ "@testing-library/dom": "^10.4.0",
36
+ "@testing-library/jest-dom": "^6.6.3",
37
+ "@testing-library/react": "^16.3.0",
38
+ "@types/node": "^20.9.0",
39
+ "@vitest/ui": "^3.1.4",
40
+ "@wix/headless-components": "0.0.0",
41
+ "jsdom": "^26.1.0",
42
+ "prettier": "^3.4.2",
43
+ "typescript": "^5.8.3",
44
+ "vitest": "^3.1.4"
45
+ },
46
+ "dependencies": {
47
+ "@wix/auto_sdk_ecom_checkout": "^1.0.115",
48
+ "@wix/auto_sdk_gift-vouchers_gift-voucher-products": "^1.0.22",
49
+ "@wix/ecom": "^1.0.1556",
50
+ "@wix/essentials": "^1.0.0",
51
+ "@wix/gift-vouchers": "^1.0.0",
52
+ "@wix/headless-ecom": "0.0.38",
53
+ "@wix/headless-media": "0.0.18",
54
+ "@wix/headless-utils": "0.0.8",
55
+ "@wix/services-definitions": "^0.1.5",
56
+ "@wix/services-manager-react": "^0.1.26"
57
+ },
58
+ "peerDependencies": {
59
+ "@wix/headless-components": "^0.0.0"
60
+ },
61
+ "publishConfig": {
62
+ "registry": "https://registry.npmjs.org/",
63
+ "access": "public"
64
+ },
65
+ "wix": {
66
+ "artifact": {
67
+ "artifactId": "headless-gift-card",
68
+ "groupId": "com.wixpress.headless-components"
69
+ }
70
+ },
71
+ "falconPackageHash": "3c9f5ea0f995bb2cc0f74187ab8802c0d13cb38c1833577f463274da"
72
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "../cjs/dist/react/index.js",
3
+ "types": "../dist/react/index.d.ts"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "../cjs/dist/services/index.js",
3
+ "types": "../dist/services/index.d.ts"
4
+ }