@namehash/ens-referrals 1.10.1 → 1.11.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/dist/index.cjs +95 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -19
- package/dist/index.d.ts +29 -19
- package/dist/index.js +95 -42
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -79,6 +79,7 @@ __export(index_exports, {
|
|
|
79
79
|
deserializeReferralProgramEditionSummariesResponse: () => deserializeReferralProgramEditionSummariesResponse,
|
|
80
80
|
deserializeReferrerLeaderboardPageResponse: () => deserializeReferrerLeaderboardPageResponse,
|
|
81
81
|
deserializeReferrerMetricsEditionsResponse: () => deserializeReferrerMetricsEditionsResponse,
|
|
82
|
+
findOverlappingEditionPair: () => findOverlappingEditionPair,
|
|
82
83
|
getReferrerEditionMetrics: () => getReferrerEditionMetrics,
|
|
83
84
|
getReferrerLeaderboardPage: () => getReferrerLeaderboardPage,
|
|
84
85
|
isFiniteNonNegativeNumber: () => isFiniteNonNegativeNumber,
|
|
@@ -478,7 +479,8 @@ function scaleBigintByNumber(value, scaleFactor) {
|
|
|
478
479
|
var CurrencyIds = {
|
|
479
480
|
ETH: "ETH",
|
|
480
481
|
USDC: "USDC",
|
|
481
|
-
DAI: "DAI"
|
|
482
|
+
DAI: "DAI",
|
|
483
|
+
ENSTokens: "ENSTokens"
|
|
482
484
|
};
|
|
483
485
|
var currencyInfo = {
|
|
484
486
|
[CurrencyIds.ETH]: {
|
|
@@ -495,6 +497,11 @@ var currencyInfo = {
|
|
|
495
497
|
id: CurrencyIds.DAI,
|
|
496
498
|
name: "Dai Stablecoin",
|
|
497
499
|
decimals: 18
|
|
500
|
+
},
|
|
501
|
+
[CurrencyIds.ENSTokens]: {
|
|
502
|
+
id: CurrencyIds.ENSTokens,
|
|
503
|
+
name: "$ENS Tokens",
|
|
504
|
+
decimals: 18
|
|
498
505
|
}
|
|
499
506
|
};
|
|
500
507
|
function priceEth(amount) {
|
|
@@ -629,6 +636,62 @@ var import_v43 = __toESM(require("zod/v4"), 1);
|
|
|
629
636
|
// src/award-models/shared/api/zod-schemas.ts
|
|
630
637
|
var import_v42 = __toESM(require("zod/v4"), 1);
|
|
631
638
|
|
|
639
|
+
// src/edition.ts
|
|
640
|
+
var REFERRAL_PROGRAM_EDITION_SLUG_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
641
|
+
function validateReferralProgramEditionConfigSet(configSet) {
|
|
642
|
+
const violation = Array.from(configSet.entries()).find(([key, config]) => key !== config.slug);
|
|
643
|
+
if (violation) {
|
|
644
|
+
const [key, config] = violation;
|
|
645
|
+
throw new Error(
|
|
646
|
+
`Edition config set invariant violation: map key "${key}" does not match config.slug "${config.slug}"`
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
const overlap = findOverlappingEditionPair(Array.from(configSet.values()));
|
|
650
|
+
if (overlap) {
|
|
651
|
+
const [a, b] = overlap;
|
|
652
|
+
throw new Error(
|
|
653
|
+
`Edition config set invariant violation: editions "${a.slug}" and "${b.slug}" have overlapping time ranges for subregistryId ${a.rules.subregistryId.chainId}:${a.rules.subregistryId.address} (startTime and endTime are inclusive)`
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function findOverlappingEditionPair(editions) {
|
|
658
|
+
const byRegistry = /* @__PURE__ */ new Map();
|
|
659
|
+
for (const edition of editions) {
|
|
660
|
+
const key = `${edition.rules.subregistryId.chainId}:${edition.rules.subregistryId.address}`;
|
|
661
|
+
const group = byRegistry.get(key);
|
|
662
|
+
if (group) {
|
|
663
|
+
group.push(edition);
|
|
664
|
+
} else {
|
|
665
|
+
byRegistry.set(key, [edition]);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
for (const group of byRegistry.values()) {
|
|
669
|
+
if (group.length < 2) continue;
|
|
670
|
+
group.sort((a, b) => a.rules.startTime - b.rules.startTime);
|
|
671
|
+
for (let i = 1; i < group.length; i++) {
|
|
672
|
+
const prev = group[i - 1];
|
|
673
|
+
const curr = group[i];
|
|
674
|
+
if (curr.rules.startTime <= prev.rules.endTime) {
|
|
675
|
+
return [prev, curr];
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return null;
|
|
680
|
+
}
|
|
681
|
+
function buildReferralProgramEditionConfigSet(configs) {
|
|
682
|
+
const slugCounts = configs.reduce((counts, config) => {
|
|
683
|
+
counts.set(config.slug, (counts.get(config.slug) || 0) + 1);
|
|
684
|
+
return counts;
|
|
685
|
+
}, /* @__PURE__ */ new Map());
|
|
686
|
+
const duplicates = Array.from(slugCounts.entries()).filter(([_, count]) => count > 1).map(([slug, count]) => `"${slug}" (${count} occurrences)`);
|
|
687
|
+
if (duplicates.length > 0) {
|
|
688
|
+
throw new Error(`Duplicate edition config slugs detected: ${duplicates.join(", ")}`);
|
|
689
|
+
}
|
|
690
|
+
const configSet = new Map(configs.map((config) => [config.slug, config]));
|
|
691
|
+
validateReferralProgramEditionConfigSet(configSet);
|
|
692
|
+
return configSet;
|
|
693
|
+
}
|
|
694
|
+
|
|
632
695
|
// src/number.ts
|
|
633
696
|
var isInteger = (value) => {
|
|
634
697
|
return Number.isInteger(value);
|
|
@@ -835,6 +898,15 @@ var calcBaseReferralProgramEditionStatus = (rules, now) => {
|
|
|
835
898
|
};
|
|
836
899
|
|
|
837
900
|
// src/award-models/shared/api/zod-schemas.ts
|
|
901
|
+
var makeReferralProgramEditionSlugSchema = (valueLabel = "ReferralProgramEditionSlug") => import_v42.default.string().min(1, `${valueLabel} must not be empty`).regex(
|
|
902
|
+
REFERRAL_PROGRAM_EDITION_SLUG_PATTERN,
|
|
903
|
+
`${valueLabel} must contain only lowercase letters, digits, and hyphens. Must not start or end with a hyphen.`
|
|
904
|
+
);
|
|
905
|
+
var makeBaseReferralProgramEditionConfigSchema = (valueLabel = "BaseReferralProgramEditionConfig") => import_v42.default.object({
|
|
906
|
+
slug: makeReferralProgramEditionSlugSchema(`${valueLabel}.slug`),
|
|
907
|
+
displayName: import_v42.default.string().min(1, `${valueLabel}.displayName must not be empty`),
|
|
908
|
+
rules: makeBaseReferralProgramRulesSchema(`${valueLabel}.rules`)
|
|
909
|
+
});
|
|
838
910
|
var makeBaseReferralProgramRulesSchema = (valueLabel) => import_v42.default.object({
|
|
839
911
|
awardModel: import_v42.default.string(),
|
|
840
912
|
startTime: makeUnixTimestampSchema(`${valueLabel}.startTime`),
|
|
@@ -860,12 +932,9 @@ var makeReferrerLeaderboardPageContextSchema = (valueLabel = "ReferrerLeaderboar
|
|
|
860
932
|
endIndex: import_v42.default.optional(makeNonNegativeIntegerSchema(`${valueLabel}.endIndex`))
|
|
861
933
|
});
|
|
862
934
|
var makeReferralProgramStatusSchema = (_valueLabel = "status") => import_v42.default.enum(ReferralProgramEditionStatuses);
|
|
863
|
-
var makeBaseReferralProgramEditionSummarySchema = (valueLabel) =>
|
|
935
|
+
var makeBaseReferralProgramEditionSummarySchema = (valueLabel) => makeBaseReferralProgramEditionConfigSchema(valueLabel).safeExtend({
|
|
864
936
|
awardModel: import_v42.default.string(),
|
|
865
|
-
|
|
866
|
-
displayName: import_v42.default.string().min(1, `${valueLabel}.displayName must not be empty`),
|
|
867
|
-
status: makeReferralProgramStatusSchema(`${valueLabel}.status`),
|
|
868
|
-
rules: makeBaseReferralProgramRulesSchema(`${valueLabel}.rules`)
|
|
937
|
+
status: makeReferralProgramStatusSchema(`${valueLabel}.status`)
|
|
869
938
|
});
|
|
870
939
|
var makeBaseReferrerLeaderboardPageSchema = (valueLabel) => import_v42.default.object({
|
|
871
940
|
awardModel: import_v42.default.string(),
|
|
@@ -1446,10 +1515,6 @@ var makeReferrerEditionMetricsSchema = (valueLabel = "ReferrerEditionMetrics") =
|
|
|
1446
1515
|
};
|
|
1447
1516
|
});
|
|
1448
1517
|
};
|
|
1449
|
-
var makeReferralProgramEditionSlugSchema = (valueLabel = "ReferralProgramEditionSlug") => import_v45.default.string().min(1, `${valueLabel} must not be empty`).regex(
|
|
1450
|
-
/^[a-z0-9]+(-[a-z0-9]+)*$/,
|
|
1451
|
-
`${valueLabel} must contain only lowercase letters, digits, and hyphens. Must not start or end with a hyphen.`
|
|
1452
|
-
);
|
|
1453
1518
|
var makeReferrerMetricsEditionsResponseOkSchema = (valueLabel = "ReferrerMetricsEditionsResponseOk") => import_v45.default.object({
|
|
1454
1519
|
responseCode: import_v45.default.literal(ReferrerMetricsEditionsResponseCodes.Ok),
|
|
1455
1520
|
data: import_v45.default.record(
|
|
@@ -1466,12 +1531,7 @@ var makeReferrerMetricsEditionsResponseSchema = (valueLabel = "ReferrerMetricsEd
|
|
|
1466
1531
|
makeReferrerMetricsEditionsResponseOkSchema(valueLabel),
|
|
1467
1532
|
makeReferrerMetricsEditionsResponseErrorSchema(valueLabel)
|
|
1468
1533
|
]);
|
|
1469
|
-
var
|
|
1470
|
-
slug: makeReferralProgramEditionSlugSchema(`${valueLabel}.slug`),
|
|
1471
|
-
displayName: import_v45.default.string().min(1, `${valueLabel}.displayName must not be empty`),
|
|
1472
|
-
rules: makeBaseReferralProgramRulesSchema(`${valueLabel}.rules`)
|
|
1473
|
-
});
|
|
1474
|
-
var makeReferralProgramEditionConfigSchema = (valueLabel = "ReferralProgramEditionConfig") => makeReferralProgramEditionConfigBaseSchema(valueLabel).safeExtend({
|
|
1534
|
+
var makeReferralProgramEditionConfigSchema = (valueLabel = "ReferralProgramEditionConfig") => makeBaseReferralProgramEditionConfigSchema(valueLabel).safeExtend({
|
|
1475
1535
|
rules: makeReferralProgramRulesSchema(`${valueLabel}.rules`)
|
|
1476
1536
|
});
|
|
1477
1537
|
var makeReferralProgramEditionConfigSetArraySchema = (valueLabel = "ReferralProgramEditionConfigSetArray") => {
|
|
@@ -1482,7 +1542,7 @@ var makeReferralProgramEditionConfigSetArraySchema = (valueLabel = "ReferralProg
|
|
|
1482
1542
|
const looseItemSchema = import_v45.default.looseObject({
|
|
1483
1543
|
rules: import_v45.default.looseObject({ awardModel: import_v45.default.string() })
|
|
1484
1544
|
});
|
|
1485
|
-
const unrecognizedBaseSchema =
|
|
1545
|
+
const unrecognizedBaseSchema = makeBaseReferralProgramEditionConfigSchema(
|
|
1486
1546
|
`${valueLabel}[edition]`
|
|
1487
1547
|
);
|
|
1488
1548
|
return import_v45.default.array(looseItemSchema).transform((items, ctx) => {
|
|
@@ -1523,6 +1583,15 @@ var makeReferralProgramEditionConfigSetArraySchema = (valueLabel = "ReferralProg
|
|
|
1523
1583
|
}
|
|
1524
1584
|
slugs.add(edition.slug);
|
|
1525
1585
|
}
|
|
1586
|
+
const overlap = findOverlappingEditionPair(result);
|
|
1587
|
+
if (overlap) {
|
|
1588
|
+
const [a, b] = overlap;
|
|
1589
|
+
ctx.addIssue({
|
|
1590
|
+
code: "custom",
|
|
1591
|
+
message: `${valueLabel}: editions "${a.slug}" and "${b.slug}" have overlapping time ranges for subregistryId ${a.rules.subregistryId.chainId}:${a.rules.subregistryId.address} (startTime and endTime are inclusive)`
|
|
1592
|
+
});
|
|
1593
|
+
return [];
|
|
1594
|
+
}
|
|
1526
1595
|
return result;
|
|
1527
1596
|
});
|
|
1528
1597
|
};
|
|
@@ -1563,6 +1632,15 @@ var makeReferralProgramEditionSummarySchema = (valueLabel = "ReferralProgramEdit
|
|
|
1563
1632
|
};
|
|
1564
1633
|
var makeReferralProgramEditionSummariesDataSchema = (valueLabel = "ReferralProgramEditionSummariesData") => import_v45.default.object({
|
|
1565
1634
|
editions: import_v45.default.array(makeReferralProgramEditionSummarySchema(`${valueLabel}.editions[edition]`))
|
|
1635
|
+
}).superRefine((data, ctx) => {
|
|
1636
|
+
const overlap = findOverlappingEditionPair(data.editions);
|
|
1637
|
+
if (!overlap) return;
|
|
1638
|
+
const [a, b] = overlap;
|
|
1639
|
+
ctx.addIssue({
|
|
1640
|
+
code: "custom",
|
|
1641
|
+
path: ["editions"],
|
|
1642
|
+
message: `${valueLabel}: editions "${a.slug}" and "${b.slug}" have overlapping time ranges for subregistryId ${a.rules.subregistryId.chainId}:${a.rules.subregistryId.address} (startTime and endTime are inclusive)`
|
|
1643
|
+
});
|
|
1566
1644
|
});
|
|
1567
1645
|
var makeReferralProgramEditionSummariesResponseOkSchema = (valueLabel = "ReferralProgramEditionSummariesResponseOk") => import_v45.default.object({
|
|
1568
1646
|
responseCode: import_v45.default.literal(ReferralProgramEditionSummariesResponseCodes.Ok),
|
|
@@ -2042,31 +2120,6 @@ var buildAggregatedReferrerMetricsPieSplit = (referrers, rules) => {
|
|
|
2042
2120
|
return result;
|
|
2043
2121
|
};
|
|
2044
2122
|
|
|
2045
|
-
// src/edition.ts
|
|
2046
|
-
var REFERRAL_PROGRAM_EDITION_SLUG_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
2047
|
-
function validateReferralProgramEditionConfigSet(configSet) {
|
|
2048
|
-
const violation = Array.from(configSet.entries()).find(([key, config]) => key !== config.slug);
|
|
2049
|
-
if (violation) {
|
|
2050
|
-
const [key, config] = violation;
|
|
2051
|
-
throw new Error(
|
|
2052
|
-
`Edition config set invariant violation: map key "${key}" does not match config.slug "${config.slug}"`
|
|
2053
|
-
);
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2056
|
-
function buildReferralProgramEditionConfigSet(configs) {
|
|
2057
|
-
const slugCounts = configs.reduce((counts, config) => {
|
|
2058
|
-
counts.set(config.slug, (counts.get(config.slug) || 0) + 1);
|
|
2059
|
-
return counts;
|
|
2060
|
-
}, /* @__PURE__ */ new Map());
|
|
2061
|
-
const duplicates = Array.from(slugCounts.entries()).filter(([_, count]) => count > 1).map(([slug, count]) => `"${slug}" (${count} occurrences)`);
|
|
2062
|
-
if (duplicates.length > 0) {
|
|
2063
|
-
throw new Error(`Duplicate edition config slugs detected: ${duplicates.join(", ")}`);
|
|
2064
|
-
}
|
|
2065
|
-
const configSet = new Map(configs.map((config) => [config.slug, config]));
|
|
2066
|
-
validateReferralProgramEditionConfigSet(configSet);
|
|
2067
|
-
return configSet;
|
|
2068
|
-
}
|
|
2069
|
-
|
|
2070
2123
|
// src/award-models/shared/edition-summary.ts
|
|
2071
2124
|
var validateBaseReferralProgramEditionSummary = (summary) => {
|
|
2072
2125
|
if (!REFERRAL_PROGRAM_EDITION_SLUG_PATTERN.test(summary.slug)) {
|