@mpgd/target-config 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 imjlk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,94 @@
1
+ import type { AdPlacementEntry, AdPlacements, ProductCatalog, ProductCatalogEntry } from '@mpgd/catalog';
2
+ import type { FeatureAvailabilityReason, TargetCapabilityConfig, TargetConfig, TargetConfigMatrix, TargetFeatureConfig, TargetPolicyRestrictions, TargetReleaseConfig, TargetRuntimeKind } from './runtime';
3
+ export type EffectiveAvailabilityReason = FeatureAvailabilityReason | 'missing-platform-id';
4
+ export interface EffectivePlatformTargetMetadata {
5
+ readonly kind: string;
6
+ readonly adapter: string;
7
+ readonly artifact?: string;
8
+ readonly output?: string;
9
+ readonly webDir?: string;
10
+ }
11
+ export interface EffectiveTargetConfigSources {
12
+ readonly targetConfig: string;
13
+ readonly productCatalog: string;
14
+ readonly adPlacements: string;
15
+ readonly platformTargetKind?: string;
16
+ readonly platformAdapter?: string;
17
+ }
18
+ export interface EffectiveProductConfig {
19
+ readonly id: ProductCatalogEntry['id'];
20
+ readonly type: ProductCatalogEntry['type'];
21
+ readonly grant: ProductCatalogEntry['grant'];
22
+ readonly enabled: boolean;
23
+ readonly reason: EffectiveAvailabilityReason;
24
+ readonly platformProductId?: string;
25
+ }
26
+ export interface EffectiveAdPlacementConfig {
27
+ readonly id: AdPlacementEntry['id'];
28
+ readonly type: AdPlacementEntry['type'];
29
+ readonly reward?: AdPlacementEntry['reward'];
30
+ readonly frequencyCap: AdPlacementEntry['frequencyCap'];
31
+ readonly enabled: boolean;
32
+ readonly reason: EffectiveAvailabilityReason;
33
+ readonly platformPlacementId?: string;
34
+ }
35
+ export interface EffectiveMonetizationConfig {
36
+ readonly iap: boolean;
37
+ readonly products: readonly EffectiveProductConfig[];
38
+ }
39
+ export interface EffectiveAdsConfig {
40
+ readonly rewardedAds: boolean;
41
+ readonly interstitialAds: boolean;
42
+ readonly placements: readonly EffectiveAdPlacementConfig[];
43
+ }
44
+ export interface EffectiveLeaderboardConfig {
45
+ readonly native: boolean;
46
+ readonly enabled: boolean;
47
+ readonly reason: FeatureAvailabilityReason;
48
+ readonly defaultLeaderboardId?: string;
49
+ }
50
+ export interface EffectiveStorageConfig {
51
+ readonly support: TargetCapabilityConfig['storage'];
52
+ readonly enabled: boolean;
53
+ }
54
+ export interface EffectiveLocalizationConfig {
55
+ readonly enabled: boolean;
56
+ }
57
+ export interface EffectiveTargetConfig {
58
+ readonly version: string;
59
+ readonly target: string;
60
+ readonly runtime: TargetRuntimeKind;
61
+ readonly release: TargetReleaseConfig;
62
+ readonly features: TargetFeatureConfig;
63
+ readonly capabilities: TargetCapabilityConfig;
64
+ readonly policy: TargetPolicyRestrictions;
65
+ readonly sources: EffectiveTargetConfigSources;
66
+ readonly monetization: EffectiveMonetizationConfig;
67
+ readonly ads: EffectiveAdsConfig;
68
+ readonly leaderboard: EffectiveLeaderboardConfig;
69
+ readonly storage: EffectiveStorageConfig;
70
+ readonly localization: EffectiveLocalizationConfig;
71
+ }
72
+ export interface EffectiveTargetConfigMatrix {
73
+ readonly version: string;
74
+ readonly targets: Record<string, EffectiveTargetConfig>;
75
+ }
76
+ export interface CreateEffectiveTargetConfigInput {
77
+ readonly target: string;
78
+ readonly targetConfigVersion: string;
79
+ readonly config: TargetConfig;
80
+ readonly catalog: ProductCatalog;
81
+ readonly adPlacements: AdPlacements;
82
+ readonly platformTarget?: EffectivePlatformTargetMetadata;
83
+ }
84
+ export interface CreateEffectiveTargetConfigMatrixInput {
85
+ readonly configMatrix: TargetConfigMatrix;
86
+ readonly catalog: ProductCatalog;
87
+ readonly adPlacements: AdPlacements;
88
+ readonly platformTargets?: Record<string, EffectivePlatformTargetMetadata>;
89
+ }
90
+ export declare const defaultLeaderboardId = "default";
91
+ export declare function createEffectiveTargetConfig(input: CreateEffectiveTargetConfigInput): EffectiveTargetConfig;
92
+ export declare function createEffectiveTargetConfigMatrix(input: CreateEffectiveTargetConfigMatrixInput): EffectiveTargetConfigMatrix;
93
+ export declare function getEffectiveProductConfig(config: EffectiveTargetConfig, productId: ProductCatalogEntry['id']): EffectiveProductConfig | undefined;
94
+ export declare function getEffectiveAdPlacementConfig(config: EffectiveTargetConfig, placementId: AdPlacementEntry['id']): EffectiveAdPlacementConfig | undefined;
@@ -0,0 +1,137 @@
1
+ export const defaultLeaderboardId = 'default';
2
+ export function createEffectiveTargetConfig(input) {
3
+ const products = input.catalog.products.map((product) => createEffectiveProductConfig(input.target, input.config, product));
4
+ const placements = input.adPlacements.placements.map((placement) => createEffectiveAdPlacementConfig(input.target, input.config, placement));
5
+ const leaderboardEnabled = input.config.features.leaderboard;
6
+ return {
7
+ version: effectiveTargetConfigVersion({
8
+ targetConfig: input.targetConfigVersion,
9
+ productCatalog: input.catalog.version,
10
+ adPlacements: input.adPlacements.version,
11
+ }),
12
+ target: input.target,
13
+ runtime: input.config.runtime,
14
+ release: input.config.release,
15
+ features: input.config.features,
16
+ capabilities: input.config.capabilities,
17
+ policy: input.config.policy,
18
+ sources: {
19
+ targetConfig: input.targetConfigVersion,
20
+ productCatalog: input.catalog.version,
21
+ adPlacements: input.adPlacements.version,
22
+ ...(input.platformTarget === undefined
23
+ ? {}
24
+ : {
25
+ platformTargetKind: input.platformTarget.kind,
26
+ platformAdapter: input.platformTarget.adapter,
27
+ }),
28
+ },
29
+ monetization: {
30
+ iap: input.config.monetization.iap,
31
+ products,
32
+ },
33
+ ads: {
34
+ rewardedAds: input.config.monetization.rewardedAds,
35
+ interstitialAds: input.config.monetization.interstitialAds,
36
+ placements,
37
+ },
38
+ leaderboard: {
39
+ native: input.config.leaderboard.native,
40
+ enabled: leaderboardEnabled,
41
+ reason: leaderboardEnabled ? 'available' : 'target-disabled',
42
+ ...(leaderboardEnabled ? { defaultLeaderboardId } : {}),
43
+ },
44
+ storage: {
45
+ support: input.config.capabilities.storage,
46
+ enabled: input.config.capabilities.storage !== 'none',
47
+ },
48
+ localization: {
49
+ enabled: input.config.capabilities.localization,
50
+ },
51
+ };
52
+ }
53
+ export function createEffectiveTargetConfigMatrix(input) {
54
+ const targets = Object.fromEntries(Object.entries(input.configMatrix.targets).map(([target, config]) => {
55
+ const platformTarget = input.platformTargets?.[target];
56
+ return [
57
+ target,
58
+ createEffectiveTargetConfig({
59
+ target,
60
+ targetConfigVersion: input.configMatrix.version,
61
+ config,
62
+ catalog: input.catalog,
63
+ adPlacements: input.adPlacements,
64
+ ...(platformTarget === undefined ? {} : { platformTarget }),
65
+ }),
66
+ ];
67
+ }));
68
+ return {
69
+ version: effectiveTargetConfigVersion({
70
+ targetConfig: input.configMatrix.version,
71
+ productCatalog: input.catalog.version,
72
+ adPlacements: input.adPlacements.version,
73
+ }),
74
+ targets,
75
+ };
76
+ }
77
+ export function getEffectiveProductConfig(config, productId) {
78
+ return config.monetization.products.find((product) => product.id === productId);
79
+ }
80
+ export function getEffectiveAdPlacementConfig(config, placementId) {
81
+ return config.ads.placements.find((placement) => placement.id === placementId);
82
+ }
83
+ function createEffectiveProductConfig(target, config, product) {
84
+ const platformProductId = productPlatformId(product, target);
85
+ const reason = effectiveItemReason(config.features.iap, platformProductId);
86
+ return {
87
+ id: product.id,
88
+ type: product.type,
89
+ grant: product.grant,
90
+ enabled: reason === 'available',
91
+ reason,
92
+ ...(platformProductId === undefined ? {} : { platformProductId }),
93
+ };
94
+ }
95
+ function createEffectiveAdPlacementConfig(target, config, placement) {
96
+ const featureEnabled = isRewardedPlacement(placement)
97
+ ? config.features.rewardedAds
98
+ : config.features.interstitialAds;
99
+ const platformPlacementId = adPlacementPlatformId(placement, target);
100
+ const reason = effectiveItemReason(featureEnabled, platformPlacementId);
101
+ return {
102
+ id: placement.id,
103
+ type: placement.type,
104
+ frequencyCap: placement.frequencyCap,
105
+ enabled: reason === 'available',
106
+ reason,
107
+ ...(placement.reward === undefined ? {} : { reward: placement.reward }),
108
+ ...(platformPlacementId === undefined ? {} : { platformPlacementId }),
109
+ };
110
+ }
111
+ function effectiveItemReason(targetEnabled, platformId) {
112
+ if (!targetEnabled) {
113
+ return 'target-disabled';
114
+ }
115
+ return platformId === undefined ? 'missing-platform-id' : 'available';
116
+ }
117
+ function effectiveTargetConfigVersion(input) {
118
+ return `${input.targetConfig}+catalog.${input.productCatalog}+ads.${input.adPlacements}`;
119
+ }
120
+ function productPlatformId(product, target) {
121
+ if (!isStoreBackedTarget(target)) {
122
+ return undefined;
123
+ }
124
+ return product.platformProductIds[target];
125
+ }
126
+ function adPlacementPlatformId(placement, target) {
127
+ if (!isStoreBackedTarget(target)) {
128
+ return undefined;
129
+ }
130
+ return placement.platformPlacementIds[target];
131
+ }
132
+ function isStoreBackedTarget(target) {
133
+ return target === 'android' || target === 'ios' || target === 'ait';
134
+ }
135
+ function isRewardedPlacement(placement) {
136
+ return placement.type === 'rewarded';
137
+ }
@@ -0,0 +1,6 @@
1
+ import type { EffectiveTargetConfigMatrix } from './effective';
2
+ import type { TargetConfigMatrix } from './runtime';
3
+ export * from './effective';
4
+ export * from './runtime';
5
+ export declare const assertEffectiveTargetConfigMatrix: (input: unknown) => EffectiveTargetConfigMatrix;
6
+ export declare const assertTargetConfigMatrix: (input: unknown) => TargetConfigMatrix;