@progus/connector 0.6.8 → 0.7.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.
package/README.md CHANGED
@@ -8,80 +8,124 @@ Headless connector for Progus partner/affiliate tracking and partner ID assignme
8
8
  npm install @progus/connector
9
9
  ```
10
10
 
11
- ## Usage (Shopify app, Node/TS)
11
+ ## Minimal Integration
12
+
13
+ Integrate the partner program in 4 steps:
14
+
15
+ ### 1. Server connector setup
12
16
 
13
17
  ```ts
18
+ // utils/progus-connector.server.ts
14
19
  import { createProgusConnector } from "@progus/connector";
15
20
 
16
- const connector = createProgusConnector({
17
- appKey: "progus-store-locator",
18
- apiBaseUrl: process.env.PARTNERS_API_URL!,
19
- signingSecret: process.env.PARTNERS_SECRET_KEY!,
20
- apiKey: process.env.PARTNERS_API_KEY,
21
- });
21
+ export function isPartnersConnectorConfigured(): boolean {
22
+ return Boolean(process.env.PARTNERS_API_URL && process.env.PARTNERS_SECRET_KEY);
23
+ }
24
+
25
+ export function getPartnersConnector() {
26
+ return createProgusConnector({
27
+ appKey: "your-app-name",
28
+ apiBaseUrl: process.env.PARTNERS_API_URL || "",
29
+ signingSecret: process.env.PARTNERS_SECRET_KEY || "",
30
+ apiKey: process.env.PARTNERS_API_KEY,
31
+ });
32
+ }
33
+ ```
34
+
35
+ ### 2. Cookie-based install tracking (client-side)
22
36
 
23
- await connector.trackInstall({
37
+ ```ts
38
+ // On app load (e.g. in root route useEffect)
39
+ const cookieMatch = document.cookie.match(/(?:^|; )progus_partner_id=([^;]*)/);
40
+ const partnerId = cookieMatch ? decodeURIComponent(cookieMatch[1]) : null;
41
+
42
+ if (partnerId) {
43
+ await connector.trackInstall({ shopDomain: session.shop, partnerId });
44
+ document.cookie = "progus_partner_id=; Path=/; Max-Age=0"; // clear after tracking
45
+ }
46
+ ```
47
+
48
+ ### 3. Partner ID assignment (Save Partner ID button)
49
+
50
+ ```ts
51
+ // On "Save Partner ID" action
52
+ const result = await connector.assignPartnerIdWithSubscription({
24
53
  shopDomain: session.shop,
25
- partnerId: partnerIdFromCookie,
54
+ partnerId: inputValue,
55
+ admin, // Shopify Admin GraphQL client
26
56
  });
27
57
 
58
+ if (result.success) {
59
+ // Lock the input field, show success
60
+ }
61
+ ```
62
+
63
+ ### 4. Required webhooks
64
+
65
+ **APP_SUBSCRIPTIONS_UPDATE** - track subscription changes:
66
+ ```ts
28
67
  await connector.trackSubscriptionUpdated({
29
- shopDomain: session.shop,
68
+ shopDomain: shop,
30
69
  data: {
31
- subscriptionStatus: "ACTIVE",
32
- subscriptionName: "pro",
33
- subscriptionId: "gid://shopify/AppSubscription/123",
70
+ subscriptionId, // numeric ID (required)
71
+ subscriptionPrice, // number (required)
72
+ subscriptionPeriod, // "EVERY_30_DAYS" or "ANNUAL" (required)
73
+ subscriptionStatus, // e.g. "ACTIVE", "CANCELLED"
74
+ subscriptionName, // plan name
34
75
  },
35
76
  });
77
+ ```
36
78
 
37
- await connector.trackUninstall({ shopDomain: session.shop });
79
+ **APP_UNINSTALLED** - track uninstalls:
80
+ ```ts
81
+ await connector.trackUninstall({ shopDomain: shop });
38
82
  ```
39
83
 
40
- ## Prompt: Partner program implementation (copy/paste)
84
+ ## AI Prompt: Partner program implementation
85
+
86
+ Copy/paste for AI assistants:
41
87
 
42
88
  ```
43
89
  You are integrating Progus Partner Program using @progus/connector in a Shopify app.
44
90
 
45
- Implement these pieces:
46
- 1) Server connector:
47
- - createProgusConnector({ appKey, PARTNERS_API_URL, PARTNERS_SECRET_KEY, PARTNERS_API_KEY })
48
- - expose getPartnersConnector() + isPartnersConnectorConfigured()
91
+ Required files to create/modify:
49
92
 
50
- 2) Install tracking:
51
- - after app install, call trackInstall({ shopDomain, partnerId })
52
- - partnerId source: read cookie "progus_partner_id" on progus.com
53
- - cookie must be JS-readable (HttpOnly=false) and cross-site (SameSite=None; Secure)
54
- - if partnerId is missing, skip tracking
93
+ 1) Server connector (utils/progus-connector.server.ts):
94
+ - createProgusConnector({ appKey, apiBaseUrl, signingSecret, apiKey })
95
+ - export getPartnersConnector() and isPartnersConnectorConfigured()
55
96
 
56
- 3) Partner ID assignment UI:
57
- - save partnerId from merchant input (Partner ID field)
58
- - call assignPartnerId({ shopDomain, partnerId }) on save
59
- - lock the field after successful save
60
- - optionally check partnerId on load with checkPartnerId({ shopDomain })
97
+ 2) Cookie-based install tracking (client-side, on app load):
98
+ - read cookie "progus_partner_id" (HttpOnly=false, SameSite=None, Secure)
99
+ - if exists: call connector.trackInstall({ shopDomain, partnerId })
100
+ - clear cookie after successful tracking
101
+ - if no cookie, skip tracking
61
102
 
62
- 4) Subscription tracking:
63
- - on app_subscriptions/update webhook, send trackSubscriptionUpdated
64
- - payload must include: subscriptionId (digits), subscriptionPrice (number), subscriptionPeriod ("EVERY_30_DAYS" or "ANNUAL"), subscriptionStatus, subscriptionName
65
- - if webhook payload is missing price/interval, fetch details via Admin GraphQL node(id) -> AppSubscription -> lineItems.plan.pricingDetails
103
+ 3) Partner ID assignment UI (on "Save Partner ID" button):
104
+ - call connector.assignPartnerIdWithSubscription({ shopDomain, partnerId, admin })
105
+ - admin = Shopify Admin GraphQL client
106
+ - connector normalizes partnerId and fetches active subscription automatically
107
+ - subscription event sent ONLY if price + period are available
108
+ - lock the Partner ID field after success
109
+ - optionally: check existing partnerId on load with connector.checkPartnerId({ shopDomain })
66
110
 
67
- 5) Uninstall tracking:
68
- - on app/uninstalled webhook, call trackUninstall({ shopDomain })
111
+ 4) APP_SUBSCRIPTIONS_UPDATE webhook (required):
112
+ - call connector.trackSubscriptionUpdated({ shopDomain, data })
113
+ - data must include: subscriptionId (number), subscriptionPrice (number), subscriptionPeriod ("EVERY_30_DAYS" | "ANNUAL")
114
+ - if webhook payload missing price/interval, query: node(id) -> AppSubscription -> lineItems.plan.pricingDetails
115
+ - connector validates; event skipped if price/period missing
69
116
 
70
- Return errors gracefully; do not break webhooks if partner tracking fails.
71
- ```
117
+ 5) APP_UNINSTALLED webhook (required):
118
+ - call connector.trackUninstall({ shopDomain })
72
119
 
73
- ## Partner ID assignment
120
+ Error handling: catch and log errors; never break webhooks on partner tracking failure.
121
+ ```
74
122
 
75
- ```ts
76
- const result = await connector.assignPartnerId({
77
- shopDomain: "my-shop.myshopify.com",
78
- partnerId: "partner_123",
79
- });
123
+ ## Validation
80
124
 
81
- if (result.success) {
82
- // persist partnerId in your app (db/cookie) as needed
83
- }
84
- ```
125
+ The connector handles all validation internally:
126
+ - `trackInstall` normalizes partnerId (trims, checks format)
127
+ - `trackSubscriptionUpdated` validates price/period; skips if missing
128
+ - Apps do not need to validate before calling connector methods
85
129
 
86
130
  ## Optional signing helper
87
131
 
@@ -20,6 +20,25 @@ function safeJsonParse(text) {
20
20
  }
21
21
 
22
22
  // src/crossSell.ts
23
+ function appendUtmSource(url, utmSource) {
24
+ const source = utmSource?.trim();
25
+ if (!source) return url;
26
+ try {
27
+ const parsed = new URL(url);
28
+ if (!parsed.searchParams.has("utm_source")) {
29
+ parsed.searchParams.set("utm_source", source);
30
+ }
31
+ return parsed.toString();
32
+ } catch {
33
+ return url;
34
+ }
35
+ }
36
+ function withSourceTracking(apps, utmSource) {
37
+ return apps.map((app) => ({
38
+ ...app,
39
+ url: appendUtmSource(app.url, utmSource)
40
+ }));
41
+ }
23
42
  function getCrossSellOffers(options = {}) {
24
43
  const appsCatalog = options.appsCatalog ?? [];
25
44
  const installedKeys = new Set(
@@ -79,7 +98,7 @@ function buildFallbackCatalog(options) {
79
98
  if (limit > 0) {
80
99
  items = items.slice(0, limit);
81
100
  }
82
- return items;
101
+ return withSourceTracking(items, appName);
83
102
  }
84
103
  async function fetchAppsCatalog(options = {}) {
85
104
  const fetchImpl = options.fetch ?? globalThis.fetch;
@@ -105,7 +124,7 @@ async function fetchAppsCatalog(options = {}) {
105
124
  logger?.error?.("Failed to fetch apps catalog", { status: response.status });
106
125
  return buildFallbackCatalog(options);
107
126
  }
108
- return parsed;
127
+ return withSourceTracking(parsed, appName);
109
128
  } catch (error) {
110
129
  logger?.error?.("Failed to fetch apps catalog", {
111
130
  error: error instanceof Error ? error.message : String(error)
@@ -40,11 +40,9 @@ type CheckPartnerIdResult = {
40
40
  message?: string;
41
41
  status?: number;
42
42
  };
43
- type AssignPartnerIdInput = {
43
+ type AssignPartnerIdWithSubscriptionInput = {
44
44
  shopDomain: string;
45
45
  partnerId: string;
46
- };
47
- type AssignPartnerIdWithSubscriptionInput = AssignPartnerIdInput & {
48
46
  admin: ShopifyAdminGraphQLClient;
49
47
  };
50
48
  type SubscriptionEventData = {
@@ -85,4 +83,4 @@ declare function getCrossSellOffers(options?: CrossSellOptions): AppsCatalogEntr
85
83
  declare function fetchAppsCatalog(options?: CrossSellFetchOptions): Promise<AppsCatalogEntry[]>;
86
84
  declare function getCrossSellOffersFromApi(options?: CrossSellFetchOptions): Promise<AppsCatalogEntry[]>;
87
85
 
88
- export { type AssignPartnerIdInput as A, type ConnectorConfig as C, type Logger as L, type SubscriptionEventData as S, type TrackEventParams as T, type TrackResult as a, type AssignPartnerIdWithSubscriptionInput as b, type CheckPartnerIdResult as c, type ShopifyAdminGraphQLClient as d, getCrossSellOffersFromApi as e, fetchAppsCatalog as f, getCrossSellOffers as g, type AppsCatalogEntry as h, type CrossSellFetchOptions as i, type CrossSellOptions as j, type TrackEventName as k };
86
+ export { type AssignPartnerIdWithSubscriptionInput as A, type ConnectorConfig as C, type Logger as L, type SubscriptionEventData as S, type TrackEventParams as T, type TrackResult as a, type CheckPartnerIdResult as b, type ShopifyAdminGraphQLClient as c, getCrossSellOffersFromApi as d, type AppsCatalogEntry as e, fetchAppsCatalog as f, getCrossSellOffers as g, type CrossSellFetchOptions as h, type CrossSellOptions as i, type TrackEventName as j };
@@ -40,11 +40,9 @@ type CheckPartnerIdResult = {
40
40
  message?: string;
41
41
  status?: number;
42
42
  };
43
- type AssignPartnerIdInput = {
43
+ type AssignPartnerIdWithSubscriptionInput = {
44
44
  shopDomain: string;
45
45
  partnerId: string;
46
- };
47
- type AssignPartnerIdWithSubscriptionInput = AssignPartnerIdInput & {
48
46
  admin: ShopifyAdminGraphQLClient;
49
47
  };
50
48
  type SubscriptionEventData = {
@@ -85,4 +83,4 @@ declare function getCrossSellOffers(options?: CrossSellOptions): AppsCatalogEntr
85
83
  declare function fetchAppsCatalog(options?: CrossSellFetchOptions): Promise<AppsCatalogEntry[]>;
86
84
  declare function getCrossSellOffersFromApi(options?: CrossSellFetchOptions): Promise<AppsCatalogEntry[]>;
87
85
 
88
- export { type AssignPartnerIdInput as A, type ConnectorConfig as C, type Logger as L, type SubscriptionEventData as S, type TrackEventParams as T, type TrackResult as a, type AssignPartnerIdWithSubscriptionInput as b, type CheckPartnerIdResult as c, type ShopifyAdminGraphQLClient as d, getCrossSellOffersFromApi as e, fetchAppsCatalog as f, getCrossSellOffers as g, type AppsCatalogEntry as h, type CrossSellFetchOptions as i, type CrossSellOptions as j, type TrackEventName as k };
86
+ export { type AssignPartnerIdWithSubscriptionInput as A, type ConnectorConfig as C, type Logger as L, type SubscriptionEventData as S, type TrackEventParams as T, type TrackResult as a, type CheckPartnerIdResult as b, type ShopifyAdminGraphQLClient as c, getCrossSellOffersFromApi as d, type AppsCatalogEntry as e, fetchAppsCatalog as f, getCrossSellOffers as g, type CrossSellFetchOptions as h, type CrossSellOptions as i, type TrackEventName as j };
@@ -39,6 +39,25 @@ function safeJsonParse(text) {
39
39
  }
40
40
 
41
41
  // src/crossSell.ts
42
+ function appendUtmSource(url, utmSource) {
43
+ const source = utmSource?.trim();
44
+ if (!source) return url;
45
+ try {
46
+ const parsed = new URL(url);
47
+ if (!parsed.searchParams.has("utm_source")) {
48
+ parsed.searchParams.set("utm_source", source);
49
+ }
50
+ return parsed.toString();
51
+ } catch {
52
+ return url;
53
+ }
54
+ }
55
+ function withSourceTracking(apps, utmSource) {
56
+ return apps.map((app) => ({
57
+ ...app,
58
+ url: appendUtmSource(app.url, utmSource)
59
+ }));
60
+ }
42
61
  function getCrossSellOffers(options = {}) {
43
62
  const appsCatalog = options.appsCatalog ?? [];
44
63
  const installedKeys = new Set(
@@ -98,7 +117,7 @@ function buildFallbackCatalog(options) {
98
117
  if (limit > 0) {
99
118
  items = items.slice(0, limit);
100
119
  }
101
- return items;
120
+ return withSourceTracking(items, appName);
102
121
  }
103
122
  async function fetchAppsCatalog(options = {}) {
104
123
  const fetchImpl = options.fetch ?? globalThis.fetch;
@@ -124,7 +143,7 @@ async function fetchAppsCatalog(options = {}) {
124
143
  logger?.error?.("Failed to fetch apps catalog", { status: response.status });
125
144
  return buildFallbackCatalog(options);
126
145
  }
127
- return parsed;
146
+ return withSourceTracking(parsed, appName);
128
147
  } catch (error) {
129
148
  logger?.error?.("Failed to fetch apps catalog", {
130
149
  error: error instanceof Error ? error.message : String(error)
@@ -1 +1 @@
1
- export { h as AppsCatalogEntry, i as CrossSellFetchOptions, j as CrossSellOptions, f as fetchAppsCatalog, g as getCrossSellOffers, e as getCrossSellOffersFromApi } from './crossSell-BZZ9FX7S.cjs';
1
+ export { e as AppsCatalogEntry, h as CrossSellFetchOptions, i as CrossSellOptions, f as fetchAppsCatalog, g as getCrossSellOffers, d as getCrossSellOffersFromApi } from './crossSell-BdqPj2g7.cjs';
@@ -1 +1 @@
1
- export { h as AppsCatalogEntry, i as CrossSellFetchOptions, j as CrossSellOptions, f as fetchAppsCatalog, g as getCrossSellOffers, e as getCrossSellOffersFromApi } from './crossSell-BZZ9FX7S.js';
1
+ export { e as AppsCatalogEntry, h as CrossSellFetchOptions, i as CrossSellOptions, f as fetchAppsCatalog, g as getCrossSellOffers, d as getCrossSellOffersFromApi } from './crossSell-BdqPj2g7.js';
package/dist/crossSell.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  fetchAppsCatalog,
3
3
  getCrossSellOffers,
4
4
  getCrossSellOffersFromApi
5
- } from "./chunk-WZ5FAA44.js";
5
+ } from "./chunk-77N7IXZB.js";
6
6
  export {
7
7
  fetchAppsCatalog,
8
8
  getCrossSellOffers,
package/dist/index.cjs CHANGED
@@ -211,7 +211,6 @@ function createProgusConnector(config) {
211
211
  trackSubscriptionPurchased: fail,
212
212
  trackSubscriptionUpdated: fail,
213
213
  trackSubscriptionCancelled: fail,
214
- assignPartnerId: fail,
215
214
  assignPartnerIdWithSubscription: fail,
216
215
  checkPartnerId: async () => ({ success: false, message, status: 500 })
217
216
  };
@@ -306,23 +305,19 @@ function createProgusConnector(config) {
306
305
  externalId: String(normalized.subscriptionId)
307
306
  });
308
307
  }
309
- async function assignPartnerId(payload) {
310
- const normalized = normalizePartnerId(payload.partnerId);
308
+ async function assignPartnerIdWithSubscription(payload) {
309
+ const { admin, shopDomain, partnerId } = payload;
310
+ const normalized = normalizePartnerId(partnerId);
311
311
  if (!normalized) {
312
312
  return { success: false, message: "Partner ID is required" };
313
313
  }
314
- const result = await trackInstall({ shopDomain: payload.shopDomain, partnerId: normalized });
315
- return { ...result, partnerId: normalized };
316
- }
317
- async function assignPartnerIdWithSubscription(payload) {
318
- const { admin, ...rest } = payload;
319
- const result = await assignPartnerId(rest);
320
- if (!result.success) return result;
314
+ const result = await trackInstall({ shopDomain, partnerId: normalized });
315
+ if (!result.success) return { ...result, partnerId: normalized };
321
316
  try {
322
317
  const subscriptionPayload = await fetchActiveSubscriptionEventData(admin, logger);
323
318
  if (subscriptionPayload) {
324
319
  await trackSubscription({
325
- shopDomain: rest.shopDomain,
320
+ shopDomain,
326
321
  data: subscriptionPayload
327
322
  });
328
323
  }
@@ -331,7 +326,7 @@ function createProgusConnector(config) {
331
326
  error: error instanceof Error ? error.message : String(error)
332
327
  });
333
328
  }
334
- return result;
329
+ return { ...result, partnerId: normalized };
335
330
  }
336
331
  async function checkPartnerId(payload) {
337
332
  if (!payload.shopDomain) {
@@ -402,13 +397,31 @@ function createProgusConnector(config) {
402
397
  trackSubscriptionPurchased: trackSubscription,
403
398
  trackSubscriptionUpdated: trackSubscription,
404
399
  trackSubscriptionCancelled: trackSubscription,
405
- assignPartnerId,
406
400
  assignPartnerIdWithSubscription,
407
401
  checkPartnerId
408
402
  };
409
403
  }
410
404
 
411
405
  // src/crossSell.ts
406
+ function appendUtmSource(url, utmSource) {
407
+ const source = utmSource?.trim();
408
+ if (!source) return url;
409
+ try {
410
+ const parsed = new URL(url);
411
+ if (!parsed.searchParams.has("utm_source")) {
412
+ parsed.searchParams.set("utm_source", source);
413
+ }
414
+ return parsed.toString();
415
+ } catch {
416
+ return url;
417
+ }
418
+ }
419
+ function withSourceTracking(apps, utmSource) {
420
+ return apps.map((app) => ({
421
+ ...app,
422
+ url: appendUtmSource(app.url, utmSource)
423
+ }));
424
+ }
412
425
  function getCrossSellOffers(options = {}) {
413
426
  const appsCatalog = options.appsCatalog ?? [];
414
427
  const installedKeys = new Set(
@@ -468,7 +481,7 @@ function buildFallbackCatalog(options) {
468
481
  if (limit > 0) {
469
482
  items = items.slice(0, limit);
470
483
  }
471
- return items;
484
+ return withSourceTracking(items, appName);
472
485
  }
473
486
  async function fetchAppsCatalog(options = {}) {
474
487
  const fetchImpl = options.fetch ?? globalThis.fetch;
@@ -494,7 +507,7 @@ async function fetchAppsCatalog(options = {}) {
494
507
  logger?.error?.("Failed to fetch apps catalog", { status: response.status });
495
508
  return buildFallbackCatalog(options);
496
509
  }
497
- return parsed;
510
+ return withSourceTracking(parsed, appName);
498
511
  } catch (error) {
499
512
  logger?.error?.("Failed to fetch apps catalog", {
500
513
  error: error instanceof Error ? error.message : String(error)
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ConnectorConfig, T as TrackEventParams, a as TrackResult, S as SubscriptionEventData, A as AssignPartnerIdInput, b as AssignPartnerIdWithSubscriptionInput, c as CheckPartnerIdResult, d as ShopifyAdminGraphQLClient } from './crossSell-BZZ9FX7S.cjs';
2
- export { h as AppsCatalogEntry, i as CrossSellFetchOptions, j as CrossSellOptions, L as Logger, k as TrackEventName, f as fetchAppsCatalog, g as getCrossSellOffers, e as getCrossSellOffersFromApi } from './crossSell-BZZ9FX7S.cjs';
1
+ import { C as ConnectorConfig, T as TrackEventParams, a as TrackResult, S as SubscriptionEventData, A as AssignPartnerIdWithSubscriptionInput, b as CheckPartnerIdResult, c as ShopifyAdminGraphQLClient } from './crossSell-BdqPj2g7.cjs';
2
+ export { e as AppsCatalogEntry, h as CrossSellFetchOptions, i as CrossSellOptions, L as Logger, j as TrackEventName, f as fetchAppsCatalog, g as getCrossSellOffers, d as getCrossSellOffersFromApi } from './crossSell-BdqPj2g7.cjs';
3
3
 
4
4
  type Connector = {
5
5
  track: (eventName: TrackEventParams["eventName"], payload: Omit<TrackEventParams, "eventName">) => Promise<TrackResult>;
@@ -22,9 +22,6 @@ type Connector = {
22
22
  shopDomain: string;
23
23
  data: SubscriptionEventData;
24
24
  }) => Promise<TrackResult>;
25
- assignPartnerId: (payload: AssignPartnerIdInput) => Promise<TrackResult & {
26
- partnerId?: string;
27
- }>;
28
25
  assignPartnerIdWithSubscription: (payload: AssignPartnerIdWithSubscriptionInput) => Promise<TrackResult & {
29
26
  partnerId?: string;
30
27
  }>;
@@ -42,4 +39,4 @@ declare function signPayload(body: string, secret: string): string;
42
39
 
43
40
  declare function normalizePartnerId(value?: string | null): string | null;
44
41
 
45
- export { AssignPartnerIdInput, AssignPartnerIdWithSubscriptionInput, CheckPartnerIdResult, ConnectorConfig, ShopifyAdminGraphQLClient, SubscriptionEventData, TrackEventParams, TrackResult, createProgusConnector, fetchActiveSubscriptionEventData, normalizePartnerId, signPayload };
42
+ export { AssignPartnerIdWithSubscriptionInput, CheckPartnerIdResult, ConnectorConfig, ShopifyAdminGraphQLClient, SubscriptionEventData, TrackEventParams, TrackResult, createProgusConnector, fetchActiveSubscriptionEventData, normalizePartnerId, signPayload };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ConnectorConfig, T as TrackEventParams, a as TrackResult, S as SubscriptionEventData, A as AssignPartnerIdInput, b as AssignPartnerIdWithSubscriptionInput, c as CheckPartnerIdResult, d as ShopifyAdminGraphQLClient } from './crossSell-BZZ9FX7S.js';
2
- export { h as AppsCatalogEntry, i as CrossSellFetchOptions, j as CrossSellOptions, L as Logger, k as TrackEventName, f as fetchAppsCatalog, g as getCrossSellOffers, e as getCrossSellOffersFromApi } from './crossSell-BZZ9FX7S.js';
1
+ import { C as ConnectorConfig, T as TrackEventParams, a as TrackResult, S as SubscriptionEventData, A as AssignPartnerIdWithSubscriptionInput, b as CheckPartnerIdResult, c as ShopifyAdminGraphQLClient } from './crossSell-BdqPj2g7.js';
2
+ export { e as AppsCatalogEntry, h as CrossSellFetchOptions, i as CrossSellOptions, L as Logger, j as TrackEventName, f as fetchAppsCatalog, g as getCrossSellOffers, d as getCrossSellOffersFromApi } from './crossSell-BdqPj2g7.js';
3
3
 
4
4
  type Connector = {
5
5
  track: (eventName: TrackEventParams["eventName"], payload: Omit<TrackEventParams, "eventName">) => Promise<TrackResult>;
@@ -22,9 +22,6 @@ type Connector = {
22
22
  shopDomain: string;
23
23
  data: SubscriptionEventData;
24
24
  }) => Promise<TrackResult>;
25
- assignPartnerId: (payload: AssignPartnerIdInput) => Promise<TrackResult & {
26
- partnerId?: string;
27
- }>;
28
25
  assignPartnerIdWithSubscription: (payload: AssignPartnerIdWithSubscriptionInput) => Promise<TrackResult & {
29
26
  partnerId?: string;
30
27
  }>;
@@ -42,4 +39,4 @@ declare function signPayload(body: string, secret: string): string;
42
39
 
43
40
  declare function normalizePartnerId(value?: string | null): string | null;
44
41
 
45
- export { AssignPartnerIdInput, AssignPartnerIdWithSubscriptionInput, CheckPartnerIdResult, ConnectorConfig, ShopifyAdminGraphQLClient, SubscriptionEventData, TrackEventParams, TrackResult, createProgusConnector, fetchActiveSubscriptionEventData, normalizePartnerId, signPayload };
42
+ export { AssignPartnerIdWithSubscriptionInput, CheckPartnerIdResult, ConnectorConfig, ShopifyAdminGraphQLClient, SubscriptionEventData, TrackEventParams, TrackResult, createProgusConnector, fetchActiveSubscriptionEventData, normalizePartnerId, signPayload };
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  normalizePartnerId,
7
7
  safeJsonParse,
8
8
  stripTrailingSlash
9
- } from "./chunk-WZ5FAA44.js";
9
+ } from "./chunk-77N7IXZB.js";
10
10
 
11
11
  // src/subscription.ts
12
12
  var ACTIVE_SUBSCRIPTIONS_QUERY = `
@@ -168,7 +168,6 @@ function createProgusConnector(config) {
168
168
  trackSubscriptionPurchased: fail,
169
169
  trackSubscriptionUpdated: fail,
170
170
  trackSubscriptionCancelled: fail,
171
- assignPartnerId: fail,
172
171
  assignPartnerIdWithSubscription: fail,
173
172
  checkPartnerId: async () => ({ success: false, message, status: 500 })
174
173
  };
@@ -263,23 +262,19 @@ function createProgusConnector(config) {
263
262
  externalId: String(normalized.subscriptionId)
264
263
  });
265
264
  }
266
- async function assignPartnerId(payload) {
267
- const normalized = normalizePartnerId(payload.partnerId);
265
+ async function assignPartnerIdWithSubscription(payload) {
266
+ const { admin, shopDomain, partnerId } = payload;
267
+ const normalized = normalizePartnerId(partnerId);
268
268
  if (!normalized) {
269
269
  return { success: false, message: "Partner ID is required" };
270
270
  }
271
- const result = await trackInstall({ shopDomain: payload.shopDomain, partnerId: normalized });
272
- return { ...result, partnerId: normalized };
273
- }
274
- async function assignPartnerIdWithSubscription(payload) {
275
- const { admin, ...rest } = payload;
276
- const result = await assignPartnerId(rest);
277
- if (!result.success) return result;
271
+ const result = await trackInstall({ shopDomain, partnerId: normalized });
272
+ if (!result.success) return { ...result, partnerId: normalized };
278
273
  try {
279
274
  const subscriptionPayload = await fetchActiveSubscriptionEventData(admin, logger);
280
275
  if (subscriptionPayload) {
281
276
  await trackSubscription({
282
- shopDomain: rest.shopDomain,
277
+ shopDomain,
283
278
  data: subscriptionPayload
284
279
  });
285
280
  }
@@ -288,7 +283,7 @@ function createProgusConnector(config) {
288
283
  error: error instanceof Error ? error.message : String(error)
289
284
  });
290
285
  }
291
- return result;
286
+ return { ...result, partnerId: normalized };
292
287
  }
293
288
  async function checkPartnerId(payload) {
294
289
  if (!payload.shopDomain) {
@@ -359,7 +354,6 @@ function createProgusConnector(config) {
359
354
  trackSubscriptionPurchased: trackSubscription,
360
355
  trackSubscriptionUpdated: trackSubscription,
361
356
  trackSubscriptionCancelled: trackSubscription,
362
- assignPartnerId,
363
357
  assignPartnerIdWithSubscription,
364
358
  checkPartnerId
365
359
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@progus/connector",
3
- "version": "0.6.8",
3
+ "version": "0.7.1",
4
4
  "description": "Progus partner/affiliate connector helpers",
5
5
  "license": "MIT",
6
6
  "type": "module",