@plasius/economy 0.10.0 → 0.11.1

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.cts CHANGED
@@ -1229,7 +1229,7 @@ interface EconomyIdPort {
1229
1229
 
1230
1230
  /** Additive authoritative command types; legacy V1/V2 command unions stay unchanged. */
1231
1231
  type EconomyAuditedCommandTypeV1 = EconomyCommandType | "initialize-wallet" | "initialize-admin-reporting";
1232
- type EconomyCommandSourceV1 = "browser" | "shopify" | "ayet" | "bitlabs" | "operator" | "system";
1232
+ type EconomyCommandSourceV1 = "browser" | "shopify" | "ayet" | "bitlabs" | "google-ad-manager" | "operator" | "system";
1233
1233
  type EconomyCommandProcessingModeV1 = "initial" | "replay";
1234
1234
  type EconomyPrincipalTypeV1 = "account" | "delegated-child" | "service" | "operator";
1235
1235
  type EconomyCausationKindV1 = "provider-event" | "economy-command" | "ledger-transaction" | "workflow-event" | "authority-commit";
@@ -1298,7 +1298,7 @@ interface AuditedEconomyCommandEnvelopeV1 {
1298
1298
  readonly acceptedRegion: string;
1299
1299
  readonly writerFencingToken: string;
1300
1300
  }
1301
- type EconomyAcquisitionProviderV1 = "shopify" | "ayet" | "bitlabs";
1301
+ type EconomyAcquisitionProviderV1 = "shopify" | "ayet" | "bitlabs" | "google-ad-manager";
1302
1302
  /**
1303
1303
  * Privacy-minimized verified provider evidence. Every value derived from a raw
1304
1304
  * provider identifier or callback body is represented by a domain-separated
@@ -1315,8 +1315,17 @@ interface EconomyProviderEvidenceHashV1 {
1315
1315
  readonly eventType: string;
1316
1316
  readonly payloadFingerprint: EconomyHmacFingerprintV1;
1317
1317
  readonly reconciliationEvidenceFingerprint?: EconomyHmacFingerprintV1;
1318
- readonly signatureScheme: string;
1319
- readonly signatureVerifiedAt: IsoTimestamp;
1318
+ /** Legacy/signed-callback verification fields; both must be present together. */
1319
+ readonly signatureScheme?: string;
1320
+ readonly signatureVerifiedAt?: IsoTimestamp;
1321
+ /**
1322
+ * Additive discriminator. Omitted legacy evidence remains provider-signed.
1323
+ * Google final reports must use authenticated retrieval, never a fabricated
1324
+ * provider-signature claim.
1325
+ */
1326
+ readonly verificationMode?: "provider-signature" | "authenticated-retrieval";
1327
+ readonly authenticatedRetrievalScheme?: string;
1328
+ readonly authenticatedRetrievedAt?: IsoTimestamp;
1320
1329
  readonly providerOccurredAt?: IsoTimestamp;
1321
1330
  readonly receivedAt: IsoTimestamp;
1322
1331
  readonly operationalHandleBindingId?: string;
package/dist/index.d.ts CHANGED
@@ -1229,7 +1229,7 @@ interface EconomyIdPort {
1229
1229
 
1230
1230
  /** Additive authoritative command types; legacy V1/V2 command unions stay unchanged. */
1231
1231
  type EconomyAuditedCommandTypeV1 = EconomyCommandType | "initialize-wallet" | "initialize-admin-reporting";
1232
- type EconomyCommandSourceV1 = "browser" | "shopify" | "ayet" | "bitlabs" | "operator" | "system";
1232
+ type EconomyCommandSourceV1 = "browser" | "shopify" | "ayet" | "bitlabs" | "google-ad-manager" | "operator" | "system";
1233
1233
  type EconomyCommandProcessingModeV1 = "initial" | "replay";
1234
1234
  type EconomyPrincipalTypeV1 = "account" | "delegated-child" | "service" | "operator";
1235
1235
  type EconomyCausationKindV1 = "provider-event" | "economy-command" | "ledger-transaction" | "workflow-event" | "authority-commit";
@@ -1298,7 +1298,7 @@ interface AuditedEconomyCommandEnvelopeV1 {
1298
1298
  readonly acceptedRegion: string;
1299
1299
  readonly writerFencingToken: string;
1300
1300
  }
1301
- type EconomyAcquisitionProviderV1 = "shopify" | "ayet" | "bitlabs";
1301
+ type EconomyAcquisitionProviderV1 = "shopify" | "ayet" | "bitlabs" | "google-ad-manager";
1302
1302
  /**
1303
1303
  * Privacy-minimized verified provider evidence. Every value derived from a raw
1304
1304
  * provider identifier or callback body is represented by a domain-separated
@@ -1315,8 +1315,17 @@ interface EconomyProviderEvidenceHashV1 {
1315
1315
  readonly eventType: string;
1316
1316
  readonly payloadFingerprint: EconomyHmacFingerprintV1;
1317
1317
  readonly reconciliationEvidenceFingerprint?: EconomyHmacFingerprintV1;
1318
- readonly signatureScheme: string;
1319
- readonly signatureVerifiedAt: IsoTimestamp;
1318
+ /** Legacy/signed-callback verification fields; both must be present together. */
1319
+ readonly signatureScheme?: string;
1320
+ readonly signatureVerifiedAt?: IsoTimestamp;
1321
+ /**
1322
+ * Additive discriminator. Omitted legacy evidence remains provider-signed.
1323
+ * Google final reports must use authenticated retrieval, never a fabricated
1324
+ * provider-signature claim.
1325
+ */
1326
+ readonly verificationMode?: "provider-signature" | "authenticated-retrieval";
1327
+ readonly authenticatedRetrievalScheme?: string;
1328
+ readonly authenticatedRetrievedAt?: IsoTimestamp;
1320
1329
  readonly providerOccurredAt?: IsoTimestamp;
1321
1330
  readonly receivedAt: IsoTimestamp;
1322
1331
  readonly operationalHandleBindingId?: string;
package/dist/index.js CHANGED
@@ -1903,6 +1903,7 @@ var COMMAND_SOURCES = /* @__PURE__ */ new Set([
1903
1903
  "shopify",
1904
1904
  "ayet",
1905
1905
  "bitlabs",
1906
+ "google-ad-manager",
1906
1907
  "operator",
1907
1908
  "system"
1908
1909
  ]);
@@ -1915,7 +1916,8 @@ var PRINCIPAL_TYPES = /* @__PURE__ */ new Set([
1915
1916
  var PROVIDER_SOURCES = /* @__PURE__ */ new Set([
1916
1917
  "shopify",
1917
1918
  "ayet",
1918
- "bitlabs"
1919
+ "bitlabs",
1920
+ "google-ad-manager"
1919
1921
  ]);
1920
1922
  var CAUSATION_KINDS = /* @__PURE__ */ new Set([
1921
1923
  "provider-event",
@@ -1927,7 +1929,8 @@ var CAUSATION_KINDS = /* @__PURE__ */ new Set([
1927
1929
  var PROVIDERS = /* @__PURE__ */ new Set([
1928
1930
  "shopify",
1929
1931
  "ayet",
1930
- "bitlabs"
1932
+ "bitlabs",
1933
+ "google-ad-manager"
1931
1934
  ]);
1932
1935
  var FINGERPRINT_DOMAINS = /* @__PURE__ */ new Set([
1933
1936
  "economy.idempotency-key.v1",
@@ -1957,6 +1960,12 @@ var SOURCE_COMMAND_TYPES = {
1957
1960
  ]),
1958
1961
  ayet: /* @__PURE__ */ new Set(["credit-reward", "hold", "release-hold", "reverse"]),
1959
1962
  bitlabs: /* @__PURE__ */ new Set(["credit-reward", "hold", "release-hold", "reverse"]),
1963
+ "google-ad-manager": /* @__PURE__ */ new Set([
1964
+ "credit-reward",
1965
+ "hold",
1966
+ "release-hold",
1967
+ "reverse"
1968
+ ]),
1960
1969
  operator: /* @__PURE__ */ new Set(["adjust", "reverse", "hold", "release-hold"]),
1961
1970
  system: /* @__PURE__ */ new Set([
1962
1971
  "credit-event",
@@ -2230,6 +2239,9 @@ function assertEconomyProviderEvidenceHash(evidence) {
2230
2239
  "reconciliationEvidenceFingerprint",
2231
2240
  "signatureScheme",
2232
2241
  "signatureVerifiedAt",
2242
+ "verificationMode",
2243
+ "authenticatedRetrievalScheme",
2244
+ "authenticatedRetrievedAt",
2233
2245
  "providerOccurredAt",
2234
2246
  "receivedAt",
2235
2247
  "operationalHandleBindingId"
@@ -2264,9 +2276,27 @@ function assertEconomyProviderEvidenceHash(evidence) {
2264
2276
  );
2265
2277
  }
2266
2278
  assertSafeClassifier(evidence.eventType, "Provider event type");
2267
- assertSafeClassifier(evidence.signatureScheme, "Provider signature scheme");
2268
- const signatureVerifiedAt = parseIsoTimestamp(evidence.signatureVerifiedAt);
2269
2279
  const receivedAt = parseIsoTimestamp(evidence.receivedAt);
2280
+ const signatureFieldsPresent = evidence.signatureScheme !== void 0 && evidence.signatureVerifiedAt !== void 0;
2281
+ const retrievalFieldsPresent = evidence.authenticatedRetrievalScheme !== void 0 && evidence.authenticatedRetrievedAt !== void 0;
2282
+ const verificationMode = evidence.verificationMode ?? "provider-signature";
2283
+ economyAssert(
2284
+ verificationMode === "provider-signature" && evidence.provider !== "google-ad-manager" && signatureFieldsPresent && !retrievalFieldsPresent && evidence.authenticatedRetrievalScheme === void 0 && evidence.authenticatedRetrievedAt === void 0 || verificationMode === "authenticated-retrieval" && evidence.provider === "google-ad-manager" && retrievalFieldsPresent && evidence.signatureScheme === void 0 && evidence.signatureVerifiedAt === void 0,
2285
+ "INVALID_CONTRACT",
2286
+ "Provider evidence must use exactly one permitted verification method"
2287
+ );
2288
+ const verifiedAt = verificationMode === "provider-signature" ? evidence.signatureVerifiedAt : evidence.authenticatedRetrievedAt;
2289
+ if (verificationMode === "provider-signature") {
2290
+ assertSafeClassifier(
2291
+ evidence.signatureScheme,
2292
+ "Provider signature scheme"
2293
+ );
2294
+ } else {
2295
+ assertSafeClassifier(
2296
+ evidence.authenticatedRetrievalScheme,
2297
+ "Provider authenticated-retrieval scheme"
2298
+ );
2299
+ }
2270
2300
  if (evidence.providerOccurredAt !== void 0) {
2271
2301
  economyAssert(
2272
2302
  parseIsoTimestamp(evidence.providerOccurredAt) <= receivedAt,
@@ -2275,9 +2305,9 @@ function assertEconomyProviderEvidenceHash(evidence) {
2275
2305
  );
2276
2306
  }
2277
2307
  economyAssert(
2278
- receivedAt >= signatureVerifiedAt,
2308
+ receivedAt >= parseIsoTimestamp(verifiedAt),
2279
2309
  "INVALID_TIME_WINDOW",
2280
- "Provider evidence cannot be received before signature verification"
2310
+ "Provider evidence cannot be received before verification"
2281
2311
  );
2282
2312
  if (evidence.operationalHandleBindingId !== void 0) {
2283
2313
  assertEconomyIdentifier(
@@ -2627,8 +2657,13 @@ function canonicalEconomyProviderEvidenceHashPayload(evidence) {
2627
2657
  evidence.reconciliationEvidenceFingerprint
2628
2658
  )
2629
2659
  },
2630
- signatureScheme: evidence.signatureScheme,
2631
- signatureVerifiedAt: evidence.signatureVerifiedAt,
2660
+ ...evidence.verificationMode === void 0 ? {} : { verificationMode: evidence.verificationMode },
2661
+ ...evidence.signatureScheme === void 0 ? {} : { signatureScheme: evidence.signatureScheme },
2662
+ ...evidence.signatureVerifiedAt === void 0 ? {} : { signatureVerifiedAt: evidence.signatureVerifiedAt },
2663
+ ...evidence.authenticatedRetrievalScheme === void 0 ? {} : {
2664
+ authenticatedRetrievalScheme: evidence.authenticatedRetrievalScheme
2665
+ },
2666
+ ...evidence.authenticatedRetrievedAt === void 0 ? {} : { authenticatedRetrievedAt: evidence.authenticatedRetrievedAt },
2632
2667
  ...evidence.providerOccurredAt === void 0 ? {} : { providerOccurredAt: evidence.providerOccurredAt },
2633
2668
  receivedAt: evidence.receivedAt,
2634
2669
  ...evidence.operationalHandleBindingId === void 0 ? {} : {
@@ -3682,6 +3717,15 @@ function assertReversalAvailable(originalTransactionId, existingTransactions) {
3682
3717
  }
3683
3718
 
3684
3719
  // src/audit-graph.ts
3720
+ var PROVIDER_COMMAND_SOURCES = /* @__PURE__ */ new Set([
3721
+ "shopify",
3722
+ "ayet",
3723
+ "bitlabs",
3724
+ "google-ad-manager"
3725
+ ]);
3726
+ function isProviderCommandSource(source) {
3727
+ return PROVIDER_COMMAND_SOURCES.has(source);
3728
+ }
3685
3729
  function assertCanonicalHash4(value, label) {
3686
3730
  economyAssert(
3687
3731
  typeof value === "string" && /^sha256:[a-f0-9]{64}$/u.test(value),
@@ -3709,7 +3753,7 @@ function assertCreatedReference(manifest, kind, id, contentHash) {
3709
3753
  }
3710
3754
  function assertProviderGraph(graph, hash, acceptanceCommit) {
3711
3755
  const envelope = graph.commandEnvelope;
3712
- const providerSource = envelope.commandSource === "shopify" || envelope.commandSource === "ayet" || envelope.commandSource === "bitlabs";
3756
+ const providerSource = isProviderCommandSource(envelope.commandSource);
3713
3757
  if (!providerSource) {
3714
3758
  economyAssert(
3715
3759
  graph.providerEvidenceManifest === void 0 && graph.providerEvidence.length === 0 && graph.operationalHandleBindings.length === 0,
@@ -3856,7 +3900,7 @@ function expectedTransactionActivityTypes(envelope) {
3856
3900
  }
3857
3901
  if (envelope.commandType === "credit-reward") {
3858
3902
  return /* @__PURE__ */ new Set([
3859
- envelope.commandSource === "ayet" ? "rewarded-ad" : "offerwall"
3903
+ envelope.commandSource === "ayet" || envelope.commandSource === "google-ad-manager" ? "rewarded-ad" : "offerwall"
3860
3904
  ]);
3861
3905
  }
3862
3906
  if (envelope.commandType === "credit-event") {
@@ -3911,7 +3955,7 @@ function assertReceiptGraph(graph, commandEnvelopeHash, hash, acceptanceCommit,
3911
3955
  accepted.receiptId,
3912
3956
  acceptedHash
3913
3957
  );
3914
- const providerSource = envelope.commandSource === "shopify" || envelope.commandSource === "ayet" || envelope.commandSource === "bitlabs";
3958
+ const providerSource = isProviderCommandSource(envelope.commandSource);
3915
3959
  if (graph.resultReceipt === void 0) {
3916
3960
  economyAssert(
3917
3961
  providerSource && graph.transaction === void 0 && resultCommit === void 0,
@@ -4031,7 +4075,9 @@ function assertAuthorityCommits(graph, hash) {
4031
4075
  "INVALID_CONTRACT",
4032
4076
  "Authority commits do not reconstruct the expected authority head"
4033
4077
  );
4034
- const providerSource = graph.commandEnvelope.commandSource === "shopify" || graph.commandEnvelope.commandSource === "ayet" || graph.commandEnvelope.commandSource === "bitlabs";
4078
+ const providerSource = isProviderCommandSource(
4079
+ graph.commandEnvelope.commandSource
4080
+ );
4035
4081
  const acceptanceKind = providerSource ? "provider-acceptance" : "first-party-command";
4036
4082
  const acceptanceCommit = graph.commits.find(
4037
4083
  (commit) => commit.manifest.commitKind === acceptanceKind