@pvh-afl/core 1.1.6 → 1.1.8
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/integrations/commerce/shopify-admin.service.d.ts +76 -16
- package/dist/integrations/commerce/shopify-admin.service.d.ts.map +1 -1
- package/dist/integrations/commerce/shopify-admin.service.js +585 -400
- package/dist/integrations/commerce/shopify-admin.service.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,54 +4,99 @@ import { CouponValidationResult } from '../loyalty/capillary.types';
|
|
|
4
4
|
* Shopify Admin API Service
|
|
5
5
|
*
|
|
6
6
|
* Handles Shopify Admin API operations for discount code management.
|
|
7
|
-
* Uses
|
|
7
|
+
* Uses GraphQL Admin API for discount operations with tags support.
|
|
8
|
+
*
|
|
9
|
+
* Migration from REST to GraphQL (2024):
|
|
10
|
+
* - REST: price_rules + discount_codes endpoints
|
|
11
|
+
* - GraphQL: discountCodeBasic mutations with tags support
|
|
12
|
+
*
|
|
13
|
+
* All Capillary-synced discounts are tagged with "CAPILLARY" for easy identification.
|
|
8
14
|
*/
|
|
9
15
|
export declare class ShopifyAdminService {
|
|
10
16
|
private readonly configService;
|
|
11
|
-
private readonly
|
|
17
|
+
private readonly GRAPHQL_API_VERSION;
|
|
18
|
+
private readonly CAPILLARY_TAG;
|
|
12
19
|
constructor(configService: ConfigService);
|
|
13
20
|
/**
|
|
14
21
|
* Create a Shopify discount code from a validated Capillary coupon.
|
|
15
22
|
*
|
|
16
|
-
*
|
|
23
|
+
* Behavior:
|
|
17
24
|
* - Uses original Capillary code directly (e.g., "SUMMER20")
|
|
18
|
-
* - If code exists: adds customer to
|
|
19
|
-
* - If code doesn't exist: creates with customer
|
|
20
|
-
* -
|
|
25
|
+
* - If code exists: updates properties from Capillary and adds customer to eligibility
|
|
26
|
+
* - If code doesn't exist: creates with customer-specific eligibility
|
|
27
|
+
* - Tags discount with "CAPILLARY" for identification
|
|
28
|
+
* - Uses appliesOncePerCustomer: true for per-customer usage limit
|
|
21
29
|
*/
|
|
22
30
|
createDiscountFromCapillaryCoupon(brand: string, capillaryValidation: CouponValidationResult, shopifyCustomerId: string): Promise<ShopifyDiscountResult>;
|
|
23
31
|
/**
|
|
24
|
-
*
|
|
32
|
+
* Create a new discount via GraphQL Admin API.
|
|
33
|
+
*/
|
|
34
|
+
private createDiscountViaGraphQL;
|
|
35
|
+
/**
|
|
36
|
+
* Update an existing discount with fresh Capillary data and add customer.
|
|
37
|
+
* This resolves the stale data issue by always syncing latest properties.
|
|
38
|
+
*/
|
|
39
|
+
private updateDiscountWithCapillaryData;
|
|
40
|
+
/**
|
|
41
|
+
* Build discount value object based on Capillary discount type.
|
|
42
|
+
*/
|
|
43
|
+
private buildDiscountValue;
|
|
44
|
+
/**
|
|
45
|
+
* Add a customer to an existing discount's eligibility.
|
|
25
46
|
* Used when multiple customers share the same Capillary coupon code.
|
|
47
|
+
*
|
|
48
|
+
* @deprecated Use updateDiscountWithCapillaryData instead which also updates properties
|
|
26
49
|
*/
|
|
27
50
|
addCustomerToPriceRule(brand: string, priceRuleId: string, shopifyCustomerId: string): Promise<{
|
|
28
51
|
success: boolean;
|
|
29
52
|
error?: string;
|
|
30
53
|
}>;
|
|
31
54
|
/**
|
|
32
|
-
*
|
|
55
|
+
* Add a customer to an existing discount's eligibility.
|
|
56
|
+
*/
|
|
57
|
+
addCustomerToDiscount(brand: string, discountId: string, shopifyCustomerId: string): Promise<{
|
|
58
|
+
success: boolean;
|
|
59
|
+
error?: string;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Format customer ID as Shopify GID.
|
|
63
|
+
*/
|
|
64
|
+
private formatCustomerGid;
|
|
65
|
+
/**
|
|
66
|
+
* Extract numeric ID from Shopify GID or return as-is if already numeric.
|
|
67
|
+
*
|
|
68
|
+
* @deprecated Use formatCustomerGid instead for GID format
|
|
33
69
|
*/
|
|
34
70
|
private extractNumericCustomerId;
|
|
35
|
-
|
|
36
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Lookup discount code by code string.
|
|
73
|
+
* Returns discount ID if found, null otherwise.
|
|
74
|
+
*/
|
|
37
75
|
private getDiscountCodeByCode;
|
|
38
|
-
private findPriceRuleByTitle;
|
|
39
|
-
private findDiscountCodeByCode;
|
|
40
76
|
private getAdminConfig;
|
|
77
|
+
/**
|
|
78
|
+
* Execute a GraphQL query/mutation against Shopify Admin API.
|
|
79
|
+
*/
|
|
80
|
+
private executeGraphQL;
|
|
41
81
|
getWebhookSecret(brand: string): string;
|
|
42
82
|
/**
|
|
43
|
-
* Reactivate a Shopify discount code by
|
|
83
|
+
* Reactivate a Shopify discount code by extending its end date and usage limit.
|
|
44
84
|
* Used when a redeemed coupon needs to be returned to the user (refund/cancellation).
|
|
45
85
|
*/
|
|
46
86
|
reactivateDiscountCode(brand: string, discountCode: string): Promise<DiscountCodeReactivateResult>;
|
|
47
87
|
/**
|
|
48
|
-
* Disable
|
|
88
|
+
* Disable/delete a Shopify discount code.
|
|
49
89
|
* Used when an earned coupon needs to be revoked (refund/cancellation).
|
|
50
90
|
*/
|
|
51
91
|
disableDiscountCode(brand: string, discountCode: string): Promise<DiscountCodeDisableResult>;
|
|
92
|
+
/**
|
|
93
|
+
* Get active Shopify discount codes filtered by tag.
|
|
94
|
+
* Returns discounts with code, title, discount type/value, validity dates, and tags.
|
|
95
|
+
*/
|
|
96
|
+
getDiscountsByTag(brand: string, tag: string, limit?: number): Promise<ShopifyDiscount[]>;
|
|
52
97
|
/**
|
|
53
98
|
* Sync a used Capillary coupon to Shopify for refund tracking.
|
|
54
|
-
* Creates a
|
|
99
|
+
* Creates a discount code marked as already used (ended).
|
|
55
100
|
* This is needed when GoKwik applies a coupon that doesn't exist in Shopify.
|
|
56
101
|
*
|
|
57
102
|
* Uses original code directly (no prefix).
|
|
@@ -62,12 +107,14 @@ export declare class ShopifyAdminService {
|
|
|
62
107
|
* Returns a date 30 days from now if the current end date has passed.
|
|
63
108
|
*/
|
|
64
109
|
private getExtendedEndDate;
|
|
65
|
-
private getHeaders;
|
|
66
110
|
}
|
|
67
111
|
export interface ShopifyDiscountResult {
|
|
68
112
|
success: boolean;
|
|
69
113
|
discountCode: string;
|
|
114
|
+
discountId?: string;
|
|
115
|
+
/** @deprecated Use discountId instead */
|
|
70
116
|
priceRuleId?: string;
|
|
117
|
+
/** @deprecated Use discountId instead */
|
|
71
118
|
discountCodeId?: string;
|
|
72
119
|
alreadyExists?: boolean;
|
|
73
120
|
error?: string;
|
|
@@ -83,4 +130,17 @@ export interface DiscountCodeDisableResult {
|
|
|
83
130
|
deleted?: boolean;
|
|
84
131
|
error?: string;
|
|
85
132
|
}
|
|
133
|
+
export interface ShopifyDiscount {
|
|
134
|
+
id: string;
|
|
135
|
+
code: string;
|
|
136
|
+
title: string;
|
|
137
|
+
discountType: 'ABS' | 'PERC';
|
|
138
|
+
discountValue: number;
|
|
139
|
+
discountUpto?: number;
|
|
140
|
+
minOrderValue?: number;
|
|
141
|
+
startsAt: string;
|
|
142
|
+
endsAt?: string;
|
|
143
|
+
usageLimit?: number;
|
|
144
|
+
tags: string[];
|
|
145
|
+
}
|
|
86
146
|
//# sourceMappingURL=shopify-admin.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shopify-admin.service.d.ts","sourceRoot":"","sources":["../../../src/integrations/commerce/shopify-admin.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE
|
|
1
|
+
{"version":3,"file":"shopify-admin.service.d.ts","sourceRoot":"","sources":["../../../src/integrations/commerce/shopify-admin.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE;;;;;;;;;;;GAWG;AACH,qBACa,mBAAmB;IAIlB,O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