@funnelsgrove/runtime 0.7.3 → 0.7.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.
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { FunnelExperimentDefinition } from '../config/funnel.experiments.types.js';
|
|
2
2
|
import type { GeneratedOfferSet } from '../runtime/offer-set-runtime.js';
|
|
3
3
|
export type FunnelRuntimeConfig = {
|
|
4
|
-
schemaVersion:
|
|
4
|
+
schemaVersion: 2;
|
|
5
5
|
funnelId: string;
|
|
6
6
|
projectId: string;
|
|
7
|
-
/** Present only on historical schema-v1 artifacts. */
|
|
8
|
-
plans?: unknown[];
|
|
9
7
|
offerSets: unknown[];
|
|
10
8
|
experiments: unknown[];
|
|
11
9
|
};
|
|
@@ -21,7 +19,7 @@ export type PublishedFunnelRuntimeConfig = {
|
|
|
21
19
|
revisionId: string;
|
|
22
20
|
sourceDeploymentId: string;
|
|
23
21
|
sourceVersionId: string;
|
|
24
|
-
schemaVersion:
|
|
22
|
+
schemaVersion: 2;
|
|
25
23
|
publishedAt: string;
|
|
26
24
|
config: FunnelRuntimeConfig;
|
|
27
25
|
};
|
|
@@ -25,20 +25,7 @@ const deepFreeze = (value) => {
|
|
|
25
25
|
}
|
|
26
26
|
return value;
|
|
27
27
|
};
|
|
28
|
-
const
|
|
29
|
-
var _a;
|
|
30
|
-
return (projectBillingPlanId
|
|
31
|
-
? (_a = plans.find((plan) => pickString(plan, 'id') === projectBillingPlanId)) !== null && _a !== void 0 ? _a : null
|
|
32
|
-
: null);
|
|
33
|
-
};
|
|
34
|
-
const getLegacyProviderMapping = (plan, mode) => {
|
|
35
|
-
var _a;
|
|
36
|
-
return ((_a = readRecordArray(plan === null || plan === void 0 ? void 0 : plan.providerMappings)
|
|
37
|
-
.find((mapping) => (pickString(mapping, 'environment') === mode
|
|
38
|
-
&& pickBoolean(mapping, 'isActive', 'is_active') !== false))) !== null && _a !== void 0 ? _a : null);
|
|
39
|
-
};
|
|
40
|
-
const buildPlanModeConfig = (item, mode, legacyPlan = null) => {
|
|
41
|
-
var _a, _b;
|
|
28
|
+
const buildPlanModeConfig = (item, mode) => {
|
|
42
29
|
const metadata = isRecord(item.metadata) ? item.metadata : {};
|
|
43
30
|
const directMappings = isRecord(item.providerMappingsByMode)
|
|
44
31
|
? item.providerMappingsByMode
|
|
@@ -51,20 +38,16 @@ const buildPlanModeConfig = (item, mode, legacyPlan = null) => {
|
|
|
51
38
|
: isRecord(metadataMappings[mode])
|
|
52
39
|
? metadataMappings[mode]
|
|
53
40
|
: {};
|
|
54
|
-
const legacyMapping = getLegacyProviderMapping(legacyPlan, mode);
|
|
55
41
|
const prefix = mode === 'test' ? 'test' : 'live';
|
|
56
42
|
const providerPlanId = (pickString(item, `${prefix}ProviderPlanId`, `${prefix}_provider_plan_id`)
|
|
57
|
-
|| pickString(modeMapping, 'providerPlanId')
|
|
58
|
-
|| (legacyMapping ? pickString(legacyMapping, 'providerPlanId', 'provider_plan_id') : null));
|
|
43
|
+
|| pickString(modeMapping, 'providerPlanId'));
|
|
59
44
|
if (!providerPlanId) {
|
|
60
45
|
return null;
|
|
61
46
|
}
|
|
62
|
-
const amountMinor =
|
|
63
|
-
const interval = pickString(modeMapping, 'billingInterval')
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const currency = pickString(modeMapping, 'currency')
|
|
67
|
-
|| (legacyMapping ? pickString(legacyMapping, 'currency') : null);
|
|
47
|
+
const amountMinor = pickNumber(modeMapping, 'amountCents');
|
|
48
|
+
const interval = pickString(modeMapping, 'billingInterval');
|
|
49
|
+
const intervalCount = pickNumber(modeMapping, 'billingIntervalCount');
|
|
50
|
+
const currency = pickString(modeMapping, 'currency');
|
|
68
51
|
const amountMajor = amountMinor === null ? null : amountMinor / 100;
|
|
69
52
|
const priceLabel = pickString(modeMapping, 'priceLabel') || (amountMajor === null
|
|
70
53
|
? null
|
|
@@ -90,7 +73,6 @@ const buildPlanModeConfig = (item, mode, legacyPlan = null) => {
|
|
|
90
73
|
}).format(amountMajor)} today` })), (interval ? { billingInterval: interval } : {})), (intervalCount === null ? {} : { billingIntervalCount: intervalCount }));
|
|
91
74
|
};
|
|
92
75
|
const normalizePublishedOfferSets = (config) => {
|
|
93
|
-
const legacyPlans = readRecordArray(config.plans);
|
|
94
76
|
return readRecordArray(config.offerSets).map((offerSet) => {
|
|
95
77
|
var _a;
|
|
96
78
|
const key = pickString(offerSet, 'key');
|
|
@@ -105,15 +87,12 @@ const normalizePublishedOfferSets = (config) => {
|
|
|
105
87
|
throw new Error(`Published runtime offer set "${key}" has an item without a plan key`);
|
|
106
88
|
}
|
|
107
89
|
const projectBillingPlanId = pickString(item, 'projectBillingPlanId', 'project_billing_plan_id');
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
const liveMapping = buildPlanModeConfig(item, 'live', legacyPlan);
|
|
90
|
+
const testMapping = buildPlanModeConfig(item, 'test');
|
|
91
|
+
const liveMapping = buildPlanModeConfig(item, 'live');
|
|
111
92
|
const title = pickString(item, 'title', 'displayNameOverride', 'display_name_override')
|
|
112
|
-
|| pickString(metadata, 'title', 'publicPlanName', 'public_plan_name')
|
|
113
|
-
|| (legacyPlan ? pickString(legacyPlan, 'displayName', 'display_name') : null);
|
|
93
|
+
|| pickString(metadata, 'title', 'publicPlanName', 'public_plan_name');
|
|
114
94
|
const description = pickString(item, 'description')
|
|
115
|
-
|| pickString(metadata, 'description')
|
|
116
|
-
|| (legacyPlan ? pickString(legacyPlan, 'description') : null);
|
|
95
|
+
|| pickString(metadata, 'description');
|
|
117
96
|
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({ funnelPlanKey }, (pickString(metadata, 'runtimePlanKey', 'planKey', 'billingPlanKey')
|
|
118
97
|
? { runtimePlanKey: pickString(metadata, 'runtimePlanKey', 'planKey', 'billingPlanKey') }
|
|
119
98
|
: {})), (projectBillingPlanId ? { projectBillingPlanId } : {})), (pickString(item, 'testProviderPlanId', 'test_provider_plan_id')
|
|
@@ -251,14 +230,13 @@ const parsePublishedRuntimeConfig = (value) => {
|
|
|
251
230
|
if (typeof value.revisionId !== 'string'
|
|
252
231
|
|| typeof value.sourceDeploymentId !== 'string'
|
|
253
232
|
|| typeof value.sourceVersionId !== 'string'
|
|
254
|
-
||
|
|
233
|
+
|| value.schemaVersion !== 2
|
|
255
234
|
|| typeof value.publishedAt !== 'string'
|
|
256
|
-
||
|
|
235
|
+
|| schemaVersion !== 2
|
|
257
236
|
|| typeof config.funnelId !== 'string'
|
|
258
237
|
|| typeof config.projectId !== 'string'
|
|
259
238
|
|| !Array.isArray(config.offerSets)
|
|
260
|
-
|| !Array.isArray(config.experiments)
|
|
261
|
-
|| (schemaVersion === 1 && !Array.isArray(config.plans))) {
|
|
239
|
+
|| !Array.isArray(config.experiments)) {
|
|
262
240
|
throw new Error('Funnel runtime config response is invalid');
|
|
263
241
|
}
|
|
264
242
|
return value;
|