@atmosphere-money/testing 0.0.0-beta.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/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## 0.0.0-beta.0
4
+
5
+ - Initial closed-beta testing package for ATM app integrations.
6
+ - Adds signed webhook fixtures and request helpers for route tests.
7
+ - Adds dedicated fixtures for payment completion, failure, refund, dispute,
8
+ product archive, subscription update, ticket issuance, and ticket check-in.
9
+ - Adds a generic event fixture for all documented ATM event types.
10
+ - Adds replay-store helpers and idempotency-key helpers.
11
+ - Adds package release checks, API snapshot checks, and dry-run tarball validation.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Atmosphere Money
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # @atmosphere-money/testing
2
+
3
+ Testing fixtures and assertions for Atmosphere Money app integrations.
4
+
5
+ This package is for app test suites. It creates signed ATM webhook fixtures,
6
+ sample payment/subscription/ticket events, generic event fixtures,
7
+ replay-store helpers, and idempotency-key helpers so apps can test fulfillment
8
+ without calling Stripe or ATM production services.
9
+
10
+ ## Status
11
+
12
+ `@atmosphere-money/testing` is the planned dev-only testing package for ATM app
13
+ integrations. Until npm publishing is enabled, closed-beta apps install it from
14
+ a local checkout or private tarball.
15
+
16
+ ## Install during closed beta
17
+
18
+ ```sh
19
+ npm install ../path/to/atmosphere-money/packages/testing
20
+ ```
21
+
22
+ When published:
23
+
24
+ ```sh
25
+ npm install -D @atmosphere-money/testing
26
+ ```
27
+
28
+ ## Signed webhook fixture
29
+
30
+ ```ts
31
+ import {
32
+ ATM_TEST_WEBHOOK_SECRET,
33
+ createPaymentCompletedFixture,
34
+ } from "@atmosphere-money/testing";
35
+ import { constructTypedAtmWebhookEvent } from "@atmosphere-money/app-node";
36
+
37
+ const fixture = createPaymentCompletedFixture({
38
+ payment: {
39
+ id: "pay_test_123",
40
+ metadata: { appOrderId: "ord_123" },
41
+ },
42
+ });
43
+
44
+ const event = constructTypedAtmWebhookEvent({
45
+ rawBody: fixture.rawBody,
46
+ secret: ATM_TEST_WEBHOOK_SECRET,
47
+ expectedType: "payment.completed",
48
+ now: fixture.event.created,
49
+ headers: {
50
+ signature: fixture.headers["atm-signature"],
51
+ deliveryId: fixture.headers["atm-delivery-id"],
52
+ event: fixture.headers["atm-event"],
53
+ apiVersion: fixture.headers["atm-api-version"],
54
+ environment: fixture.headers["atm-environment"],
55
+ },
56
+ });
57
+ ```
58
+
59
+ ## Request helper
60
+
61
+ Use `createAtmWebhookRequest` when your route tests expect a real Web
62
+ `Request`.
63
+
64
+ ```ts
65
+ import {
66
+ ATM_TEST_WEBHOOK_SECRET,
67
+ createAtmWebhookRequest,
68
+ createPaymentCompletedFixture,
69
+ } from "@atmosphere-money/testing";
70
+ import { createNodeWebhookHandler } from "@atmosphere-money/app-node";
71
+
72
+ const fixture = createPaymentCompletedFixture();
73
+ const request = createAtmWebhookRequest(fixture);
74
+
75
+ const handler = createNodeWebhookHandler({
76
+ secret: ATM_TEST_WEBHOOK_SECRET,
77
+ expectedType: "payment.completed",
78
+ onEvent: async (event) => {
79
+ const metadata = event.data.payment.metadata as
80
+ | { appOrderId?: string }
81
+ | undefined;
82
+ await markOrderPaid(String(metadata?.appOrderId ?? ""));
83
+ },
84
+ });
85
+
86
+ const response = await handler(request);
87
+ ```
88
+
89
+ ## Replay helper
90
+
91
+ ```ts
92
+ import {
93
+ assertFreshDelivery,
94
+ createMemoryReplayStore,
95
+ } from "@atmosphere-money/testing";
96
+
97
+ const replayStore = createMemoryReplayStore();
98
+ await assertFreshDelivery(replayStore, "del_payment_completed_fixture");
99
+ ```
100
+
101
+ ## Generic event fixture
102
+
103
+ Use `createAtmEventFixture` for documented events that do not need a dedicated
104
+ factory.
105
+
106
+ ```ts
107
+ import { createAtmEventFixture } from "@atmosphere-money/testing";
108
+
109
+ const archived = createAtmEventFixture({
110
+ type: "product.archived",
111
+ data: {
112
+ productUri: "at://did:plc:creator/money.atmosphere.product/product_123",
113
+ appDid: "did:plc:app",
114
+ },
115
+ });
116
+ ```
117
+
118
+ ## Common event fixtures
119
+
120
+ Use dedicated factories for events most apps branch on during fulfillment,
121
+ support, and operations.
122
+
123
+ ```ts
124
+ import {
125
+ createPaymentDisputedFixture,
126
+ createPaymentFailedFixture,
127
+ createPaymentRefundedFixture,
128
+ createProductArchivedFixture,
129
+ createTicketCheckedInFixture,
130
+ } from "@atmosphere-money/testing";
131
+
132
+ const failedPayment = createPaymentFailedFixture({
133
+ payment: { failureCode: "card_declined" },
134
+ });
135
+ const refundedPayment = createPaymentRefundedFixture({
136
+ payment: { refundedAmountCents: 500 },
137
+ });
138
+ const disputedPayment = createPaymentDisputedFixture({
139
+ payment: { disputeStatus: "under_review" },
140
+ });
141
+ const archivedProduct = createProductArchivedFixture();
142
+ const checkedInTicket = createTicketCheckedInFixture();
143
+ ```
144
+
145
+ ## Included fixtures
146
+
147
+ - `createAtmEventFixture`
148
+ - `createPaymentCompletedFixture`
149
+ - `createPaymentFailedFixture`
150
+ - `createPaymentRefundedFixture`
151
+ - `createPaymentDisputedFixture`
152
+ - `createProductArchivedFixture`
153
+ - `createSubscriptionUpdatedFixture`
154
+ - `createTicketCheckedInFixture`
155
+ - `createTicketsIssuedFixture`
156
+ - `signAtmFixture`
157
+ - `createAtmWebhookRequest`
158
+ - `createMemoryReplayStore`
159
+ - `assertFreshDelivery`
160
+ - `createAtmIdempotencyKey`
161
+
162
+ ## License
163
+
164
+ `@atmosphere-money/testing` is released under the MIT license. The package
165
+ license does not license the rest of the ATM monorepo or hosted platform code.
166
+
167
+ ## Package boundary
168
+
169
+ This package does not mock Stripe, ATM checkout, processor webhooks, or PDS
170
+ writes. It only helps apps test their own webhook/XRPC receiver and fulfillment
171
+ logic with ATM-shaped events.
@@ -0,0 +1,185 @@
1
+ export type AtmTestEnvironment = "test" | "live";
2
+ export type AtmTestWebhookEventType = "app.webhook.test" | "payment.completed" | "payment.failed" | "payment.refunded" | "payment.disputed" | "subscription.invoice_paid" | "subscription.updated" | "subscription.cancelled" | "payer.record.requested" | "creator.proof.requested" | "attestation.updated" | "product.updated" | "product.archived" | "product.deleted" | "ticket.hold.created" | "ticket.hold.expired" | "tickets.issued" | "ticket.voided" | "ticket.refunded" | "ticket.checked_in";
3
+ export type AtmTestWebhookEnvelope<TData = Record<string, unknown>> = {
4
+ id: string;
5
+ type: AtmTestWebhookEventType;
6
+ created: number;
7
+ apiVersion: string;
8
+ environment: AtmTestEnvironment;
9
+ data: TData;
10
+ };
11
+ export type AtmSignedFixture<TData = Record<string, unknown>> = {
12
+ event: AtmTestWebhookEnvelope<TData>;
13
+ rawBody: string;
14
+ headers: {
15
+ "atm-signature": string;
16
+ "atm-delivery-id": string;
17
+ "atm-event": AtmTestWebhookEventType;
18
+ "atm-api-version": string;
19
+ "atm-environment": AtmTestEnvironment;
20
+ };
21
+ };
22
+ export type AtmFixtureRequestOptions = {
23
+ url?: string;
24
+ method?: string;
25
+ headers?: HeadersInit;
26
+ };
27
+ export type AtmPaymentCompletedFixtureData = {
28
+ payment: {
29
+ id: string;
30
+ amountCents: number;
31
+ currency: string;
32
+ status: "completed";
33
+ paymentType: "tip" | "shop" | "commission" | "subscribe" | "ticket";
34
+ payerDid?: string;
35
+ recipientDid: string;
36
+ appDid: string;
37
+ metadata: Record<string, unknown>;
38
+ };
39
+ };
40
+ export type AtmPaymentFailedFixtureData = {
41
+ payment: {
42
+ id: string;
43
+ amountCents: number;
44
+ currency: string;
45
+ status: "failed";
46
+ paymentType: "tip" | "shop" | "commission" | "subscribe" | "ticket";
47
+ payerDid?: string;
48
+ recipientDid: string;
49
+ appDid: string;
50
+ failureCode: string;
51
+ failureMessage: string;
52
+ metadata: Record<string, unknown>;
53
+ };
54
+ };
55
+ export type AtmPaymentRefundedFixtureData = {
56
+ payment: {
57
+ id: string;
58
+ amountCents: number;
59
+ refundedAmountCents: number;
60
+ currency: string;
61
+ status: "refunded";
62
+ paymentType: "tip" | "shop" | "commission" | "subscribe" | "ticket";
63
+ payerDid?: string;
64
+ recipientDid: string;
65
+ appDid: string;
66
+ refundId: string;
67
+ metadata: Record<string, unknown>;
68
+ };
69
+ };
70
+ export type AtmPaymentDisputedFixtureData = {
71
+ payment: {
72
+ id: string;
73
+ amountCents: number;
74
+ currency: string;
75
+ status: "disputed";
76
+ paymentType: "tip" | "shop" | "commission" | "subscribe" | "ticket";
77
+ payerDid?: string;
78
+ recipientDid: string;
79
+ appDid: string;
80
+ disputeId: string;
81
+ disputeStatus: "needs_response" | "under_review" | "won" | "lost";
82
+ metadata: Record<string, unknown>;
83
+ };
84
+ };
85
+ export type AtmSubscriptionUpdatedFixtureData = {
86
+ subscription: {
87
+ id: string;
88
+ status: "active" | "past_due" | "cancelled";
89
+ amountCents: number;
90
+ previousAmountCents?: number;
91
+ currency: string;
92
+ interval: "month" | "quarter" | "year";
93
+ payerDid?: string;
94
+ recipientDid: string;
95
+ appDid: string;
96
+ };
97
+ };
98
+ export type AtmTicketsIssuedFixtureData = {
99
+ eventUri: string;
100
+ holdId: string;
101
+ paymentId?: string;
102
+ buyerDid?: string;
103
+ issuedCount: number;
104
+ tickets: Array<{
105
+ ticketId: string;
106
+ ticketTierId: string;
107
+ status: "issued";
108
+ }>;
109
+ };
110
+ export type AtmProductArchivedFixtureData = {
111
+ product: {
112
+ productUri: string;
113
+ productCid?: string;
114
+ appDid: string;
115
+ creatorDid?: string;
116
+ archivedAt: string;
117
+ metadata: Record<string, unknown>;
118
+ };
119
+ };
120
+ export type AtmTicketCheckedInFixtureData = {
121
+ ticket: {
122
+ ticketId: string;
123
+ ticketTierId: string;
124
+ eventUri: string;
125
+ buyerDid?: string;
126
+ checkInListId: string;
127
+ checkedInAt: string;
128
+ repeat: boolean;
129
+ metadata: Record<string, unknown>;
130
+ };
131
+ };
132
+ export type AtmFixtureOptions = {
133
+ id?: string;
134
+ deliveryId?: string;
135
+ created?: number;
136
+ apiVersion?: string;
137
+ environment?: AtmTestEnvironment;
138
+ secret?: string;
139
+ };
140
+ export type AtmReplayStore = {
141
+ insertOnce(key: string): Promise<boolean> | boolean;
142
+ has?(key: string): Promise<boolean> | boolean;
143
+ };
144
+ export declare const ATM_TEST_WEBHOOK_SECRET = "atm_whsec_test_fixture";
145
+ export declare const ATM_TEST_API_VERSION = "2026-05";
146
+ export declare const ATM_TEST_CREATED = 1780000000;
147
+ export declare function createAtmEventFixture<TData>(options: AtmFixtureOptions & {
148
+ type: AtmTestWebhookEventType;
149
+ data: TData;
150
+ }): AtmSignedFixture<TData>;
151
+ export declare function createPaymentCompletedFixture(options?: AtmFixtureOptions & {
152
+ payment?: Partial<AtmPaymentCompletedFixtureData["payment"]>;
153
+ }): AtmSignedFixture<AtmPaymentCompletedFixtureData>;
154
+ export declare function createPaymentFailedFixture(options?: AtmFixtureOptions & {
155
+ payment?: Partial<AtmPaymentFailedFixtureData["payment"]>;
156
+ }): AtmSignedFixture<AtmPaymentFailedFixtureData>;
157
+ export declare function createPaymentRefundedFixture(options?: AtmFixtureOptions & {
158
+ payment?: Partial<AtmPaymentRefundedFixtureData["payment"]>;
159
+ }): AtmSignedFixture<AtmPaymentRefundedFixtureData>;
160
+ export declare function createPaymentDisputedFixture(options?: AtmFixtureOptions & {
161
+ payment?: Partial<AtmPaymentDisputedFixtureData["payment"]>;
162
+ }): AtmSignedFixture<AtmPaymentDisputedFixtureData>;
163
+ export declare function createSubscriptionUpdatedFixture(options?: AtmFixtureOptions & {
164
+ subscription?: Partial<AtmSubscriptionUpdatedFixtureData["subscription"]>;
165
+ }): AtmSignedFixture<AtmSubscriptionUpdatedFixtureData>;
166
+ export declare function createTicketsIssuedFixture(options?: AtmFixtureOptions & {
167
+ ticket?: Partial<AtmTicketsIssuedFixtureData>;
168
+ }): AtmSignedFixture<AtmTicketsIssuedFixtureData>;
169
+ export declare function createProductArchivedFixture(options?: AtmFixtureOptions & {
170
+ product?: Partial<AtmProductArchivedFixtureData["product"]>;
171
+ }): AtmSignedFixture<AtmProductArchivedFixtureData>;
172
+ export declare function createTicketCheckedInFixture(options?: AtmFixtureOptions & {
173
+ ticket?: Partial<AtmTicketCheckedInFixtureData["ticket"]>;
174
+ }): AtmSignedFixture<AtmTicketCheckedInFixtureData>;
175
+ export declare function signAtmFixture(options: {
176
+ rawBody: string;
177
+ deliveryId: string;
178
+ secret?: string;
179
+ timestamp?: number;
180
+ }): string;
181
+ export declare function createMemoryReplayStore(initialKeys?: Iterable<string>): AtmReplayStore;
182
+ export declare function createAtmWebhookRequest<TData>(fixture: AtmSignedFixture<TData>, options?: AtmFixtureRequestOptions): Request;
183
+ export declare function assertFreshDelivery(store: AtmReplayStore, deliveryId: string): Promise<void>;
184
+ export declare function createAtmIdempotencyKey(parts: Array<string | number | boolean | null | undefined>): string;
185
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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AO,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,MAAM,CAS1G"}
package/dist/index.js ADDED
@@ -0,0 +1,256 @@
1
+ import { createHmac } from "node:crypto";
2
+ export const ATM_TEST_WEBHOOK_SECRET = "atm_whsec_test_fixture";
3
+ export const ATM_TEST_API_VERSION = "2026-05";
4
+ export const ATM_TEST_CREATED = 1_780_000_000;
5
+ export function createAtmEventFixture(options) {
6
+ return createSignedFixture({
7
+ type: options.type,
8
+ options,
9
+ data: options.data,
10
+ });
11
+ }
12
+ export function createPaymentCompletedFixture(options = {}) {
13
+ return createAtmEventFixture({
14
+ type: "payment.completed",
15
+ ...options,
16
+ data: {
17
+ payment: {
18
+ id: options.payment?.id ?? "pay_fixture_123",
19
+ amountCents: options.payment?.amountCents ?? 1200,
20
+ currency: options.payment?.currency ?? "usd",
21
+ status: "completed",
22
+ paymentType: options.payment?.paymentType ?? "shop",
23
+ payerDid: options.payment?.payerDid ?? "did:plc:buyer",
24
+ recipientDid: options.payment?.recipientDid ?? "did:plc:creator",
25
+ appDid: options.payment?.appDid ?? "did:plc:app",
26
+ metadata: options.payment?.metadata ?? { appOrderId: "ord_fixture_123" },
27
+ },
28
+ },
29
+ });
30
+ }
31
+ export function createPaymentFailedFixture(options = {}) {
32
+ return createAtmEventFixture({
33
+ type: "payment.failed",
34
+ ...options,
35
+ data: {
36
+ payment: {
37
+ id: options.payment?.id ?? "pay_fixture_failed",
38
+ amountCents: options.payment?.amountCents ?? 1200,
39
+ currency: options.payment?.currency ?? "usd",
40
+ status: "failed",
41
+ paymentType: options.payment?.paymentType ?? "shop",
42
+ payerDid: options.payment?.payerDid ?? "did:plc:buyer",
43
+ recipientDid: options.payment?.recipientDid ?? "did:plc:creator",
44
+ appDid: options.payment?.appDid ?? "did:plc:app",
45
+ failureCode: options.payment?.failureCode ?? "card_declined",
46
+ failureMessage: options.payment?.failureMessage ?? "The payment was declined.",
47
+ metadata: options.payment?.metadata ?? { appOrderId: "ord_fixture_failed" },
48
+ },
49
+ },
50
+ });
51
+ }
52
+ export function createPaymentRefundedFixture(options = {}) {
53
+ return createAtmEventFixture({
54
+ type: "payment.refunded",
55
+ ...options,
56
+ data: {
57
+ payment: {
58
+ id: options.payment?.id ?? "pay_fixture_refunded",
59
+ amountCents: options.payment?.amountCents ?? 1200,
60
+ refundedAmountCents: options.payment?.refundedAmountCents ?? 1200,
61
+ currency: options.payment?.currency ?? "usd",
62
+ status: "refunded",
63
+ paymentType: options.payment?.paymentType ?? "shop",
64
+ payerDid: options.payment?.payerDid ?? "did:plc:buyer",
65
+ recipientDid: options.payment?.recipientDid ?? "did:plc:creator",
66
+ appDid: options.payment?.appDid ?? "did:plc:app",
67
+ refundId: options.payment?.refundId ?? "ref_fixture_123",
68
+ metadata: options.payment?.metadata ?? { appOrderId: "ord_fixture_refunded" },
69
+ },
70
+ },
71
+ });
72
+ }
73
+ export function createPaymentDisputedFixture(options = {}) {
74
+ return createAtmEventFixture({
75
+ type: "payment.disputed",
76
+ ...options,
77
+ data: {
78
+ payment: {
79
+ id: options.payment?.id ?? "pay_fixture_disputed",
80
+ amountCents: options.payment?.amountCents ?? 1200,
81
+ currency: options.payment?.currency ?? "usd",
82
+ status: "disputed",
83
+ paymentType: options.payment?.paymentType ?? "shop",
84
+ payerDid: options.payment?.payerDid ?? "did:plc:buyer",
85
+ recipientDid: options.payment?.recipientDid ?? "did:plc:creator",
86
+ appDid: options.payment?.appDid ?? "did:plc:app",
87
+ disputeId: options.payment?.disputeId ?? "dp_fixture_123",
88
+ disputeStatus: options.payment?.disputeStatus ?? "needs_response",
89
+ metadata: options.payment?.metadata ?? { appOrderId: "ord_fixture_disputed" },
90
+ },
91
+ },
92
+ });
93
+ }
94
+ export function createSubscriptionUpdatedFixture(options = {}) {
95
+ return createAtmEventFixture({
96
+ type: "subscription.updated",
97
+ ...options,
98
+ data: {
99
+ subscription: {
100
+ id: options.subscription?.id ?? "sub_fixture_123",
101
+ status: options.subscription?.status ?? "active",
102
+ amountCents: options.subscription?.amountCents ?? 1500,
103
+ previousAmountCents: options.subscription?.previousAmountCents ?? 500,
104
+ currency: options.subscription?.currency ?? "usd",
105
+ interval: options.subscription?.interval ?? "month",
106
+ payerDid: options.subscription?.payerDid ?? "did:plc:buyer",
107
+ recipientDid: options.subscription?.recipientDid ?? "did:plc:creator",
108
+ appDid: options.subscription?.appDid ?? "did:plc:app",
109
+ },
110
+ },
111
+ });
112
+ }
113
+ export function createTicketsIssuedFixture(options = {}) {
114
+ const tickets = options.ticket?.tickets ?? [
115
+ {
116
+ ticketId: "ticket_fixture_123",
117
+ ticketTierId: "tier_fixture_general",
118
+ status: "issued",
119
+ },
120
+ ];
121
+ return createAtmEventFixture({
122
+ type: "tickets.issued",
123
+ ...options,
124
+ data: {
125
+ eventUri: options.ticket?.eventUri ??
126
+ "at://did:plc:organizer/community.lexicon.calendar.event/demo",
127
+ holdId: options.ticket?.holdId ?? "hold_fixture_123",
128
+ paymentId: options.ticket?.paymentId ?? "pay_fixture_123",
129
+ buyerDid: options.ticket?.buyerDid ?? "did:plc:buyer",
130
+ issuedCount: options.ticket?.issuedCount ?? tickets.length,
131
+ tickets,
132
+ },
133
+ });
134
+ }
135
+ export function createProductArchivedFixture(options = {}) {
136
+ const product = {
137
+ productUri: options.product?.productUri ??
138
+ "at://did:plc:creator/money.atmosphere.product/product_fixture",
139
+ appDid: options.product?.appDid ?? "did:plc:app",
140
+ archivedAt: options.product?.archivedAt ?? "2026-05-01T12:00:00.000Z",
141
+ metadata: options.product?.metadata ?? { reason: "creator_archived" },
142
+ };
143
+ if (options.product?.productCid !== undefined)
144
+ product.productCid = options.product.productCid;
145
+ if (options.product?.creatorDid !== undefined)
146
+ product.creatorDid = options.product.creatorDid;
147
+ return createAtmEventFixture({
148
+ type: "product.archived",
149
+ ...options,
150
+ data: { product },
151
+ });
152
+ }
153
+ export function createTicketCheckedInFixture(options = {}) {
154
+ const ticket = {
155
+ ticketId: options.ticket?.ticketId ?? "ticket_fixture_123",
156
+ ticketTierId: options.ticket?.ticketTierId ?? "tier_fixture_general",
157
+ eventUri: options.ticket?.eventUri ??
158
+ "at://did:plc:organizer/community.lexicon.calendar.event/demo",
159
+ checkInListId: options.ticket?.checkInListId ?? "checklist_fixture_123",
160
+ checkedInAt: options.ticket?.checkedInAt ?? "2026-05-01T12:00:00.000Z",
161
+ repeat: options.ticket?.repeat ?? false,
162
+ metadata: options.ticket?.metadata ?? { scannerId: "scanner_fixture_123" },
163
+ };
164
+ if (options.ticket?.buyerDid !== undefined)
165
+ ticket.buyerDid = options.ticket.buyerDid;
166
+ return createAtmEventFixture({
167
+ type: "ticket.checked_in",
168
+ ...options,
169
+ data: { ticket },
170
+ });
171
+ }
172
+ export function signAtmFixture(options) {
173
+ const timestamp = options.timestamp ?? ATM_TEST_CREATED;
174
+ const secret = options.secret ?? ATM_TEST_WEBHOOK_SECRET;
175
+ const signedPayload = `${timestamp}.${options.deliveryId}.${options.rawBody}`;
176
+ const digest = createHmac("sha256", secret)
177
+ .update(signedPayload)
178
+ .digest("hex");
179
+ return `t=${timestamp},v1=${digest}`;
180
+ }
181
+ export function createMemoryReplayStore(initialKeys = []) {
182
+ const seen = new Set(initialKeys);
183
+ return {
184
+ insertOnce(key) {
185
+ if (seen.has(key))
186
+ return false;
187
+ seen.add(key);
188
+ return true;
189
+ },
190
+ has(key) {
191
+ return seen.has(key);
192
+ },
193
+ };
194
+ }
195
+ export function createAtmWebhookRequest(fixture, options = {}) {
196
+ const headers = new Headers(options.headers);
197
+ for (const [name, value] of Object.entries(fixture.headers)) {
198
+ headers.set(name, value);
199
+ }
200
+ return new Request(options.url ?? "https://app.example/webhooks/atm", {
201
+ method: options.method ?? "POST",
202
+ headers,
203
+ body: fixture.rawBody,
204
+ });
205
+ }
206
+ export async function assertFreshDelivery(store, deliveryId) {
207
+ const inserted = await store.insertOnce(deliveryId);
208
+ if (!inserted) {
209
+ throw new Error(`Duplicate ATM delivery id: ${deliveryId}`);
210
+ }
211
+ }
212
+ export function createAtmIdempotencyKey(parts) {
213
+ const normalized = parts
214
+ .filter((part) => part !== null && part !== undefined && part !== "")
215
+ .map((part) => String(part).trim())
216
+ .join(":");
217
+ if (!normalized) {
218
+ throw new Error("At least one idempotency key part is required");
219
+ }
220
+ return `atm:test:${normalized}`;
221
+ }
222
+ function createSignedFixture({ type, options, data, }) {
223
+ const deliveryId = options.deliveryId ?? options.id ?? `del_${type.replace(".", "_")}_fixture`;
224
+ const id = options.id ?? deliveryId;
225
+ const created = options.created ?? ATM_TEST_CREATED;
226
+ const apiVersion = options.apiVersion ?? ATM_TEST_API_VERSION;
227
+ const environment = options.environment ?? "test";
228
+ const event = {
229
+ id,
230
+ type,
231
+ created,
232
+ apiVersion,
233
+ environment,
234
+ data,
235
+ };
236
+ const rawBody = JSON.stringify(event);
237
+ const signatureOptions = {
238
+ rawBody,
239
+ deliveryId,
240
+ timestamp: created,
241
+ };
242
+ if (options.secret !== undefined)
243
+ signatureOptions.secret = options.secret;
244
+ const signature = signAtmFixture(signatureOptions);
245
+ return {
246
+ event,
247
+ rawBody,
248
+ headers: {
249
+ "atm-signature": signature,
250
+ "atm-delivery-id": deliveryId,
251
+ "atm-event": type,
252
+ "atm-api-version": apiVersion,
253
+ "atm-environment": environment,
254
+ },
255
+ };
256
+ }
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@atmosphere-money/testing",
3
+ "version": "0.0.0-beta.0",
4
+ "description": "Testing fixtures and assertions for Atmosphere Money app integrations.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "private": false,
8
+ "sideEffects": false,
9
+ "homepage": "https://atmosphere.money/docs/testing-package",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/Atmosphere-Money/ATM.git",
13
+ "directory": "packages/testing"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/Atmosphere-Money/ATM/issues"
17
+ },
18
+ "keywords": [
19
+ "atmosphere-money",
20
+ "at-protocol",
21
+ "atproto",
22
+ "payments",
23
+ "webhooks",
24
+ "fixtures",
25
+ "testing"
26
+ ],
27
+ "files": [
28
+ "dist",
29
+ "README.md",
30
+ "CHANGELOG.md",
31
+ "LICENSE"
32
+ ],
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js"
37
+ }
38
+ },
39
+ "types": "./dist/index.d.ts",
40
+ "main": "./dist/index.js",
41
+ "scripts": {
42
+ "build": "tsc -p tsconfig.json",
43
+ "test": "tsx test/index.test.ts",
44
+ "api:snapshot": "node ../../scripts/check-sdk-api-snapshot.mjs packages/testing --write",
45
+ "api:check": "node ../../scripts/check-sdk-api-snapshot.mjs packages/testing",
46
+ "check": "npm run build && npm run api:check && npm run test && npm run release:check && npm run pack:dry-run",
47
+ "release:check": "node scripts/check-release.mjs",
48
+ "publish:check": "ATM_TESTING_PUBLISH=1 node scripts/check-release.mjs && npm run pack:dry-run",
49
+ "pack:dry-run": "npm pack --dry-run",
50
+ "prepare": "npm run build",
51
+ "prepack": "npm run build"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "engines": {
57
+ "node": ">=22.0.0"
58
+ },
59
+ "devDependencies": {
60
+ "@types/node": "^22.10.2",
61
+ "tsx": "^4.22.3",
62
+ "typescript": "^5.7.2"
63
+ }
64
+ }