@mpgd/catalog 0.5.1 → 0.5.2
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/dist/index.d.ts +8 -4
- package/dist/index.js +93 -55
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type tags } from 'typia';
|
|
2
2
|
import type { LogicalAdPlacementId, LogicalProductId, ProductType } from '@mpgd/platform';
|
|
3
|
-
|
|
4
|
-
export type
|
|
3
|
+
/** Built-in and game-owned deployment target names. */
|
|
4
|
+
export type CatalogTarget = string;
|
|
5
|
+
/** Built-in and game-owned ad placement target names. */
|
|
6
|
+
export type AdPlacementTarget = string;
|
|
5
7
|
export type ProductGrant = {
|
|
6
8
|
readonly type: 'currency';
|
|
7
9
|
readonly currency: 'coin' | 'gem';
|
|
@@ -48,6 +50,8 @@ export interface AdPlacements {
|
|
|
48
50
|
readonly version: string;
|
|
49
51
|
readonly placements: readonly AdPlacementEntry[];
|
|
50
52
|
}
|
|
51
|
-
export declare const assertProductCatalog: (input: unknown) => ProductCatalog;
|
|
52
|
-
export declare const assertAdPlacements: (input: unknown) => AdPlacements;
|
|
53
53
|
export declare const assertProductGrant: (input: unknown) => ProductGrant;
|
|
54
|
+
export declare function assertProductCatalog(input: unknown): ProductCatalog;
|
|
55
|
+
export declare function assertAdPlacements(input: unknown): AdPlacements;
|
|
56
|
+
export declare function resolveProductPlatformId(product: ProductCatalogEntry, target: CatalogTarget): string | undefined;
|
|
57
|
+
export declare function resolveAdPlacementPlatformId(placement: AdPlacementEntry, target: AdPlacementTarget): string | undefined;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as _assertGuard_1 from "typia/lib/internal/_assertGuard";
|
|
2
|
+
import * as _accessExpressionAsString_1 from "typia/lib/internal/_accessExpressionAsString";
|
|
3
|
+
const __typia_transform__accessExpressionAsString = _accessExpressionAsString_1._accessExpressionAsString;
|
|
2
4
|
import typia from 'typia';
|
|
3
|
-
|
|
5
|
+
const assertProductCatalogShape = (() => {
|
|
4
6
|
const _ae0 = "({ readonly type: \"currency\"; readonly currency: \"coin\" | \"gem\"; readonly amount: number; } | { readonly type: \"entitlement\"; readonly entitlement: string; } | { readonly type: \"resource\"; readonly resource: string & MinLength<1>; readonly amount: number & ExclusiveMinimum<0> & Maximum<1.7976931348623157e+308>; })";
|
|
5
7
|
const _ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.version || _assertGuard_1._assertGuard(_exceptionable, {
|
|
6
8
|
method: "typia.createAssert",
|
|
@@ -51,12 +53,12 @@ export const assertProductCatalog = (() => {
|
|
|
51
53
|
}, _errorFactory)) && (("object" === typeof input.platformProductIds && null !== input.platformProductIds && false === Array.isArray(input.platformProductIds) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
52
54
|
method: "typia.createAssert",
|
|
53
55
|
path: _path + ".platformProductIds",
|
|
54
|
-
expected: "Partial<Record<
|
|
56
|
+
expected: "Partial<Record<string, string>>",
|
|
55
57
|
value: input.platformProductIds
|
|
56
58
|
}, _errorFactory)) && _ao5(input.platformProductIds, _path + ".platformProductIds", true && _exceptionable) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
57
59
|
method: "typia.createAssert",
|
|
58
60
|
path: _path + ".platformProductIds",
|
|
59
|
-
expected: "Partial<Record<
|
|
61
|
+
expected: "Partial<Record<string, string>>",
|
|
60
62
|
value: input.platformProductIds
|
|
61
63
|
}, _errorFactory));
|
|
62
64
|
const _ao2 = (input, _path, _exceptionable = true) => ("currency" === input.type || _assertGuard_1._assertGuard(_exceptionable, {
|
|
@@ -117,32 +119,17 @@ export const assertProductCatalog = (() => {
|
|
|
117
119
|
expected: "(number & ExclusiveMinimum<0> & Maximum<1.7976931348623157e+308>)",
|
|
118
120
|
value: input.amount
|
|
119
121
|
}, _errorFactory));
|
|
120
|
-
const _ao5 = (input, _path, _exceptionable = true) =>
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
value
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
method: "typia.createAssert",
|
|
132
|
-
path: _path + ".ios",
|
|
133
|
-
expected: "(string | undefined)",
|
|
134
|
-
value: input.ios
|
|
135
|
-
}, _errorFactory)) && (undefined === input.reddit || "string" === typeof input.reddit || _assertGuard_1._assertGuard(_exceptionable, {
|
|
136
|
-
method: "typia.createAssert",
|
|
137
|
-
path: _path + ".reddit",
|
|
138
|
-
expected: "(string | undefined)",
|
|
139
|
-
value: input.reddit
|
|
140
|
-
}, _errorFactory)) && (undefined === input.verse8 || "string" === typeof input.verse8 || _assertGuard_1._assertGuard(_exceptionable, {
|
|
141
|
-
method: "typia.createAssert",
|
|
142
|
-
path: _path + ".verse8",
|
|
143
|
-
expected: "(string | undefined)",
|
|
144
|
-
value: input.verse8
|
|
145
|
-
}, _errorFactory));
|
|
122
|
+
const _ao5 = (input, _path, _exceptionable = true) => false === _exceptionable || Object.keys(input).every(key => {
|
|
123
|
+
const value = input[key];
|
|
124
|
+
if (undefined === value)
|
|
125
|
+
return true;
|
|
126
|
+
return undefined === value || "string" === typeof value || _assertGuard_1._assertGuard(_exceptionable, {
|
|
127
|
+
method: "typia.createAssert",
|
|
128
|
+
path: _path + __typia_transform__accessExpressionAsString(key),
|
|
129
|
+
expected: "(string | undefined)",
|
|
130
|
+
value: value
|
|
131
|
+
}, _errorFactory);
|
|
132
|
+
});
|
|
146
133
|
const _au0 = (input, _path, _exceptionable = true) => (() => {
|
|
147
134
|
if ("currency" === input.type)
|
|
148
135
|
return _ao2(input, _path, true && _exceptionable);
|
|
@@ -163,7 +150,12 @@ export const assertProductCatalog = (() => {
|
|
|
163
150
|
const _io2 = input => "currency" === input.type && ("coin" === input.currency || "gem" === input.currency) && "number" === typeof input.amount;
|
|
164
151
|
const _io3 = input => "entitlement" === input.type && "string" === typeof input.entitlement;
|
|
165
152
|
const _io4 = input => "resource" === input.type && ("string" === typeof input.resource && 1 <= input.resource.length) && ("number" === typeof input.amount && (0 < input.amount && input.amount <= 1.7976931348623157e+308));
|
|
166
|
-
const _io5 = input =>
|
|
153
|
+
const _io5 = input => Object.keys(input).every(key => {
|
|
154
|
+
const value = input[key];
|
|
155
|
+
if (undefined === value)
|
|
156
|
+
return true;
|
|
157
|
+
return undefined === value || "string" === typeof value;
|
|
158
|
+
});
|
|
167
159
|
const _iu0 = input => (() => {
|
|
168
160
|
if ("currency" === input.type)
|
|
169
161
|
return _io2(input);
|
|
@@ -194,7 +186,7 @@ export const assertProductCatalog = (() => {
|
|
|
194
186
|
return input;
|
|
195
187
|
};
|
|
196
188
|
})();
|
|
197
|
-
|
|
189
|
+
const assertAdPlacementsShape = (() => {
|
|
198
190
|
const _ip0 = input => "number" === typeof input["amount"];
|
|
199
191
|
const _ae0 = "(undefined | { readonly type: \"continue\"; readonly amount: number; } | { readonly type: \"currency\"; readonly amount: number; readonly currency: \"coin\" | \"gem\"; })";
|
|
200
192
|
const _ap0 = (input, _path, _exceptionable = true) => "number" === typeof input["amount"] || _assertGuard_1._assertGuard(_exceptionable, {
|
|
@@ -263,12 +255,12 @@ export const assertAdPlacements = (() => {
|
|
|
263
255
|
}, _errorFactory)) && (("object" === typeof input.platformPlacementIds && null !== input.platformPlacementIds && false === Array.isArray(input.platformPlacementIds) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
264
256
|
method: "typia.createAssert",
|
|
265
257
|
path: _path + ".platformPlacementIds",
|
|
266
|
-
expected: "Partial<Record<
|
|
258
|
+
expected: "Partial<Record<string, string>>",
|
|
267
259
|
value: input.platformPlacementIds
|
|
268
260
|
}, _errorFactory)) && _ao5(input.platformPlacementIds, _path + ".platformPlacementIds", true && _exceptionable) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
269
261
|
method: "typia.createAssert",
|
|
270
262
|
path: _path + ".platformPlacementIds",
|
|
271
|
-
expected: "Partial<Record<
|
|
263
|
+
expected: "Partial<Record<string, string>>",
|
|
272
264
|
value: input.platformPlacementIds
|
|
273
265
|
}, _errorFactory));
|
|
274
266
|
const _ao2 = (input, _path, _exceptionable = true) => ("continue" === input.type || _assertGuard_1._assertGuard(_exceptionable, {
|
|
@@ -304,27 +296,17 @@ export const assertAdPlacements = (() => {
|
|
|
304
296
|
expected: "(number | undefined)",
|
|
305
297
|
value: input.minStageInterval
|
|
306
298
|
}, _errorFactory));
|
|
307
|
-
const _ao5 = (input, _path, _exceptionable = true) =>
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
value
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
method: "typia.createAssert",
|
|
319
|
-
path: _path + ".ios",
|
|
320
|
-
expected: "(string | undefined)",
|
|
321
|
-
value: input.ios
|
|
322
|
-
}, _errorFactory)) && (undefined === input.verse8 || "string" === typeof input.verse8 || _assertGuard_1._assertGuard(_exceptionable, {
|
|
323
|
-
method: "typia.createAssert",
|
|
324
|
-
path: _path + ".verse8",
|
|
325
|
-
expected: "(string | undefined)",
|
|
326
|
-
value: input.verse8
|
|
327
|
-
}, _errorFactory));
|
|
299
|
+
const _ao5 = (input, _path, _exceptionable = true) => false === _exceptionable || Object.keys(input).every(key => {
|
|
300
|
+
const value = input[key];
|
|
301
|
+
if (undefined === value)
|
|
302
|
+
return true;
|
|
303
|
+
return undefined === value || "string" === typeof value || _assertGuard_1._assertGuard(_exceptionable, {
|
|
304
|
+
method: "typia.createAssert",
|
|
305
|
+
path: _path + __typia_transform__accessExpressionAsString(key),
|
|
306
|
+
expected: "(string | undefined)",
|
|
307
|
+
value: value
|
|
308
|
+
}, _errorFactory);
|
|
309
|
+
});
|
|
328
310
|
const _au0 = (input, _path, _exceptionable = true) => (() => {
|
|
329
311
|
if ("continue" === input.type)
|
|
330
312
|
return _ao2(input, _path, true && _exceptionable);
|
|
@@ -343,7 +325,12 @@ export const assertAdPlacements = (() => {
|
|
|
343
325
|
const _io2 = input => "continue" === input.type && _ip0(input);
|
|
344
326
|
const _io3 = input => "currency" === input.type && _ip0(input) && ("coin" === input.currency || "gem" === input.currency);
|
|
345
327
|
const _io4 = input => "number" === typeof input.cooldownSeconds && (undefined === input.maxPerSession || "number" === typeof input.maxPerSession) && (undefined === input.minStageInterval || "number" === typeof input.minStageInterval);
|
|
346
|
-
const _io5 = input =>
|
|
328
|
+
const _io5 = input => Object.keys(input).every(key => {
|
|
329
|
+
const value = input[key];
|
|
330
|
+
if (undefined === value)
|
|
331
|
+
return true;
|
|
332
|
+
return undefined === value || "string" === typeof value;
|
|
333
|
+
});
|
|
347
334
|
const _iu0 = input => (() => {
|
|
348
335
|
if ("continue" === input.type)
|
|
349
336
|
return _io2(input);
|
|
@@ -480,3 +467,54 @@ export const assertProductGrant = (() => {
|
|
|
480
467
|
return input;
|
|
481
468
|
};
|
|
482
469
|
})();
|
|
470
|
+
export function assertProductCatalog(input) {
|
|
471
|
+
const catalog = assertProductCatalogShape(input);
|
|
472
|
+
assertUniqueNormalizedPlatformIdentifiers(catalog.products.map((product) => ({
|
|
473
|
+
logicalId: product.id,
|
|
474
|
+
identifiers: product.platformProductIds,
|
|
475
|
+
})), 'product');
|
|
476
|
+
return catalog;
|
|
477
|
+
}
|
|
478
|
+
export function assertAdPlacements(input) {
|
|
479
|
+
const placements = assertAdPlacementsShape(input);
|
|
480
|
+
assertUniqueNormalizedPlatformIdentifiers(placements.placements.map((placement) => ({
|
|
481
|
+
logicalId: placement.id,
|
|
482
|
+
identifiers: placement.platformPlacementIds,
|
|
483
|
+
})), 'ad placement');
|
|
484
|
+
return placements;
|
|
485
|
+
}
|
|
486
|
+
export function resolveProductPlatformId(product, target) {
|
|
487
|
+
const identifier = readOwnPlatformIdentifier(product.platformProductIds, target);
|
|
488
|
+
return normalizePlatformIdentifier(identifier);
|
|
489
|
+
}
|
|
490
|
+
export function resolveAdPlacementPlatformId(placement, target) {
|
|
491
|
+
return normalizePlatformIdentifier(readOwnPlatformIdentifier(placement.platformPlacementIds, target));
|
|
492
|
+
}
|
|
493
|
+
function readOwnPlatformIdentifier(identifiers, target) {
|
|
494
|
+
return Object.prototype.hasOwnProperty.call(identifiers, target)
|
|
495
|
+
? identifiers[target]
|
|
496
|
+
: undefined;
|
|
497
|
+
}
|
|
498
|
+
function normalizePlatformIdentifier(identifier) {
|
|
499
|
+
const normalized = identifier?.trim();
|
|
500
|
+
return normalized === undefined || normalized.length === 0 ? undefined : normalized;
|
|
501
|
+
}
|
|
502
|
+
function assertUniqueNormalizedPlatformIdentifiers(entries, kind) {
|
|
503
|
+
const identifiersByTarget = new Map();
|
|
504
|
+
for (const entry of entries) {
|
|
505
|
+
for (const [target, identifier] of Object.entries(entry.identifiers)) {
|
|
506
|
+
const normalized = normalizePlatformIdentifier(identifier);
|
|
507
|
+
if (normalized === undefined) {
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
510
|
+
const targetIdentifiers = identifiersByTarget.get(target) ?? new Map();
|
|
511
|
+
const existingLogicalId = targetIdentifiers.get(normalized);
|
|
512
|
+
if (existingLogicalId !== undefined) {
|
|
513
|
+
throw new Error(`Duplicate normalized ${kind} platform identifier ${normalized} for target ${target}: `
|
|
514
|
+
+ `${existingLogicalId} and ${entry.logicalId}.`);
|
|
515
|
+
}
|
|
516
|
+
targetIdentifiers.set(normalized, entry.logicalId);
|
|
517
|
+
identifiersByTarget.set(target, targetIdentifiers);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|