@progus/connector 0.5.1 → 0.5.3
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/index.cjs +33 -3
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -59,6 +59,7 @@ function createProgusConnector(config) {
|
|
|
59
59
|
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
60
60
|
const logger = config.logger ?? console;
|
|
61
61
|
const enableIdempotency = config.enableIdempotency !== false;
|
|
62
|
+
const validSubscriptionPeriods = /* @__PURE__ */ new Set(["ANNUAL", "EVERY_30_DAYS"]);
|
|
62
63
|
if (!fetchImpl) {
|
|
63
64
|
throw new Error("Fetch implementation is required");
|
|
64
65
|
}
|
|
@@ -141,10 +142,15 @@ function createProgusConnector(config) {
|
|
|
141
142
|
return postEvent("uninstallation", { shopDomain: payload.shopDomain });
|
|
142
143
|
}
|
|
143
144
|
async function trackSubscription(payload) {
|
|
145
|
+
const normalized = normalizeSubscriptionData(payload.data);
|
|
146
|
+
if (!normalized) {
|
|
147
|
+
logger?.info?.("Partner event skipped: invalid subscription data");
|
|
148
|
+
return { success: false, message: "Invalid subscription data" };
|
|
149
|
+
}
|
|
144
150
|
return postEvent("subscription", {
|
|
145
151
|
shopDomain: payload.shopDomain,
|
|
146
|
-
data:
|
|
147
|
-
externalId:
|
|
152
|
+
data: normalized,
|
|
153
|
+
externalId: String(normalized.subscriptionId)
|
|
148
154
|
});
|
|
149
155
|
}
|
|
150
156
|
async function assignPartnerId(payload) {
|
|
@@ -162,7 +168,7 @@ function createProgusConnector(config) {
|
|
|
162
168
|
if (!apiBaseUrl || !config.signingSecret) {
|
|
163
169
|
return { success: false, message: "Partners API configuration not set", status: 500 };
|
|
164
170
|
}
|
|
165
|
-
const requestBody = JSON.stringify({ shop: payload.shopDomain });
|
|
171
|
+
const requestBody = JSON.stringify({ shop: payload.shopDomain, appName: config.appKey });
|
|
166
172
|
const headers = {
|
|
167
173
|
"Content-Type": "application/json",
|
|
168
174
|
"x-progus-hmac-sha256": signPayload(requestBody, config.signingSecret)
|
|
@@ -195,6 +201,30 @@ function createProgusConnector(config) {
|
|
|
195
201
|
return { success: false, message: "Error checking partner ID", status: 500 };
|
|
196
202
|
}
|
|
197
203
|
}
|
|
204
|
+
function normalizeSubscriptionData(data) {
|
|
205
|
+
const subscriptionId = Number(data.subscriptionId);
|
|
206
|
+
if (!Number.isFinite(subscriptionId)) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
const subscriptionPrice = Number(data.subscriptionPrice);
|
|
210
|
+
if (!Number.isFinite(subscriptionPrice)) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
const period = data.subscriptionPeriod ? String(data.subscriptionPeriod).toUpperCase() : "";
|
|
214
|
+
if (!validSubscriptionPeriods.has(period)) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
const subscriptionName = data.subscriptionName ? data.subscriptionName.toLowerCase() : void 0;
|
|
218
|
+
const subscriptionStatus = data.subscriptionStatus ? data.subscriptionStatus.toLowerCase() : void 0;
|
|
219
|
+
return {
|
|
220
|
+
...data,
|
|
221
|
+
subscriptionId,
|
|
222
|
+
subscriptionPrice,
|
|
223
|
+
subscriptionPeriod: period,
|
|
224
|
+
subscriptionName,
|
|
225
|
+
subscriptionStatus
|
|
226
|
+
};
|
|
227
|
+
}
|
|
198
228
|
return {
|
|
199
229
|
track: (eventName, payload) => postEvent(eventName, payload),
|
|
200
230
|
trackInstall,
|
package/dist/index.d.cts
CHANGED
|
@@ -40,8 +40,8 @@ type AssignPartnerIdInput = {
|
|
|
40
40
|
type SubscriptionEventData = {
|
|
41
41
|
subscriptionStatus?: string;
|
|
42
42
|
subscriptionName?: string;
|
|
43
|
-
subscriptionId?: string;
|
|
44
|
-
subscriptionPrice?: number;
|
|
43
|
+
subscriptionId?: number | string;
|
|
44
|
+
subscriptionPrice?: number | string;
|
|
45
45
|
subscriptionPeriod?: string;
|
|
46
46
|
};
|
|
47
47
|
|
package/dist/index.d.ts
CHANGED
|
@@ -40,8 +40,8 @@ type AssignPartnerIdInput = {
|
|
|
40
40
|
type SubscriptionEventData = {
|
|
41
41
|
subscriptionStatus?: string;
|
|
42
42
|
subscriptionName?: string;
|
|
43
|
-
subscriptionId?: string;
|
|
44
|
-
subscriptionPrice?: number;
|
|
43
|
+
subscriptionId?: number | string;
|
|
44
|
+
subscriptionPrice?: number | string;
|
|
45
45
|
subscriptionPeriod?: string;
|
|
46
46
|
};
|
|
47
47
|
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ function createProgusConnector(config) {
|
|
|
31
31
|
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
32
32
|
const logger = config.logger ?? console;
|
|
33
33
|
const enableIdempotency = config.enableIdempotency !== false;
|
|
34
|
+
const validSubscriptionPeriods = /* @__PURE__ */ new Set(["ANNUAL", "EVERY_30_DAYS"]);
|
|
34
35
|
if (!fetchImpl) {
|
|
35
36
|
throw new Error("Fetch implementation is required");
|
|
36
37
|
}
|
|
@@ -113,10 +114,15 @@ function createProgusConnector(config) {
|
|
|
113
114
|
return postEvent("uninstallation", { shopDomain: payload.shopDomain });
|
|
114
115
|
}
|
|
115
116
|
async function trackSubscription(payload) {
|
|
117
|
+
const normalized = normalizeSubscriptionData(payload.data);
|
|
118
|
+
if (!normalized) {
|
|
119
|
+
logger?.info?.("Partner event skipped: invalid subscription data");
|
|
120
|
+
return { success: false, message: "Invalid subscription data" };
|
|
121
|
+
}
|
|
116
122
|
return postEvent("subscription", {
|
|
117
123
|
shopDomain: payload.shopDomain,
|
|
118
|
-
data:
|
|
119
|
-
externalId:
|
|
124
|
+
data: normalized,
|
|
125
|
+
externalId: String(normalized.subscriptionId)
|
|
120
126
|
});
|
|
121
127
|
}
|
|
122
128
|
async function assignPartnerId(payload) {
|
|
@@ -134,7 +140,7 @@ function createProgusConnector(config) {
|
|
|
134
140
|
if (!apiBaseUrl || !config.signingSecret) {
|
|
135
141
|
return { success: false, message: "Partners API configuration not set", status: 500 };
|
|
136
142
|
}
|
|
137
|
-
const requestBody = JSON.stringify({ shop: payload.shopDomain });
|
|
143
|
+
const requestBody = JSON.stringify({ shop: payload.shopDomain, appName: config.appKey });
|
|
138
144
|
const headers = {
|
|
139
145
|
"Content-Type": "application/json",
|
|
140
146
|
"x-progus-hmac-sha256": signPayload(requestBody, config.signingSecret)
|
|
@@ -167,6 +173,30 @@ function createProgusConnector(config) {
|
|
|
167
173
|
return { success: false, message: "Error checking partner ID", status: 500 };
|
|
168
174
|
}
|
|
169
175
|
}
|
|
176
|
+
function normalizeSubscriptionData(data) {
|
|
177
|
+
const subscriptionId = Number(data.subscriptionId);
|
|
178
|
+
if (!Number.isFinite(subscriptionId)) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
const subscriptionPrice = Number(data.subscriptionPrice);
|
|
182
|
+
if (!Number.isFinite(subscriptionPrice)) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const period = data.subscriptionPeriod ? String(data.subscriptionPeriod).toUpperCase() : "";
|
|
186
|
+
if (!validSubscriptionPeriods.has(period)) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
const subscriptionName = data.subscriptionName ? data.subscriptionName.toLowerCase() : void 0;
|
|
190
|
+
const subscriptionStatus = data.subscriptionStatus ? data.subscriptionStatus.toLowerCase() : void 0;
|
|
191
|
+
return {
|
|
192
|
+
...data,
|
|
193
|
+
subscriptionId,
|
|
194
|
+
subscriptionPrice,
|
|
195
|
+
subscriptionPeriod: period,
|
|
196
|
+
subscriptionName,
|
|
197
|
+
subscriptionStatus
|
|
198
|
+
};
|
|
199
|
+
}
|
|
170
200
|
return {
|
|
171
201
|
track: (eventName, payload) => postEvent(eventName, payload),
|
|
172
202
|
trackInstall,
|