owostack 0.4.3 → 0.4.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.
- package/dist/index.js +45 -52
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -392,6 +392,40 @@ function creditPack(slug, config) {
|
|
|
392
392
|
function slugToName(slug) {
|
|
393
393
|
return slug.split(/[-_]/).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
394
394
|
}
|
|
395
|
+
function collectReferencedCreditSystems(catalog) {
|
|
396
|
+
const creditSystems = catalog.filter(
|
|
397
|
+
(entry) => entry._type === "credit_system"
|
|
398
|
+
);
|
|
399
|
+
const knownCreditSystemSlugs = new Set(creditSystems.map((cs) => cs.slug));
|
|
400
|
+
for (const entry of catalog) {
|
|
401
|
+
if (entry._type !== "plan") continue;
|
|
402
|
+
for (const feature of entry.features) {
|
|
403
|
+
const creditSystemHandle = _creditSystemRegistry.get(feature.slug);
|
|
404
|
+
if (!creditSystemHandle || knownCreditSystemSlugs.has(feature.slug)) {
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
creditSystems.push(creditSystemHandle._buildDefinition());
|
|
408
|
+
knownCreditSystemSlugs.add(feature.slug);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return creditSystems;
|
|
412
|
+
}
|
|
413
|
+
function collectCatalogFeatureSlugs(catalog) {
|
|
414
|
+
const featureSlugs = /* @__PURE__ */ new Set();
|
|
415
|
+
for (const entry of catalog) {
|
|
416
|
+
if (entry._type !== "plan") continue;
|
|
417
|
+
for (const feature of entry.features) {
|
|
418
|
+
if (_creditSystemRegistry.has(feature.slug)) continue;
|
|
419
|
+
featureSlugs.add(feature.slug);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
for (const creditSystem2 of collectReferencedCreditSystems(catalog)) {
|
|
423
|
+
for (const feature of creditSystem2.features) {
|
|
424
|
+
featureSlugs.add(feature.feature);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return featureSlugs;
|
|
428
|
+
}
|
|
395
429
|
function buildSyncPayload(catalog, defaultProvider) {
|
|
396
430
|
const featureMap = /* @__PURE__ */ new Map();
|
|
397
431
|
for (const entry of catalog) {
|
|
@@ -411,9 +445,16 @@ function buildSyncPayload(catalog, defaultProvider) {
|
|
|
411
445
|
}
|
|
412
446
|
}
|
|
413
447
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
448
|
+
const creditSystems = collectReferencedCreditSystems(
|
|
449
|
+
catalog
|
|
450
|
+
).map((cs) => ({
|
|
451
|
+
slug: cs.slug,
|
|
452
|
+
name: cs.name,
|
|
453
|
+
description: cs.description,
|
|
454
|
+
features: cs.features
|
|
455
|
+
}));
|
|
456
|
+
for (const creditSystem2 of creditSystems) {
|
|
457
|
+
for (const csFeature of creditSystem2.features) {
|
|
417
458
|
const featureSlug = csFeature.feature;
|
|
418
459
|
if (!featureMap.has(featureSlug)) {
|
|
419
460
|
const handle = _featureRegistry.get(featureSlug);
|
|
@@ -425,47 +466,6 @@ function buildSyncPayload(catalog, defaultProvider) {
|
|
|
425
466
|
}
|
|
426
467
|
}
|
|
427
468
|
}
|
|
428
|
-
for (const entry of catalog) {
|
|
429
|
-
if (entry._type !== "plan") continue;
|
|
430
|
-
for (const f of entry.features) {
|
|
431
|
-
const csHandle = _creditSystemRegistry.get(f.slug);
|
|
432
|
-
if (csHandle) {
|
|
433
|
-
const def = csHandle._buildDefinition();
|
|
434
|
-
for (const csFeature of def.features) {
|
|
435
|
-
const featureSlug = csFeature.feature;
|
|
436
|
-
if (!featureMap.has(featureSlug)) {
|
|
437
|
-
const handle = _featureRegistry.get(featureSlug);
|
|
438
|
-
featureMap.set(featureSlug, {
|
|
439
|
-
slug: featureSlug,
|
|
440
|
-
type: "metered",
|
|
441
|
-
name: handle?.featureName || slugToName(featureSlug)
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
const creditSystems = catalog.filter((e) => e._type === "credit_system").map((cs) => ({
|
|
449
|
-
slug: cs.slug,
|
|
450
|
-
name: cs.name,
|
|
451
|
-
description: cs.description,
|
|
452
|
-
features: cs.features
|
|
453
|
-
}));
|
|
454
|
-
for (const entry of catalog) {
|
|
455
|
-
if (entry._type !== "plan") continue;
|
|
456
|
-
for (const f of entry.features) {
|
|
457
|
-
const csHandle = _creditSystemRegistry.get(f.slug);
|
|
458
|
-
if (csHandle && !creditSystems.find((cs) => cs.slug === f.slug)) {
|
|
459
|
-
const def = csHandle._buildDefinition();
|
|
460
|
-
creditSystems.push({
|
|
461
|
-
slug: def.slug,
|
|
462
|
-
name: def.name,
|
|
463
|
-
description: def.description,
|
|
464
|
-
features: def.features
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
469
|
const plans = catalog.filter((e) => e._type === "plan").map((p) => ({
|
|
470
470
|
slug: p.slug,
|
|
471
471
|
name: p.name,
|
|
@@ -545,14 +545,7 @@ function buildSyncPayload(catalog, defaultProvider) {
|
|
|
545
545
|
}
|
|
546
546
|
function bindFeatureHandles(client, catalog) {
|
|
547
547
|
if (catalog) {
|
|
548
|
-
const slugsInCatalog =
|
|
549
|
-
for (const entry of catalog) {
|
|
550
|
-
if (entry._type === "plan") {
|
|
551
|
-
for (const f of entry.features) {
|
|
552
|
-
slugsInCatalog.add(f.slug);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
548
|
+
const slugsInCatalog = collectCatalogFeatureSlugs(catalog);
|
|
556
549
|
for (const [slug, handle] of _featureRegistry) {
|
|
557
550
|
if (slugsInCatalog.has(slug)) {
|
|
558
551
|
handle._client = client;
|