@progus/connector 0.5.5 → 0.6.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
@@ -91,9 +91,25 @@ import { signPayload } from "@progus/connector";
91
91
  const signature = signPayload(JSON.stringify({ test: true }), process.env.PARTNERS_SECRET_KEY!);
92
92
  ```
93
93
 
94
- ## UI components and cross-sell
94
+ ## Cross-sell recommendations (server-side)
95
95
 
96
- Use `@progus/connector-ui` for browser-safe helpers and UI components.
96
+ Use the connector to fetch and filter the Progus apps catalog on the backend,
97
+ then pass the list to your frontend UI.
98
+
99
+ ```ts
100
+ import { getCrossSellOffersFromApi } from "@progus/connector";
101
+
102
+ const recommendations = await getCrossSellOffersFromApi({
103
+ appName: "progus-store-locator",
104
+ limit: 3,
105
+ fetch, // pass your server-side fetch
106
+ });
107
+ ```
108
+
109
+ ## UI components
110
+
111
+ Use `@progus/connector-ui` for UI components. It re-exports cross-sell helpers
112
+ from `@progus/connector`.
97
113
 
98
114
  ## Environment variables
99
115
 
@@ -0,0 +1,129 @@
1
+ // src/utils.ts
2
+ function normalizePartnerId(value) {
3
+ if (!value) return null;
4
+ const trimmed = value.trim();
5
+ return trimmed.length > 0 ? trimmed : null;
6
+ }
7
+ function buildEventId(shopDomain, eventName, externalId) {
8
+ if (!externalId) return void 0;
9
+ return `${shopDomain}:${eventName}:${externalId}`;
10
+ }
11
+ function stripTrailingSlash(value) {
12
+ return value.replace(/\/+$/, "");
13
+ }
14
+ function safeJsonParse(text) {
15
+ try {
16
+ return JSON.parse(text);
17
+ } catch {
18
+ return null;
19
+ }
20
+ }
21
+
22
+ // src/crossSell.ts
23
+ function getCrossSellOffers(options = {}) {
24
+ const appsCatalog = options.appsCatalog ?? [];
25
+ const installedKeys = new Set(
26
+ [options.appName, ...options.installedAppKeys ?? []].filter(
27
+ (key) => Boolean(key)
28
+ )
29
+ );
30
+ const locale = options.locale;
31
+ return appsCatalog.filter((app) => app.enabled !== false).filter((app) => locale ? !app.locales || app.locales.includes(locale) : true).filter((app) => !installedKeys.has(app.key)).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
32
+ }
33
+ var DEFAULT_APPS_CATALOG_URL = "https://appsdata.progus.com/recommendations";
34
+ var FALLBACK_APPS_CATALOG = [
35
+ {
36
+ key: "progus_ai_studio",
37
+ type: "app",
38
+ title: "Progus AI Studio",
39
+ company: "Progus",
40
+ companyUrl: "https://progus.com",
41
+ desc: "Generate on-brand AI product & variant images in bulk.",
42
+ url: "https://apps.shopify.com/progus-ai-studio",
43
+ icon: "https://cdn.shopify.com/app-store/listing_images/9428a41ed53c66cd7329a2583cd2f3d9/icon/COje1rnS4pEDEAE=.png",
44
+ priority: 100,
45
+ enabled: true
46
+ },
47
+ {
48
+ key: "progus_trust_badges",
49
+ type: "app",
50
+ title: "Progus Trust Badges",
51
+ company: "Progus",
52
+ companyUrl: "https://progus.com",
53
+ desc: "Add Trust Badges to your store to build trust and credibility.",
54
+ url: "https://apps.shopify.com/progus-trust-badges-1",
55
+ icon: "https://cdn.shopify.com/app-store/listing_images/f9d0009e237f27d2db35b41ef99be858/icon/CJ3y1qDn1JEDEAE=.png",
56
+ priority: 80,
57
+ enabled: true
58
+ },
59
+ {
60
+ key: "progus_cod",
61
+ type: "app",
62
+ title: "Progus COD",
63
+ company: "Progus",
64
+ companyUrl: "https://progus.com",
65
+ desc: "Automate COD Fees & Hide/Show Cash on Delivery by Rules.",
66
+ url: "https://apps.shopify.com/progus-cod",
67
+ icon: "https://cdn.shopify.com/app-store/listing_images/bc537219cc3ed2bd4e7e3e683fe6b74a/icon/CMi_6dTEkIoDEAE=.png",
68
+ priority: 90,
69
+ enabled: true
70
+ }
71
+ ];
72
+ function buildFallbackCatalog(options) {
73
+ const appName = options.appName;
74
+ const limit = typeof options.limit === "number" ? options.limit : 3;
75
+ let items = FALLBACK_APPS_CATALOG.filter((app) => app.enabled !== false);
76
+ if (appName) {
77
+ items = items.filter((app) => app.key !== appName);
78
+ }
79
+ if (limit > 0) {
80
+ items = items.slice(0, limit);
81
+ }
82
+ return items;
83
+ }
84
+ async function fetchAppsCatalog(options = {}) {
85
+ const fetchImpl = options.fetch ?? globalThis.fetch;
86
+ const logger = options.logger ?? console;
87
+ const appName = options.appName;
88
+ const baseUrl = stripTrailingSlash(options.appsCatalogUrl ?? DEFAULT_APPS_CATALOG_URL);
89
+ const limit = typeof options.limit === "number" ? options.limit : 3;
90
+ const params = new URLSearchParams();
91
+ if (appName) params.set("appName", appName);
92
+ if (limit > 0) params.set("limit", String(limit));
93
+ const url = params.toString() ? `${baseUrl}?${params.toString()}` : baseUrl;
94
+ if (!fetchImpl) {
95
+ logger?.error?.("Failed to fetch apps catalog", {
96
+ error: "Fetch implementation is required"
97
+ });
98
+ return buildFallbackCatalog(options);
99
+ }
100
+ try {
101
+ const response = await fetchImpl(url);
102
+ const text = await response.text();
103
+ const parsed = safeJsonParse(text);
104
+ if (!response.ok || !parsed) {
105
+ logger?.error?.("Failed to fetch apps catalog", { status: response.status });
106
+ return buildFallbackCatalog(options);
107
+ }
108
+ return parsed;
109
+ } catch (error) {
110
+ logger?.error?.("Failed to fetch apps catalog", {
111
+ error: error instanceof Error ? error.message : String(error)
112
+ });
113
+ return buildFallbackCatalog(options);
114
+ }
115
+ }
116
+ async function getCrossSellOffersFromApi(options = {}) {
117
+ const appsCatalog = options.appsCatalog ?? await fetchAppsCatalog(options);
118
+ return getCrossSellOffers({ ...options, appsCatalog });
119
+ }
120
+
121
+ export {
122
+ normalizePartnerId,
123
+ buildEventId,
124
+ stripTrailingSlash,
125
+ safeJsonParse,
126
+ getCrossSellOffers,
127
+ fetchAppsCatalog,
128
+ getCrossSellOffersFromApi
129
+ };
@@ -0,0 +1,78 @@
1
+ type Logger = {
2
+ info?: (message: string, meta?: Record<string, unknown>) => void;
3
+ warn?: (message: string, meta?: Record<string, unknown>) => void;
4
+ error?: (message: string, meta?: Record<string, unknown>) => void;
5
+ };
6
+ type FetchLike = typeof fetch;
7
+ type ConnectorConfig = {
8
+ appKey: string;
9
+ apiBaseUrl: string;
10
+ apiKey?: string;
11
+ signingSecret?: string;
12
+ fetch?: FetchLike;
13
+ logger?: Logger;
14
+ enableIdempotency?: boolean;
15
+ };
16
+ type TrackEventName = "installation" | "uninstallation" | "subscription";
17
+ type TrackEventParams<TData = Record<string, unknown>> = {
18
+ eventName: TrackEventName | (string & {});
19
+ shopDomain: string;
20
+ partnerId?: string | null;
21
+ data?: TData;
22
+ externalId?: string;
23
+ };
24
+ type TrackResult<TData = Record<string, unknown>> = {
25
+ success: boolean;
26
+ message?: string;
27
+ status?: number;
28
+ data?: TData;
29
+ };
30
+ type CheckPartnerIdResult = {
31
+ success: boolean;
32
+ partnerId?: string;
33
+ message?: string;
34
+ status?: number;
35
+ };
36
+ type AssignPartnerIdInput = {
37
+ shopDomain: string;
38
+ partnerId: string;
39
+ };
40
+ type SubscriptionEventData = {
41
+ subscriptionStatus?: string;
42
+ subscriptionName?: string;
43
+ subscriptionId?: number | string;
44
+ subscriptionPrice?: number | string;
45
+ subscriptionPeriod?: string;
46
+ };
47
+ type AppsCatalogEntry = {
48
+ key: string;
49
+ type: string;
50
+ title: string;
51
+ company?: string;
52
+ companyUrl?: string;
53
+ desc?: string;
54
+ url: string;
55
+ icon?: string;
56
+ enabled?: boolean;
57
+ priority?: number;
58
+ locales?: string[];
59
+ };
60
+ type CrossSellOptions = {
61
+ appName?: string;
62
+ installedAppKeys?: string[];
63
+ locale?: string;
64
+ shopPlan?: string;
65
+ appsCatalog?: AppsCatalogEntry[];
66
+ };
67
+ type CrossSellFetchOptions = CrossSellOptions & {
68
+ appsCatalogUrl?: string;
69
+ limit?: number;
70
+ fetch?: FetchLike;
71
+ logger?: Logger;
72
+ };
73
+
74
+ declare function getCrossSellOffers(options?: CrossSellOptions): AppsCatalogEntry[];
75
+ declare function fetchAppsCatalog(options?: CrossSellFetchOptions): Promise<AppsCatalogEntry[]>;
76
+ declare function getCrossSellOffersFromApi(options?: CrossSellFetchOptions): Promise<AppsCatalogEntry[]>;
77
+
78
+ 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 CheckPartnerIdResult as b, getCrossSellOffersFromApi as c, type AppsCatalogEntry as d, type CrossSellFetchOptions as e, fetchAppsCatalog as f, getCrossSellOffers as g, type CrossSellOptions as h, type TrackEventName as i };
@@ -0,0 +1,78 @@
1
+ type Logger = {
2
+ info?: (message: string, meta?: Record<string, unknown>) => void;
3
+ warn?: (message: string, meta?: Record<string, unknown>) => void;
4
+ error?: (message: string, meta?: Record<string, unknown>) => void;
5
+ };
6
+ type FetchLike = typeof fetch;
7
+ type ConnectorConfig = {
8
+ appKey: string;
9
+ apiBaseUrl: string;
10
+ apiKey?: string;
11
+ signingSecret?: string;
12
+ fetch?: FetchLike;
13
+ logger?: Logger;
14
+ enableIdempotency?: boolean;
15
+ };
16
+ type TrackEventName = "installation" | "uninstallation" | "subscription";
17
+ type TrackEventParams<TData = Record<string, unknown>> = {
18
+ eventName: TrackEventName | (string & {});
19
+ shopDomain: string;
20
+ partnerId?: string | null;
21
+ data?: TData;
22
+ externalId?: string;
23
+ };
24
+ type TrackResult<TData = Record<string, unknown>> = {
25
+ success: boolean;
26
+ message?: string;
27
+ status?: number;
28
+ data?: TData;
29
+ };
30
+ type CheckPartnerIdResult = {
31
+ success: boolean;
32
+ partnerId?: string;
33
+ message?: string;
34
+ status?: number;
35
+ };
36
+ type AssignPartnerIdInput = {
37
+ shopDomain: string;
38
+ partnerId: string;
39
+ };
40
+ type SubscriptionEventData = {
41
+ subscriptionStatus?: string;
42
+ subscriptionName?: string;
43
+ subscriptionId?: number | string;
44
+ subscriptionPrice?: number | string;
45
+ subscriptionPeriod?: string;
46
+ };
47
+ type AppsCatalogEntry = {
48
+ key: string;
49
+ type: string;
50
+ title: string;
51
+ company?: string;
52
+ companyUrl?: string;
53
+ desc?: string;
54
+ url: string;
55
+ icon?: string;
56
+ enabled?: boolean;
57
+ priority?: number;
58
+ locales?: string[];
59
+ };
60
+ type CrossSellOptions = {
61
+ appName?: string;
62
+ installedAppKeys?: string[];
63
+ locale?: string;
64
+ shopPlan?: string;
65
+ appsCatalog?: AppsCatalogEntry[];
66
+ };
67
+ type CrossSellFetchOptions = CrossSellOptions & {
68
+ appsCatalogUrl?: string;
69
+ limit?: number;
70
+ fetch?: FetchLike;
71
+ logger?: Logger;
72
+ };
73
+
74
+ declare function getCrossSellOffers(options?: CrossSellOptions): AppsCatalogEntry[];
75
+ declare function fetchAppsCatalog(options?: CrossSellFetchOptions): Promise<AppsCatalogEntry[]>;
76
+ declare function getCrossSellOffersFromApi(options?: CrossSellFetchOptions): Promise<AppsCatalogEntry[]>;
77
+
78
+ 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 CheckPartnerIdResult as b, getCrossSellOffersFromApi as c, type AppsCatalogEntry as d, type CrossSellFetchOptions as e, fetchAppsCatalog as f, getCrossSellOffers as g, type CrossSellOptions as h, type TrackEventName as i };
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/crossSell.ts
21
+ var crossSell_exports = {};
22
+ __export(crossSell_exports, {
23
+ fetchAppsCatalog: () => fetchAppsCatalog,
24
+ getCrossSellOffers: () => getCrossSellOffers,
25
+ getCrossSellOffersFromApi: () => getCrossSellOffersFromApi
26
+ });
27
+ module.exports = __toCommonJS(crossSell_exports);
28
+
29
+ // src/utils.ts
30
+ function stripTrailingSlash(value) {
31
+ return value.replace(/\/+$/, "");
32
+ }
33
+ function safeJsonParse(text) {
34
+ try {
35
+ return JSON.parse(text);
36
+ } catch {
37
+ return null;
38
+ }
39
+ }
40
+
41
+ // src/crossSell.ts
42
+ function getCrossSellOffers(options = {}) {
43
+ const appsCatalog = options.appsCatalog ?? [];
44
+ const installedKeys = new Set(
45
+ [options.appName, ...options.installedAppKeys ?? []].filter(
46
+ (key) => Boolean(key)
47
+ )
48
+ );
49
+ const locale = options.locale;
50
+ return appsCatalog.filter((app) => app.enabled !== false).filter((app) => locale ? !app.locales || app.locales.includes(locale) : true).filter((app) => !installedKeys.has(app.key)).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
51
+ }
52
+ var DEFAULT_APPS_CATALOG_URL = "https://appsdata.progus.com/recommendations";
53
+ var FALLBACK_APPS_CATALOG = [
54
+ {
55
+ key: "progus_ai_studio",
56
+ type: "app",
57
+ title: "Progus AI Studio",
58
+ company: "Progus",
59
+ companyUrl: "https://progus.com",
60
+ desc: "Generate on-brand AI product & variant images in bulk.",
61
+ url: "https://apps.shopify.com/progus-ai-studio",
62
+ icon: "https://cdn.shopify.com/app-store/listing_images/9428a41ed53c66cd7329a2583cd2f3d9/icon/COje1rnS4pEDEAE=.png",
63
+ priority: 100,
64
+ enabled: true
65
+ },
66
+ {
67
+ key: "progus_trust_badges",
68
+ type: "app",
69
+ title: "Progus Trust Badges",
70
+ company: "Progus",
71
+ companyUrl: "https://progus.com",
72
+ desc: "Add Trust Badges to your store to build trust and credibility.",
73
+ url: "https://apps.shopify.com/progus-trust-badges-1",
74
+ icon: "https://cdn.shopify.com/app-store/listing_images/f9d0009e237f27d2db35b41ef99be858/icon/CJ3y1qDn1JEDEAE=.png",
75
+ priority: 80,
76
+ enabled: true
77
+ },
78
+ {
79
+ key: "progus_cod",
80
+ type: "app",
81
+ title: "Progus COD",
82
+ company: "Progus",
83
+ companyUrl: "https://progus.com",
84
+ desc: "Automate COD Fees & Hide/Show Cash on Delivery by Rules.",
85
+ url: "https://apps.shopify.com/progus-cod",
86
+ icon: "https://cdn.shopify.com/app-store/listing_images/bc537219cc3ed2bd4e7e3e683fe6b74a/icon/CMi_6dTEkIoDEAE=.png",
87
+ priority: 90,
88
+ enabled: true
89
+ }
90
+ ];
91
+ function buildFallbackCatalog(options) {
92
+ const appName = options.appName;
93
+ const limit = typeof options.limit === "number" ? options.limit : 3;
94
+ let items = FALLBACK_APPS_CATALOG.filter((app) => app.enabled !== false);
95
+ if (appName) {
96
+ items = items.filter((app) => app.key !== appName);
97
+ }
98
+ if (limit > 0) {
99
+ items = items.slice(0, limit);
100
+ }
101
+ return items;
102
+ }
103
+ async function fetchAppsCatalog(options = {}) {
104
+ const fetchImpl = options.fetch ?? globalThis.fetch;
105
+ const logger = options.logger ?? console;
106
+ const appName = options.appName;
107
+ const baseUrl = stripTrailingSlash(options.appsCatalogUrl ?? DEFAULT_APPS_CATALOG_URL);
108
+ const limit = typeof options.limit === "number" ? options.limit : 3;
109
+ const params = new URLSearchParams();
110
+ if (appName) params.set("appName", appName);
111
+ if (limit > 0) params.set("limit", String(limit));
112
+ const url = params.toString() ? `${baseUrl}?${params.toString()}` : baseUrl;
113
+ if (!fetchImpl) {
114
+ logger?.error?.("Failed to fetch apps catalog", {
115
+ error: "Fetch implementation is required"
116
+ });
117
+ return buildFallbackCatalog(options);
118
+ }
119
+ try {
120
+ const response = await fetchImpl(url);
121
+ const text = await response.text();
122
+ const parsed = safeJsonParse(text);
123
+ if (!response.ok || !parsed) {
124
+ logger?.error?.("Failed to fetch apps catalog", { status: response.status });
125
+ return buildFallbackCatalog(options);
126
+ }
127
+ return parsed;
128
+ } catch (error) {
129
+ logger?.error?.("Failed to fetch apps catalog", {
130
+ error: error instanceof Error ? error.message : String(error)
131
+ });
132
+ return buildFallbackCatalog(options);
133
+ }
134
+ }
135
+ async function getCrossSellOffersFromApi(options = {}) {
136
+ const appsCatalog = options.appsCatalog ?? await fetchAppsCatalog(options);
137
+ return getCrossSellOffers({ ...options, appsCatalog });
138
+ }
139
+ // Annotate the CommonJS export names for ESM import in node:
140
+ 0 && (module.exports = {
141
+ fetchAppsCatalog,
142
+ getCrossSellOffers,
143
+ getCrossSellOffersFromApi
144
+ });
@@ -0,0 +1 @@
1
+ export { f as fetchAppsCatalog, g as getCrossSellOffers, c as getCrossSellOffersFromApi } from './crossSell-BFz9e72n.cjs';
@@ -0,0 +1 @@
1
+ export { f as fetchAppsCatalog, g as getCrossSellOffers, c as getCrossSellOffersFromApi } from './crossSell-BFz9e72n.js';
@@ -0,0 +1,10 @@
1
+ import {
2
+ fetchAppsCatalog,
3
+ getCrossSellOffers,
4
+ getCrossSellOffersFromApi
5
+ } from "./chunk-WZ5FAA44.js";
6
+ export {
7
+ fetchAppsCatalog,
8
+ getCrossSellOffers,
9
+ getCrossSellOffersFromApi
10
+ };
package/dist/index.cjs CHANGED
@@ -21,6 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  createProgusConnector: () => createProgusConnector,
24
+ fetchAppsCatalog: () => fetchAppsCatalog,
25
+ getCrossSellOffers: () => getCrossSellOffers,
26
+ getCrossSellOffersFromApi: () => getCrossSellOffersFromApi,
24
27
  normalizePartnerId: () => normalizePartnerId,
25
28
  signPayload: () => signPayload
26
29
  });
@@ -61,7 +64,19 @@ function createProgusConnector(config) {
61
64
  const enableIdempotency = config.enableIdempotency !== false;
62
65
  const validSubscriptionPeriods = /* @__PURE__ */ new Set(["ANNUAL", "EVERY_30_DAYS"]);
63
66
  if (!fetchImpl) {
64
- throw new Error("Fetch implementation is required");
67
+ const message = "Fetch implementation is required";
68
+ logger?.error?.(message);
69
+ const fail = async () => ({ success: false, message });
70
+ return {
71
+ track: async () => ({ success: false, message }),
72
+ trackInstall: fail,
73
+ trackUninstall: fail,
74
+ trackSubscriptionPurchased: fail,
75
+ trackSubscriptionUpdated: fail,
76
+ trackSubscriptionCancelled: fail,
77
+ assignPartnerId: fail,
78
+ checkPartnerId: async () => ({ success: false, message, status: 500 })
79
+ };
65
80
  }
66
81
  async function postEvent(eventName, payload) {
67
82
  const { shopDomain, partnerId, data, externalId } = payload;
@@ -234,9 +249,111 @@ function createProgusConnector(config) {
234
249
  checkPartnerId
235
250
  };
236
251
  }
252
+
253
+ // src/crossSell.ts
254
+ function getCrossSellOffers(options = {}) {
255
+ const appsCatalog = options.appsCatalog ?? [];
256
+ const installedKeys = new Set(
257
+ [options.appName, ...options.installedAppKeys ?? []].filter(
258
+ (key) => Boolean(key)
259
+ )
260
+ );
261
+ const locale = options.locale;
262
+ return appsCatalog.filter((app) => app.enabled !== false).filter((app) => locale ? !app.locales || app.locales.includes(locale) : true).filter((app) => !installedKeys.has(app.key)).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
263
+ }
264
+ var DEFAULT_APPS_CATALOG_URL = "https://appsdata.progus.com/recommendations";
265
+ var FALLBACK_APPS_CATALOG = [
266
+ {
267
+ key: "progus_ai_studio",
268
+ type: "app",
269
+ title: "Progus AI Studio",
270
+ company: "Progus",
271
+ companyUrl: "https://progus.com",
272
+ desc: "Generate on-brand AI product & variant images in bulk.",
273
+ url: "https://apps.shopify.com/progus-ai-studio",
274
+ icon: "https://cdn.shopify.com/app-store/listing_images/9428a41ed53c66cd7329a2583cd2f3d9/icon/COje1rnS4pEDEAE=.png",
275
+ priority: 100,
276
+ enabled: true
277
+ },
278
+ {
279
+ key: "progus_trust_badges",
280
+ type: "app",
281
+ title: "Progus Trust Badges",
282
+ company: "Progus",
283
+ companyUrl: "https://progus.com",
284
+ desc: "Add Trust Badges to your store to build trust and credibility.",
285
+ url: "https://apps.shopify.com/progus-trust-badges-1",
286
+ icon: "https://cdn.shopify.com/app-store/listing_images/f9d0009e237f27d2db35b41ef99be858/icon/CJ3y1qDn1JEDEAE=.png",
287
+ priority: 80,
288
+ enabled: true
289
+ },
290
+ {
291
+ key: "progus_cod",
292
+ type: "app",
293
+ title: "Progus COD",
294
+ company: "Progus",
295
+ companyUrl: "https://progus.com",
296
+ desc: "Automate COD Fees & Hide/Show Cash on Delivery by Rules.",
297
+ url: "https://apps.shopify.com/progus-cod",
298
+ icon: "https://cdn.shopify.com/app-store/listing_images/bc537219cc3ed2bd4e7e3e683fe6b74a/icon/CMi_6dTEkIoDEAE=.png",
299
+ priority: 90,
300
+ enabled: true
301
+ }
302
+ ];
303
+ function buildFallbackCatalog(options) {
304
+ const appName = options.appName;
305
+ const limit = typeof options.limit === "number" ? options.limit : 3;
306
+ let items = FALLBACK_APPS_CATALOG.filter((app) => app.enabled !== false);
307
+ if (appName) {
308
+ items = items.filter((app) => app.key !== appName);
309
+ }
310
+ if (limit > 0) {
311
+ items = items.slice(0, limit);
312
+ }
313
+ return items;
314
+ }
315
+ async function fetchAppsCatalog(options = {}) {
316
+ const fetchImpl = options.fetch ?? globalThis.fetch;
317
+ const logger = options.logger ?? console;
318
+ const appName = options.appName;
319
+ const baseUrl = stripTrailingSlash(options.appsCatalogUrl ?? DEFAULT_APPS_CATALOG_URL);
320
+ const limit = typeof options.limit === "number" ? options.limit : 3;
321
+ const params = new URLSearchParams();
322
+ if (appName) params.set("appName", appName);
323
+ if (limit > 0) params.set("limit", String(limit));
324
+ const url = params.toString() ? `${baseUrl}?${params.toString()}` : baseUrl;
325
+ if (!fetchImpl) {
326
+ logger?.error?.("Failed to fetch apps catalog", {
327
+ error: "Fetch implementation is required"
328
+ });
329
+ return buildFallbackCatalog(options);
330
+ }
331
+ try {
332
+ const response = await fetchImpl(url);
333
+ const text = await response.text();
334
+ const parsed = safeJsonParse(text);
335
+ if (!response.ok || !parsed) {
336
+ logger?.error?.("Failed to fetch apps catalog", { status: response.status });
337
+ return buildFallbackCatalog(options);
338
+ }
339
+ return parsed;
340
+ } catch (error) {
341
+ logger?.error?.("Failed to fetch apps catalog", {
342
+ error: error instanceof Error ? error.message : String(error)
343
+ });
344
+ return buildFallbackCatalog(options);
345
+ }
346
+ }
347
+ async function getCrossSellOffersFromApi(options = {}) {
348
+ const appsCatalog = options.appsCatalog ?? await fetchAppsCatalog(options);
349
+ return getCrossSellOffers({ ...options, appsCatalog });
350
+ }
237
351
  // Annotate the CommonJS export names for ESM import in node:
238
352
  0 && (module.exports = {
239
353
  createProgusConnector,
354
+ fetchAppsCatalog,
355
+ getCrossSellOffers,
356
+ getCrossSellOffersFromApi,
240
357
  normalizePartnerId,
241
358
  signPayload
242
359
  });
package/dist/index.d.cts CHANGED
@@ -1,49 +1,5 @@
1
- type Logger = {
2
- info?: (message: string, meta?: Record<string, unknown>) => void;
3
- warn?: (message: string, meta?: Record<string, unknown>) => void;
4
- error?: (message: string, meta?: Record<string, unknown>) => void;
5
- };
6
- type FetchLike = typeof fetch;
7
- type ConnectorConfig = {
8
- appKey: string;
9
- apiBaseUrl: string;
10
- apiKey?: string;
11
- signingSecret?: string;
12
- fetch?: FetchLike;
13
- logger?: Logger;
14
- enableIdempotency?: boolean;
15
- };
16
- type TrackEventName = "installation" | "uninstallation" | "subscription";
17
- type TrackEventParams<TData = Record<string, unknown>> = {
18
- eventName: TrackEventName | (string & {});
19
- shopDomain: string;
20
- partnerId?: string | null;
21
- data?: TData;
22
- externalId?: string;
23
- };
24
- type TrackResult<TData = Record<string, unknown>> = {
25
- success: boolean;
26
- message?: string;
27
- status?: number;
28
- data?: TData;
29
- };
30
- type CheckPartnerIdResult = {
31
- success: boolean;
32
- partnerId?: string;
33
- message?: string;
34
- status?: number;
35
- };
36
- type AssignPartnerIdInput = {
37
- shopDomain: string;
38
- partnerId: string;
39
- };
40
- type SubscriptionEventData = {
41
- subscriptionStatus?: string;
42
- subscriptionName?: string;
43
- subscriptionId?: number | string;
44
- subscriptionPrice?: number | string;
45
- subscriptionPeriod?: string;
46
- };
1
+ import { C as ConnectorConfig, T as TrackEventParams, a as TrackResult, S as SubscriptionEventData, A as AssignPartnerIdInput, b as CheckPartnerIdResult } from './crossSell-BFz9e72n.cjs';
2
+ export { d as AppsCatalogEntry, e as CrossSellFetchOptions, h as CrossSellOptions, L as Logger, i as TrackEventName, f as fetchAppsCatalog, g as getCrossSellOffers, c as getCrossSellOffersFromApi } from './crossSell-BFz9e72n.cjs';
47
3
 
48
4
  type Connector = {
49
5
  track: (eventName: TrackEventParams["eventName"], payload: Omit<TrackEventParams, "eventName">) => Promise<TrackResult>;
@@ -79,4 +35,4 @@ declare function signPayload(body: string, secret: string): string;
79
35
 
80
36
  declare function normalizePartnerId(value?: string | null): string | null;
81
37
 
82
- export { type AssignPartnerIdInput, type CheckPartnerIdResult, type ConnectorConfig, type Logger, type SubscriptionEventData, type TrackEventName, type TrackEventParams, type TrackResult, createProgusConnector, normalizePartnerId, signPayload };
38
+ export { AssignPartnerIdInput, CheckPartnerIdResult, ConnectorConfig, SubscriptionEventData, TrackEventParams, TrackResult, createProgusConnector, normalizePartnerId, signPayload };
package/dist/index.d.ts CHANGED
@@ -1,49 +1,5 @@
1
- type Logger = {
2
- info?: (message: string, meta?: Record<string, unknown>) => void;
3
- warn?: (message: string, meta?: Record<string, unknown>) => void;
4
- error?: (message: string, meta?: Record<string, unknown>) => void;
5
- };
6
- type FetchLike = typeof fetch;
7
- type ConnectorConfig = {
8
- appKey: string;
9
- apiBaseUrl: string;
10
- apiKey?: string;
11
- signingSecret?: string;
12
- fetch?: FetchLike;
13
- logger?: Logger;
14
- enableIdempotency?: boolean;
15
- };
16
- type TrackEventName = "installation" | "uninstallation" | "subscription";
17
- type TrackEventParams<TData = Record<string, unknown>> = {
18
- eventName: TrackEventName | (string & {});
19
- shopDomain: string;
20
- partnerId?: string | null;
21
- data?: TData;
22
- externalId?: string;
23
- };
24
- type TrackResult<TData = Record<string, unknown>> = {
25
- success: boolean;
26
- message?: string;
27
- status?: number;
28
- data?: TData;
29
- };
30
- type CheckPartnerIdResult = {
31
- success: boolean;
32
- partnerId?: string;
33
- message?: string;
34
- status?: number;
35
- };
36
- type AssignPartnerIdInput = {
37
- shopDomain: string;
38
- partnerId: string;
39
- };
40
- type SubscriptionEventData = {
41
- subscriptionStatus?: string;
42
- subscriptionName?: string;
43
- subscriptionId?: number | string;
44
- subscriptionPrice?: number | string;
45
- subscriptionPeriod?: string;
46
- };
1
+ import { C as ConnectorConfig, T as TrackEventParams, a as TrackResult, S as SubscriptionEventData, A as AssignPartnerIdInput, b as CheckPartnerIdResult } from './crossSell-BFz9e72n.js';
2
+ export { d as AppsCatalogEntry, e as CrossSellFetchOptions, h as CrossSellOptions, L as Logger, i as TrackEventName, f as fetchAppsCatalog, g as getCrossSellOffers, c as getCrossSellOffersFromApi } from './crossSell-BFz9e72n.js';
47
3
 
48
4
  type Connector = {
49
5
  track: (eventName: TrackEventParams["eventName"], payload: Omit<TrackEventParams, "eventName">) => Promise<TrackResult>;
@@ -79,4 +35,4 @@ declare function signPayload(body: string, secret: string): string;
79
35
 
80
36
  declare function normalizePartnerId(value?: string | null): string | null;
81
37
 
82
- export { type AssignPartnerIdInput, type CheckPartnerIdResult, type ConnectorConfig, type Logger, type SubscriptionEventData, type TrackEventName, type TrackEventParams, type TrackResult, createProgusConnector, normalizePartnerId, signPayload };
38
+ export { AssignPartnerIdInput, CheckPartnerIdResult, ConnectorConfig, SubscriptionEventData, TrackEventParams, TrackResult, createProgusConnector, normalizePartnerId, signPayload };
package/dist/index.js CHANGED
@@ -1,30 +1,19 @@
1
+ import {
2
+ buildEventId,
3
+ fetchAppsCatalog,
4
+ getCrossSellOffers,
5
+ getCrossSellOffersFromApi,
6
+ normalizePartnerId,
7
+ safeJsonParse,
8
+ stripTrailingSlash
9
+ } from "./chunk-WZ5FAA44.js";
10
+
1
11
  // src/signing.ts
2
12
  import { createHmac } from "crypto";
3
13
  function signPayload(body, secret) {
4
14
  return createHmac("sha256", secret).update(body).digest("hex");
5
15
  }
6
16
 
7
- // src/utils.ts
8
- function normalizePartnerId(value) {
9
- if (!value) return null;
10
- const trimmed = value.trim();
11
- return trimmed.length > 0 ? trimmed : null;
12
- }
13
- function buildEventId(shopDomain, eventName, externalId) {
14
- if (!externalId) return void 0;
15
- return `${shopDomain}:${eventName}:${externalId}`;
16
- }
17
- function stripTrailingSlash(value) {
18
- return value.replace(/\/+$/, "");
19
- }
20
- function safeJsonParse(text) {
21
- try {
22
- return JSON.parse(text);
23
- } catch {
24
- return null;
25
- }
26
- }
27
-
28
17
  // src/connector.ts
29
18
  function createProgusConnector(config) {
30
19
  const apiBaseUrl = config.apiBaseUrl ? stripTrailingSlash(config.apiBaseUrl) : "";
@@ -33,7 +22,19 @@ function createProgusConnector(config) {
33
22
  const enableIdempotency = config.enableIdempotency !== false;
34
23
  const validSubscriptionPeriods = /* @__PURE__ */ new Set(["ANNUAL", "EVERY_30_DAYS"]);
35
24
  if (!fetchImpl) {
36
- throw new Error("Fetch implementation is required");
25
+ const message = "Fetch implementation is required";
26
+ logger?.error?.(message);
27
+ const fail = async () => ({ success: false, message });
28
+ return {
29
+ track: async () => ({ success: false, message }),
30
+ trackInstall: fail,
31
+ trackUninstall: fail,
32
+ trackSubscriptionPurchased: fail,
33
+ trackSubscriptionUpdated: fail,
34
+ trackSubscriptionCancelled: fail,
35
+ assignPartnerId: fail,
36
+ checkPartnerId: async () => ({ success: false, message, status: 500 })
37
+ };
37
38
  }
38
39
  async function postEvent(eventName, payload) {
39
40
  const { shopDomain, partnerId, data, externalId } = payload;
@@ -208,6 +209,9 @@ function createProgusConnector(config) {
208
209
  }
209
210
  export {
210
211
  createProgusConnector,
212
+ fetchAppsCatalog,
213
+ getCrossSellOffers,
214
+ getCrossSellOffersFromApi,
211
215
  normalizePartnerId,
212
216
  signPayload
213
217
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@progus/connector",
3
- "version": "0.5.5",
3
+ "version": "0.6.1",
4
4
  "description": "Progus partner/affiliate connector helpers",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -12,6 +12,11 @@
12
12
  "types": "./dist/index.d.ts",
13
13
  "import": "./dist/index.js",
14
14
  "require": "./dist/index.cjs"
15
+ },
16
+ "./crossSell": {
17
+ "types": "./dist/crossSell.d.ts",
18
+ "import": "./dist/crossSell.js",
19
+ "require": "./dist/crossSell.cjs"
15
20
  }
16
21
  },
17
22
  "files": [
@@ -26,8 +31,8 @@
26
31
  "access": "public"
27
32
  },
28
33
  "scripts": {
29
- "build": "tsup src/index.ts --format esm,cjs --dts --clean --target node18",
30
- "dev": "tsup src/index.ts --format esm,cjs --dts --watch --target node18",
34
+ "build": "tsup src/index.ts src/crossSell.ts --format esm,cjs --dts --clean --target node18",
35
+ "dev": "tsup src/index.ts src/crossSell.ts --format esm,cjs --dts --watch --target node18",
31
36
  "smoke": "tsx scripts/smoke.ts"
32
37
  },
33
38
  "devDependencies": {