@progus/connector 0.5.2 → 0.5.4

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 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: payload.data,
147
- externalId: payload.data.subscriptionId
152
+ data: normalized,
153
+ externalId: String(normalized.subscriptionId)
148
154
  });
149
155
  }
150
156
  async function assignPartnerId(payload) {
@@ -195,6 +201,28 @@ 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
+ return {
219
+ ...data,
220
+ subscriptionId,
221
+ subscriptionPrice,
222
+ subscriptionPeriod: period,
223
+ subscriptionName
224
+ };
225
+ }
198
226
  return {
199
227
  track: (eventName, payload) => postEvent(eventName, payload),
200
228
  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: payload.data,
119
- externalId: payload.data.subscriptionId
124
+ data: normalized,
125
+ externalId: String(normalized.subscriptionId)
120
126
  });
121
127
  }
122
128
  async function assignPartnerId(payload) {
@@ -167,6 +173,28 @@ 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
+ return {
191
+ ...data,
192
+ subscriptionId,
193
+ subscriptionPrice,
194
+ subscriptionPeriod: period,
195
+ subscriptionName
196
+ };
197
+ }
170
198
  return {
171
199
  track: (eventName, payload) => postEvent(eventName, payload),
172
200
  trackInstall,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@progus/connector",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Progus partner/affiliate connector helpers",
5
5
  "license": "MIT",
6
6
  "type": "module",