@mpgd/game-services 0.23.0 → 0.24.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.
@@ -1,32 +0,0 @@
1
- import type { PlatformGateway, PurchaseResult } from '@mpgd/platform';
2
- export interface AdapterSettledGrant {
3
- readonly ledgerEntryId: string;
4
- readonly alreadyProcessed?: boolean;
5
- }
6
- /**
7
- * Internal: the ledger grant a checkout result already carries, or undefined
8
- * when the backend must verify. A gateway with a commerce v2 provider decides
9
- * from the provider's capability block (RFC "Capabilities":
10
- * `authority.evidence: 'adapter-settled'`) plus the result's
11
- * `authoritativeGrant`; a provider whose capabilities cannot be read, or that
12
- * declares any other evidence, answers undefined so the client verifies. A
13
- * gateway without a v2 provider keeps the deprecated target-name rule until
14
- * C4 removes it.
15
- */
16
- export declare function findAdapterSettledGrant(input: {
17
- readonly gateway: Pick<PlatformGateway, 'commerceV2'>;
18
- readonly target: string;
19
- readonly purchase: PurchaseResult;
20
- }): Promise<AdapterSettledGrant | undefined>;
21
- /**
22
- * Internal: the Microsoft Store adapter completes the ledger grant before it returns this
23
- * checkout result, so no further backend verification is requested for it.
24
- *
25
- * @deprecated Settlement is declared by the commerce v2 capability block; use
26
- * `findAdapterSettledGrant`, which reads it on gateways that expose `commerceV2`. Kept for
27
- * gateways that still install only the v1 `createMicrosoftStoreCommerceAdapter`; C4 removes it.
28
- */
29
- export declare function isAuthoritativeMicrosoftStoreCompletion(target: string, purchase: PurchaseResult): purchase is PurchaseResult & {
30
- readonly status: 'completed';
31
- readonly transactionId: string;
32
- };
@@ -1,62 +0,0 @@
1
- /**
2
- * Internal: the ledger grant a checkout result already carries, or undefined
3
- * when the backend must verify. A gateway with a commerce v2 provider decides
4
- * from the provider's capability block (RFC "Capabilities":
5
- * `authority.evidence: 'adapter-settled'`) plus the result's
6
- * `authoritativeGrant`; a provider whose capabilities cannot be read, or that
7
- * declares any other evidence, answers undefined so the client verifies. A
8
- * gateway without a v2 provider keeps the deprecated target-name rule until
9
- * C4 removes it.
10
- */
11
- export async function findAdapterSettledGrant(input) {
12
- const { purchase } = input;
13
- const grant = purchase.authoritativeGrant;
14
- if (purchase.status !== 'completed' || purchase.transactionId === undefined || grant === undefined) {
15
- return undefined;
16
- }
17
- const provider = input.gateway.commerceV2;
18
- const settled = provider === undefined
19
- ? isAuthoritativeMicrosoftStoreCompletion(input.target, purchase)
20
- : (await readEvidenceAuthority(provider)) === 'adapter-settled';
21
- if (!settled) {
22
- return undefined;
23
- }
24
- return {
25
- ledgerEntryId: grant.ledgerEntryId,
26
- ...(grant.alreadyProcessed === undefined ? {} : { alreadyProcessed: grant.alreadyProcessed }),
27
- };
28
- }
29
- /**
30
- * A provider's `authority.evidence` declaration is fixed for its lifetime, so
31
- * one successful read serves every later checkout; a failed read is not
32
- * cached, and the next checkout probes again.
33
- */
34
- const evidenceAuthorityByProvider = new WeakMap();
35
- async function readEvidenceAuthority(provider) {
36
- const cached = evidenceAuthorityByProvider.get(provider);
37
- if (cached !== undefined) {
38
- return cached;
39
- }
40
- try {
41
- const { evidence } = (await provider.getCapabilities()).authority;
42
- evidenceAuthorityByProvider.set(provider, evidence);
43
- return evidence;
44
- }
45
- catch {
46
- return undefined;
47
- }
48
- }
49
- /**
50
- * Internal: the Microsoft Store adapter completes the ledger grant before it returns this
51
- * checkout result, so no further backend verification is requested for it.
52
- *
53
- * @deprecated Settlement is declared by the commerce v2 capability block; use
54
- * `findAdapterSettledGrant`, which reads it on gateways that expose `commerceV2`. Kept for
55
- * gateways that still install only the v1 `createMicrosoftStoreCommerceAdapter`; C4 removes it.
56
- */
57
- export function isAuthoritativeMicrosoftStoreCompletion(target, purchase) {
58
- return target === 'microsoft-store'
59
- && purchase.status === 'completed'
60
- && purchase.transactionId !== undefined
61
- && purchase.authoritativeGrant?.ledgerEntryId === purchase.transactionId;
62
- }