@plasius/economy 0.1.0 → 0.2.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/README.md +7 -1
- package/dist/index.cjs +20 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -46
- package/dist/index.d.ts +48 -46
- package/dist/index.js +20 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,7 +45,13 @@ const restored = parseTokenSubunits(wireAmount); // 50000n
|
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
Non-canonical values such as `"01"`, decimals, exponent notation, and values
|
|
48
|
-
outside signed PostgreSQL `bigint` range are rejected.
|
|
48
|
+
outside signed PostgreSQL `bigint` range are rejected. Runtime validators also
|
|
49
|
+
reject non-string JSON values rather than coercing numbers into wire amounts.
|
|
50
|
+
|
|
51
|
+
`ActivityEntryV1` contains both a stable `source` (`shopify`, `ayet`, `bitlabs`,
|
|
52
|
+
`subscription`, `event`, `competition`, or `adjustment`) and a bounded
|
|
53
|
+
display-oriented `sourceLabel`. Filters and reconciliation must use `source`;
|
|
54
|
+
localized UI must use `sourceLabel`.
|
|
49
55
|
|
|
50
56
|
## Baseline GBP catalog
|
|
51
57
|
|
package/dist/index.cjs
CHANGED
|
@@ -119,7 +119,7 @@ function assertInRange(amount) {
|
|
|
119
119
|
}
|
|
120
120
|
function parseTokenSubunits(value) {
|
|
121
121
|
economyAssert(
|
|
122
|
-
CANONICAL_INTEGER.test(value),
|
|
122
|
+
typeof value === "string" && CANONICAL_INTEGER.test(value),
|
|
123
123
|
"INVALID_AMOUNT",
|
|
124
124
|
"TokenSubunit amount must be a canonical base-10 integer string"
|
|
125
125
|
);
|
|
@@ -168,12 +168,17 @@ var ECONOMY_CONTRACT_VERSION = "1";
|
|
|
168
168
|
var IDENTIFIER = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
|
|
169
169
|
function assertEconomyIdentifier(value, label = "identifier") {
|
|
170
170
|
economyAssert(
|
|
171
|
-
IDENTIFIER.test(value),
|
|
171
|
+
typeof value === "string" && IDENTIFIER.test(value),
|
|
172
172
|
"INVALID_CONTRACT",
|
|
173
173
|
`${label} must be a non-empty opaque identifier`
|
|
174
174
|
);
|
|
175
175
|
}
|
|
176
176
|
function parseIsoTimestamp(value) {
|
|
177
|
+
economyAssert(
|
|
178
|
+
typeof value === "string",
|
|
179
|
+
"INVALID_CONTRACT",
|
|
180
|
+
"Timestamp must be an ISO-8601 UTC value"
|
|
181
|
+
);
|
|
177
182
|
const match = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{3}))?Z$/u.exec(
|
|
178
183
|
value
|
|
179
184
|
);
|
|
@@ -895,6 +900,15 @@ var ACTIVITY_STATUSES = /* @__PURE__ */ new Set([
|
|
|
895
900
|
"reversed",
|
|
896
901
|
"failed"
|
|
897
902
|
]);
|
|
903
|
+
var ACTIVITY_SOURCES = /* @__PURE__ */ new Set([
|
|
904
|
+
"shopify",
|
|
905
|
+
"ayet",
|
|
906
|
+
"bitlabs",
|
|
907
|
+
"subscription",
|
|
908
|
+
"event",
|
|
909
|
+
"competition",
|
|
910
|
+
"adjustment"
|
|
911
|
+
]);
|
|
898
912
|
function assertCanonicalHash(value, label) {
|
|
899
913
|
economyAssert(
|
|
900
914
|
/^sha256:[a-f0-9]{64}$/u.test(value),
|
|
@@ -916,9 +930,9 @@ function assertActivityEntry(entry) {
|
|
|
916
930
|
);
|
|
917
931
|
assertEconomyIdentifier(entry.transactionId, "transactionId");
|
|
918
932
|
economyAssert(
|
|
919
|
-
ACTIVITY_TYPES.has(entry.activityType) && ACTIVITY_STATUSES.has(entry.status),
|
|
933
|
+
ACTIVITY_TYPES.has(entry.activityType) && ACTIVITY_STATUSES.has(entry.status) && ACTIVITY_SOURCES.has(entry.source),
|
|
920
934
|
"INVALID_CONTRACT",
|
|
921
|
-
"Activity type or
|
|
935
|
+
"Activity type, status, or source is unsupported"
|
|
922
936
|
);
|
|
923
937
|
parseIsoTimestamp(entry.occurredAt);
|
|
924
938
|
economyAssert(
|
|
@@ -934,13 +948,13 @@ function assertActivityEntry(entry) {
|
|
|
934
948
|
}
|
|
935
949
|
if (entry.maskedReference !== void 0) {
|
|
936
950
|
economyAssert(
|
|
937
|
-
entry.maskedReference.length > 0 && entry.maskedReference.length <= 128 && !hasControlCharacters(entry.maskedReference),
|
|
951
|
+
typeof entry.maskedReference === "string" && entry.maskedReference.length > 0 && entry.maskedReference.length <= 128 && !hasControlCharacters(entry.maskedReference),
|
|
938
952
|
"INVALID_CONTRACT",
|
|
939
953
|
"Masked activity references must be bounded and safe for display"
|
|
940
954
|
);
|
|
941
955
|
}
|
|
942
956
|
economyAssert(
|
|
943
|
-
entry.sourceLabel.trim().length > 0 && entry.sourceLabel.length <= 128 && !hasControlCharacters(entry.sourceLabel),
|
|
957
|
+
typeof entry.sourceLabel === "string" && entry.sourceLabel.trim().length > 0 && entry.sourceLabel.length <= 128 && !hasControlCharacters(entry.sourceLabel),
|
|
944
958
|
"INVALID_CONTRACT",
|
|
945
959
|
"Activity source labels must be bounded and safe for display"
|
|
946
960
|
);
|