@funnelsgrove/runtime 0.7.16 → 0.7.19

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.
@@ -37,6 +37,7 @@ function ActiveFunnelRuntimeConfigBoundary({ funnelId, funnelVersionId, children
37
37
  const refresh = () => loadFunnelRuntimeConfig(funnelId, { versionId: funnelVersionId })
38
38
  .then((published) => resolvePublishedFunnelRuntimeConfig(published, {
39
39
  expectedFunnelVersionId: funnelVersionId,
40
+ hostname: window.location.hostname,
40
41
  }))
41
42
  .then((config) => {
42
43
  if (!active)
@@ -19,7 +19,6 @@ export type GeneratedOfferSetPlanModeConfig = {
19
19
  export type GeneratedOfferSetPlanItem = {
20
20
  readonly funnelPlanKey: string;
21
21
  readonly runtimePlanKey?: string | null;
22
- readonly projectBillingPlanId?: string | null;
23
22
  readonly testProvider?: 'stripe' | 'solidgate' | null;
24
23
  readonly liveProvider?: 'stripe' | 'solidgate' | null;
25
24
  readonly testProviderPlanId?: string | null;
@@ -81,7 +80,7 @@ export type OfferSetRuntimeDiscount = {
81
80
  export type OfferSetRuntimePlanOverrides = {
82
81
  offerSetId?: string;
83
82
  offerSetKey?: string;
84
- projectPlanId?: string;
83
+ funnelPlanKey?: string;
85
84
  providerPlanId?: string;
86
85
  paymentMode?: 'one_time';
87
86
  analyticsPurchaseValue?: number;
@@ -155,12 +155,11 @@ const readGeneratedPlanNumberValue = (item, mode, itemKeys, metadataKeys = itemK
155
155
  return ((_c = (_b = (_a = readFiniteNumberField(modeConfig, metadataKeys)) !== null && _a !== void 0 ? _a : readFiniteNumberField(fallbackModeConfig, metadataKeys)) !== null && _b !== void 0 ? _b : itemValue) !== null && _c !== void 0 ? _c : readFiniteNumberField(metadata, metadataKeys));
156
156
  };
157
157
  const buildGeneratedPlanOverrides = (item, mode, isDefault) => {
158
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
158
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
159
159
  const metadata = readOfferItemMetadata(item);
160
160
  const providerPlanId = readProviderPlanId(item, mode);
161
161
  const followUpProviderPlanId = readFollowUpProviderPlanId(item, mode);
162
- const projectPlanId = (_a = readString(item.projectBillingPlanId)) !== null && _a !== void 0 ? _a : readStringField(metadata, ['projectBillingPlanId', 'projectPlanId', 'project_billing_plan_id']);
163
- const title = (_c = (_b = readString(item.title)) !== null && _b !== void 0 ? _b : readString(item.displayNameOverride)) !== null && _c !== void 0 ? _c : readStringField(metadata, ['title', 'displayName', 'publicPlanName', 'public_plan_name']);
162
+ const title = (_b = (_a = readString(item.title)) !== null && _a !== void 0 ? _a : readString(item.displayNameOverride)) !== null && _b !== void 0 ? _b : readStringField(metadata, ['title', 'displayName', 'publicPlanName', 'public_plan_name']);
164
163
  const description = readGeneratedPlanStringValue(item, mode, ['description']);
165
164
  const priceDisplayFallbackMode = mode === 'live' ? 'test' : undefined;
166
165
  const readPriceString = (key) => (readGeneratedPlanStringValue(item, mode, [key], [String(key)], priceDisplayFallbackMode));
@@ -171,17 +170,17 @@ const buildGeneratedPlanOverrides = (item, mode, isDefault) => {
171
170
  const checkoutSummaryLabel = readPriceString('checkoutSummaryLabel');
172
171
  const billingInterval = readPriceString('billingInterval');
173
172
  const billingIntervalCount = readPriceNumber('billingIntervalCount');
174
- const followUpPlanTitle = (_e = (_d = readString(item.followUpPlanTitle)) !== null && _d !== void 0 ? _d : readString(item.followUpTitle)) !== null && _e !== void 0 ? _e : readStringField(metadata, ['followUpPlanTitle', 'followUpTitle', 'follow_up_plan_title']);
173
+ const followUpPlanTitle = (_d = (_c = readString(item.followUpPlanTitle)) !== null && _c !== void 0 ? _c : readString(item.followUpTitle)) !== null && _d !== void 0 ? _d : readStringField(metadata, ['followUpPlanTitle', 'followUpTitle', 'follow_up_plan_title']);
175
174
  const followUpBillingInterval = readGeneratedPlanStringValue(item, mode, ['followUpBillingInterval'], ['followUpBillingInterval', 'follow_up_billing_interval']);
176
175
  const followUpBillingIntervalCount = readGeneratedPlanNumberValue(item, mode, ['followUpBillingIntervalCount'], ['followUpBillingIntervalCount', 'follow_up_billing_interval_count']);
177
176
  const introIterations = readGeneratedPlanNumberValue(item, mode, ['introIterations'], ['introIterations', 'intro_iterations']);
178
177
  const amountCents = readPriceNumber('amountCents');
179
178
  const modeConfig = readGeneratedModeConfig(item, mode);
180
- const paymentMode = (_m = (_l = (_k = (_j = (_h = (_g = (_f = readOneTimePaymentMode(modeConfig.paymentMode)) !== null && _f !== void 0 ? _f : readOneTimePaymentMode(modeConfig.payment_mode)) !== null && _g !== void 0 ? _g : readOneTimePaymentMode(modeConfig.checkoutMode)) !== null && _h !== void 0 ? _h : readOneTimePaymentMode(modeConfig.checkout_mode)) !== null && _j !== void 0 ? _j : readOneTimePaymentMode(metadata.paymentMode)) !== null && _k !== void 0 ? _k : readOneTimePaymentMode(metadata.payment_mode)) !== null && _l !== void 0 ? _l : readOneTimePaymentMode(metadata.checkoutMode)) !== null && _m !== void 0 ? _m : readOneTimePaymentMode(metadata.checkout_mode);
181
- const analyticsPurchaseValue = (_o = readFiniteNumber(item.analyticsPurchaseValue)) !== null && _o !== void 0 ? _o : readFiniteNumberField(metadata, ['analyticsPurchaseValue']);
182
- const featuredTag = (_p = readString(item.featuredTag)) !== null && _p !== void 0 ? _p : readStringField(metadata, ['featuredTag']);
183
- const oldPriceLabel = (_q = readString(item.oldPriceLabel)) !== null && _q !== void 0 ? _q : readStringField(metadata, ['oldPriceLabel']);
184
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (projectPlanId ? { projectPlanId } : {})), (providerPlanId ? { providerPlanId } : {})), (paymentMode ? { paymentMode } : {})), (analyticsPurchaseValue !== null ? { analyticsPurchaseValue } : {})), (title ? { title } : {})), (description ? { description } : {})), (priceLabel ? { priceLabel } : {})), (perDayAmount ? { perDayAmount } : {})), (perDayLabel ? { perDayLabel } : {})), (amountCents !== null ? { amountCents: Math.max(0, Math.round(amountCents)) } : {})), (checkoutSummaryLabel ? { checkoutSummaryLabel } : {})), (billingInterval ? { billingInterval } : {})), (billingIntervalCount !== null ? { billingIntervalCount: Math.max(1, Math.round(billingIntervalCount)) } : {})), (followUpProviderPlanId ? { followUpProviderPlanId } : {})), (followUpPlanTitle ? { followUpPlanTitle } : {})), (followUpBillingInterval ? { followUpBillingInterval } : {})), (followUpBillingIntervalCount !== null ? { followUpBillingIntervalCount: Math.max(1, Math.round(followUpBillingIntervalCount)) } : {})), (introIterations !== null ? { introIterations: Math.max(1, Math.round(introIterations)) } : {})), (featuredTag ? { featuredTag } : {})), (oldPriceLabel ? { oldPriceLabel } : {})), (isDefault ? { isDefault: true } : {}));
179
+ const paymentMode = (_l = (_k = (_j = (_h = (_g = (_f = (_e = readOneTimePaymentMode(modeConfig.paymentMode)) !== null && _e !== void 0 ? _e : readOneTimePaymentMode(modeConfig.payment_mode)) !== null && _f !== void 0 ? _f : readOneTimePaymentMode(modeConfig.checkoutMode)) !== null && _g !== void 0 ? _g : readOneTimePaymentMode(modeConfig.checkout_mode)) !== null && _h !== void 0 ? _h : readOneTimePaymentMode(metadata.paymentMode)) !== null && _j !== void 0 ? _j : readOneTimePaymentMode(metadata.payment_mode)) !== null && _k !== void 0 ? _k : readOneTimePaymentMode(metadata.checkoutMode)) !== null && _l !== void 0 ? _l : readOneTimePaymentMode(metadata.checkout_mode);
180
+ const analyticsPurchaseValue = (_m = readFiniteNumber(item.analyticsPurchaseValue)) !== null && _m !== void 0 ? _m : readFiniteNumberField(metadata, ['analyticsPurchaseValue']);
181
+ const featuredTag = (_o = readString(item.featuredTag)) !== null && _o !== void 0 ? _o : readStringField(metadata, ['featuredTag']);
182
+ const oldPriceLabel = (_p = readString(item.oldPriceLabel)) !== null && _p !== void 0 ? _p : readStringField(metadata, ['oldPriceLabel']);
183
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ funnelPlanKey: item.funnelPlanKey }, (providerPlanId ? { providerPlanId } : {})), (paymentMode ? { paymentMode } : {})), (analyticsPurchaseValue !== null ? { analyticsPurchaseValue } : {})), (title ? { title } : {})), (description ? { description } : {})), (priceLabel ? { priceLabel } : {})), (perDayAmount ? { perDayAmount } : {})), (perDayLabel ? { perDayLabel } : {})), (amountCents !== null ? { amountCents: Math.max(0, Math.round(amountCents)) } : {})), (checkoutSummaryLabel ? { checkoutSummaryLabel } : {})), (billingInterval ? { billingInterval } : {})), (billingIntervalCount !== null ? { billingIntervalCount: Math.max(1, Math.round(billingIntervalCount)) } : {})), (followUpProviderPlanId ? { followUpProviderPlanId } : {})), (followUpPlanTitle ? { followUpPlanTitle } : {})), (followUpBillingInterval ? { followUpBillingInterval } : {})), (followUpBillingIntervalCount !== null ? { followUpBillingIntervalCount: Math.max(1, Math.round(followUpBillingIntervalCount)) } : {})), (introIterations !== null ? { introIterations: Math.max(1, Math.round(introIterations)) } : {})), (featuredTag ? { featuredTag } : {})), (oldPriceLabel ? { oldPriceLabel } : {})), (isDefault ? { isDefault: true } : {}));
185
184
  };
186
185
  export const applyGeneratedOfferSetToPlanCatalog = (baseCatalog, mode, offerSet) => {
187
186
  var _a, _b, _c, _d;
@@ -204,7 +203,9 @@ export const applyGeneratedOfferSetToPlanCatalog = (baseCatalog, mode, offerSet)
204
203
  if (!key) {
205
204
  continue;
206
205
  }
207
- nextCatalog[key] = Object.assign(Object.assign(Object.assign(Object.assign({}, ((_c = nextCatalog[key]) !== null && _c !== void 0 ? _c : {})), (((_d = offerSet.id) === null || _d === void 0 ? void 0 : _d.trim()) ? { offerSetId: offerSet.id.trim() } : {})), { offerSetKey: offerSet.key }), buildGeneratedPlanOverrides(item, mode, getOfferSetItemKind(item) === 'plan' && key === defaultPlanKey));
206
+ const basePlan = Object.assign({}, ((_c = nextCatalog[key]) !== null && _c !== void 0 ? _c : {}));
207
+ delete basePlan.projectPlanId;
208
+ nextCatalog[key] = Object.assign(Object.assign(Object.assign(Object.assign({}, basePlan), (((_d = offerSet.id) === null || _d === void 0 ? void 0 : _d.trim()) ? { offerSetId: offerSet.id.trim() } : {})), { offerSetKey: offerSet.key }), buildGeneratedPlanOverrides(item, mode, getOfferSetItemKind(item) === 'plan' && key === defaultPlanKey));
208
209
  }
209
210
  return nextCatalog;
210
211
  };
@@ -9,6 +9,7 @@ export type FunnelRuntimeConfig = {
9
9
  sampleRate?: unknown;
10
10
  };
11
11
  defaultOfferSetId?: string | null;
12
+ defaultOfferSetIdByDomain?: Record<string, unknown>;
12
13
  offerSets: unknown[];
13
14
  experiments: unknown[];
14
15
  };
@@ -37,6 +38,7 @@ export type PublishedFunnelRuntimeConfig = {
37
38
  type RuntimeConfigFetcher = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
38
39
  export declare const resolvePublishedFunnelRuntimeConfig: (published: PublishedFunnelRuntimeConfig, options?: {
39
40
  expectedFunnelVersionId?: string;
41
+ hostname?: string;
40
42
  }) => ResolvedFunnelRuntimeConfig;
41
43
  export declare const loadFunnelRuntimeConfig: (funnelId: string, options?: {
42
44
  fetcher?: RuntimeConfigFetcher;
@@ -112,7 +112,6 @@ const normalizePublishedOfferSets = (config) => {
112
112
  if (!funnelPlanKey) {
113
113
  throw new Error(`Published runtime offer set "${key}" has an item without a plan key`);
114
114
  }
115
- const projectBillingPlanId = pickString(item, 'projectBillingPlanId', 'project_billing_plan_id');
116
115
  const testProvider = parsePaymentProvider(pick(item, 'testProvider', 'test_provider'), `Published runtime offer set "${key}"`);
117
116
  const liveProvider = parsePaymentProvider(pick(item, 'liveProvider', 'live_provider'), `Published runtime offer set "${key}"`);
118
117
  const testMapping = buildPlanModeConfig(item, 'test');
@@ -121,9 +120,9 @@ const normalizePublishedOfferSets = (config) => {
121
120
  || pickString(metadata, 'title', 'publicPlanName', 'public_plan_name');
122
121
  const description = pickString(item, 'description')
123
122
  || pickString(metadata, 'description');
124
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ funnelPlanKey }, (pickString(metadata, 'runtimePlanKey', 'planKey', 'billingPlanKey')
123
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ funnelPlanKey }, (pickString(metadata, 'runtimePlanKey', 'planKey', 'billingPlanKey')
125
124
  ? { runtimePlanKey: pickString(metadata, 'runtimePlanKey', 'planKey', 'billingPlanKey') }
126
- : {})), (projectBillingPlanId ? { projectBillingPlanId } : {})), (testProvider ? { testProvider } : {})), (liveProvider ? { liveProvider } : {})), (pickString(item, 'testProviderPlanId', 'test_provider_plan_id')
125
+ : {})), (testProvider ? { testProvider } : {})), (liveProvider ? { liveProvider } : {})), (pickString(item, 'testProviderPlanId', 'test_provider_plan_id')
127
126
  ? { testProviderPlanId: pickString(item, 'testProviderPlanId', 'test_provider_plan_id') }
128
127
  : {})), (pickString(item, 'liveProviderPlanId', 'live_provider_plan_id')
129
128
  ? { liveProviderPlanId: pickString(item, 'liveProviderPlanId', 'live_provider_plan_id') }
@@ -237,18 +236,26 @@ const normalizePublishedExperiments = (config, publishedAt, offerSets) => readRe
237
236
  };
238
237
  });
239
238
  export const resolvePublishedFunnelRuntimeConfig = (published, options = {}) => {
239
+ var _a;
240
240
  if (options.expectedFunnelVersionId
241
241
  && published.sourceVersionId !== options.expectedFunnelVersionId) {
242
242
  throw new Error('Published runtime config belongs to a different funnel version');
243
243
  }
244
244
  const offerSets = normalizePublishedOfferSets(published.config);
245
+ const hostname = ((_a = options.hostname) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase().replace(/\.$/, '')) || '';
246
+ const domainDefaults = published.config.defaultOfferSetIdByDomain;
247
+ const hasDomainDefault = Boolean(hostname
248
+ && isRecord(domainDefaults)
249
+ && Object.prototype.hasOwnProperty.call(domainDefaults, hostname));
245
250
  return deepFreeze({
246
251
  revisionId: published.revisionId,
247
252
  sourceDeploymentId: published.sourceDeploymentId,
248
253
  sourceVersionId: published.sourceVersionId,
249
254
  publishedAt: published.publishedAt,
250
255
  sessionReplay: normalizeSessionReplay(published.config.sessionReplay),
251
- defaultOfferSetId: readString(published.config.defaultOfferSetId),
256
+ defaultOfferSetId: hasDomainDefault && isRecord(domainDefaults)
257
+ ? readString(domainDefaults[hostname])
258
+ : readString(published.config.defaultOfferSetId),
252
259
  offerSets,
253
260
  experiments: normalizePublishedExperiments(published.config, published.publishedAt, offerSets),
254
261
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/runtime",
3
- "version": "0.7.16",
3
+ "version": "0.7.19",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",