create-disposabl-app 0.19.4 → 0.19.6
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/disposabl.js +1 -1
- package/dist/index.js +1 -1
- package/dist/templates/default/packages/backend/convex/_generated/server.d.ts +1 -0
- package/dist/templates/default/packages/backend/convex/convex.config.ts +1 -0
- package/dist/templates/default/packages/disposabl-kit/PAYMENTS.md +3 -1
- package/dist/templates/default/packages/disposabl-kit/server/revenuecat-contract.ts +55 -0
- package/dist/templates/default/packages/disposabl-kit/server/revenuecat-functions.ts +35 -26
- package/dist/templates/default/packages/tests/revenuecat-inbox.test.ts +234 -0
- package/package.json +1 -1
package/dist/disposabl.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1563,7 +1563,7 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
|
1563
1563
|
import { Command, CommanderError } from "commander";
|
|
1564
1564
|
import * as p2 from "@clack/prompts";
|
|
1565
1565
|
// package.json
|
|
1566
|
-
var version = "0.19.
|
|
1566
|
+
var version = "0.19.6";
|
|
1567
1567
|
|
|
1568
1568
|
// ../cli/telemetry.ts
|
|
1569
1569
|
var import_proper_lockfile2 = __toESM(require_proper_lockfile(), 1);
|
|
@@ -32,6 +32,7 @@ type Env = {
|
|
|
32
32
|
readonly R2_BUCKET_NAME: string | undefined;
|
|
33
33
|
readonly R2_ACCESS_KEY_ID: string | undefined;
|
|
34
34
|
readonly R2_SECRET_ACCESS_KEY: string | undefined;
|
|
35
|
+
readonly REVENUECAT_MANAGED_MONTHLY_ROUTES: string | undefined;
|
|
35
36
|
readonly CONVEX_CLOUD_URL: string;
|
|
36
37
|
readonly CONVEX_SITE_URL: string;
|
|
37
38
|
readonly AUTH_EMAIL_ORIGIN: string | undefined;
|
|
@@ -25,6 +25,7 @@ const app = defineApp({
|
|
|
25
25
|
REVENUECAT_PROJECT_ID: v.optional(v.string()),
|
|
26
26
|
REVENUECAT_ENVIRONMENT: v.optional(v.string()),
|
|
27
27
|
REVENUECAT_ROUTES: v.optional(v.string()),
|
|
28
|
+
REVENUECAT_MANAGED_MONTHLY_ROUTES: v.optional(v.string()),
|
|
28
29
|
REVENUECAT_SYNC_ENABLED: v.optional(v.string()),
|
|
29
30
|
DISPOSABL_ENVIRONMENT: v.optional(v.string()),
|
|
30
31
|
POSTHOG_ENABLED: v.optional(v.string()),
|
|
@@ -52,9 +52,11 @@ Native consumable top-ups use a separately fetched store product and the opt-in
|
|
|
52
52
|
|
|
53
53
|
With payments selected, custom processing is disabled unless `REVENUECAT_CONSUMABLE_OWNER=custom`, `REVENUECAT_WEBHOOK_AUTH`, `REVENUECAT_PROJECT_ID`, `REVENUECAT_ENVIRONMENT` (`SANDBOX` or `PRODUCTION`), `REVENUECAT_ROUTES`, and `AUTUMN_SECRET_KEY` are present. `REVENUECAT_ROUTES` is a JSON array such as `[{"app":"apple-app-id","store":"APP_STORE","product":"apple-topup"},{"app":"google-app-id","store":"PLAY_STORE","product":"google-topup"}]`. Each app ID must be unique. The inbox requires an `am_sk_test_` Autumn key for `SANDBOX` and an `am_sk_live_` key for `PRODUCTION`; a mismatched or unrecognized key disables intake and dispatch. The prefix is an environment guard, not proof that the key belongs to the intended Autumn organization. Invalid or ambiguous configuration disables the inbox. Configure a distinct authorization for each project and environment, sent as the complete Authorization header to `/revenuecat/webhook`. RevenueCat payloads do not normally include a project ID: the project association depends on that credential; authenticated app ID, store, environment and product select the allowlisted route. Transfer events without an environment are rejected for review. Use separate test and live deployments and secrets. Payments-off never processes a webhook or makes an Autumn request.
|
|
54
54
|
|
|
55
|
+
Optionally set `REVENUECAT_MANAGED_MONTHLY_ROUTES` to a JSON array of `{ "app", "store", "product" }` tuples for managed monthly products, for example `[{"app":"apple-app-id","store":"APP_STORE","product":"apple-monthly"}]`. Each tuple must match an existing top-up app and store, have a different product, and be unique; at most 20 tuples are allowed. An absent or empty array adds no routes, while malformed or conflicting configuration disables the inbox. Authenticated, structurally valid `INITIAL_PURCHASE`, `RENEWAL`, and `CANCELLATION` events matching these tuples return 200 with `ignored` without persistence or grant. Unknown products and other event types on these monthly routes remain rejected. This allowlist does not configure or verify the managed provider mapping.
|
|
56
|
+
|
|
55
57
|
After completing the verification below, an operator may explicitly set `REVENUECAT_CONSUMABLE_INTEGRATION_VERIFIED=true` on the matching backend. Set `EXPO_PUBLIC_REVENUECAT_IOS_APP_ID`, `EXPO_PUBLIC_REVENUECAT_ANDROID_APP_ID`, `EXPO_PUBLIC_REVENUECAT_IOS_TOPUP_PRODUCT`, and `EXPO_PUBLIC_REVENUECAT_ANDROID_TOPUP_PRODUCT` to the exact route values for each build. The SDK fetches the localized store price and verifies the product identifier and non-subscription category. On iOS it requires StoreKit 2 to identify the product as consumable; StoreKit 1 cannot prove this. On Android the SDK may report an unknown specific product type, so the operator must independently verify its consumable configuration. Do not enable based on category alone. The monthly RevenueCat offering remains separate and contains only the monthly product.
|
|
56
58
|
|
|
57
|
-
The authenticated webhook checks app, environment, store, product, transaction and a known local user, then durably records delivery and transaction ownership. A stable balance ID excludes the customer, so an account switch cannot create a second grant. A scheduled worker atomically changes `queued` to `grant_unknown` before calling Autumn 2.6 `balances.create` with the configured top-up credit quantity. Only an explicit `{success:true}` response records a grant. A timeout, malformed response, provider error, or worker crash leaves `grant_unknown`: duplicate deliveries and action retries cannot issue another create. A separate paid transaction can proceed independently.
|
|
59
|
+
The authenticated webhook checks app, environment, store, product, transaction and a known local user, then durably records delivery and transaction ownership. A stable balance ID excludes the customer, so an account switch cannot create a second grant. A scheduled worker atomically changes `queued` to `grant_unknown` before calling Autumn 2.6 `balances.create` with the configured top-up credit quantity. Only an explicit `{success:true}` response records a grant. A timeout, malformed response, provider error, or worker crash leaves `grant_unknown`: duplicate deliveries and action retries cannot issue another create. A separate paid transaction can proceed independently. An HTTP 200 after persistence means accepted for processing, never credited.
|
|
58
60
|
|
|
59
61
|
A cancellation before dispatch creates a local tombstone; a later purchase cannot grant. Cancellation during a write is held until the result is known. After a grant, cancellation enters `refund_review` because the webhook alone does not prove the refund is full. An operator must establish the scope and spent-credit policy from provider records before calling private `revenuecat:confirmFullRefund` with a nonsecret evidence reference. It targets only that balance ID via `balances.update` with `remaining: 0`. An uncertain update is held as `refund_unknown`. Transfers and refund reversals require review; transfer notifications are stored separately and place affected customers on hold across both apps in the same project and environment. A transfer arriving after dispatch cannot cancel an in-flight provider request. There is no automatic hold release until transfer reconciliation is defined, and incomplete event identities are rejected. No automatic restore, replay of an uncertain operation, or missed-webhook reconciliation is implied.
|
|
60
62
|
|
|
@@ -8,6 +8,7 @@ export type RevenueCatConfig = {
|
|
|
8
8
|
product: string;
|
|
9
9
|
store: "APP_STORE" | "PLAY_STORE";
|
|
10
10
|
autumnKey: string;
|
|
11
|
+
managedMonthlyProducts?: string[];
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
export type PurchaseEvent = {
|
|
@@ -116,9 +117,63 @@ export function revenueCatConfigs(
|
|
|
116
117
|
return null;
|
|
117
118
|
result.push({ authorization, project, environment, autumnKey, ...route });
|
|
118
119
|
}
|
|
120
|
+
if (env.REVENUECAT_MANAGED_MONTHLY_ROUTES !== undefined) {
|
|
121
|
+
let monthly: unknown;
|
|
122
|
+
try {
|
|
123
|
+
monthly = JSON.parse(env.REVENUECAT_MANAGED_MONTHLY_ROUTES);
|
|
124
|
+
} catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
if (!Array.isArray(monthly) || monthly.length > 20) return null;
|
|
128
|
+
for (const route of monthly) {
|
|
129
|
+
if (
|
|
130
|
+
!route ||
|
|
131
|
+
typeof route !== "object" ||
|
|
132
|
+
Array.isArray(route) ||
|
|
133
|
+
Object.keys(route).sort().join(",") !== "app,product,store" ||
|
|
134
|
+
typeof route.product !== "string" ||
|
|
135
|
+
!route.product ||
|
|
136
|
+
route.product.trim() !== route.product ||
|
|
137
|
+
route.product.length > 256
|
|
138
|
+
)
|
|
139
|
+
return null;
|
|
140
|
+
const config = result.find(
|
|
141
|
+
(item) => item.app === route.app && item.store === route.store,
|
|
142
|
+
);
|
|
143
|
+
if (
|
|
144
|
+
!config ||
|
|
145
|
+
config.product === route.product ||
|
|
146
|
+
config.managedMonthlyProducts?.includes(route.product)
|
|
147
|
+
)
|
|
148
|
+
return null;
|
|
149
|
+
(config.managedMonthlyProducts ??= []).push(route.product);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
119
152
|
return result;
|
|
120
153
|
}
|
|
121
154
|
|
|
155
|
+
/** Managed monthly lifecycle events are acknowledged without entering the top-up inbox. */
|
|
156
|
+
export function isManagedMonthlyEvent(
|
|
157
|
+
payload: unknown,
|
|
158
|
+
configs: RevenueCatConfig[],
|
|
159
|
+
) {
|
|
160
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
161
|
+
return false;
|
|
162
|
+
const event = (payload as Record<string, unknown>).event;
|
|
163
|
+
if (!event || typeof event !== "object" || Array.isArray(event)) return false;
|
|
164
|
+
const e = event as Record<string, unknown>;
|
|
165
|
+
if (
|
|
166
|
+
!["INITIAL_PURCHASE", "RENEWAL", "CANCELLATION"].includes(e.type as string)
|
|
167
|
+
)
|
|
168
|
+
return false;
|
|
169
|
+
return configs.some((config) =>
|
|
170
|
+
config.managedMonthlyProducts?.some(
|
|
171
|
+
(product) =>
|
|
172
|
+
parseRevenueCatEvent(payload, { ...config, product }) !== null,
|
|
173
|
+
),
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
122
177
|
export function selectRevenueCatRoute(
|
|
123
178
|
payload: unknown,
|
|
124
179
|
configs: RevenueCatConfig[],
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
balanceRequest,
|
|
13
13
|
parseRevenueCatEvent,
|
|
14
14
|
parseTransfer,
|
|
15
|
+
isManagedMonthlyEvent,
|
|
15
16
|
revenueCatConfigs,
|
|
16
17
|
selectRevenueCatRoute,
|
|
17
18
|
resolveRevenueCatRoute,
|
|
@@ -83,33 +84,41 @@ export async function webhookAuthorized(
|
|
|
83
84
|
return !!supplied && (await sameSecret(supplied, authorization));
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
export const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
87
|
+
export const createWebhook = (
|
|
88
|
+
enabled = paymentsEnabled,
|
|
89
|
+
environment: Record<string, string | undefined> = process.env,
|
|
90
|
+
) =>
|
|
91
|
+
httpActionGeneric(async (ctx, request) => {
|
|
92
|
+
const configs = revenueCatConfigs(enabled, environment);
|
|
93
|
+
if (!configs) return new Response("Unavailable", { status: 503 });
|
|
94
|
+
if (!(await webhookAuthorized(request, configs[0]!.authorization)))
|
|
95
|
+
return new Response("Unauthorized", { status: 401 });
|
|
96
|
+
let payload: unknown;
|
|
97
|
+
try {
|
|
98
|
+
payload = await request.json();
|
|
99
|
+
} catch {
|
|
100
|
+
return new Response("Invalid event", { status: 400 });
|
|
101
|
+
}
|
|
102
|
+
if (isManagedMonthlyEvent(payload, configs))
|
|
103
|
+
return Response.json({ status: "ignored" }, { status: 200 });
|
|
104
|
+
const config = selectRevenueCatRoute(payload, configs);
|
|
105
|
+
if (!config) return new Response("Invalid event", { status: 400 });
|
|
106
|
+
const transfer = parseTransfer(payload, config);
|
|
107
|
+
if (transfer) {
|
|
108
|
+
await ctx.runMutation(transferRef, transfer);
|
|
109
|
+
return Response.json({ status: "operator_review" }, { status: 200 });
|
|
110
|
+
}
|
|
111
|
+
const event = parseRevenueCatEvent(payload, config);
|
|
112
|
+
if (!event) return new Response("Invalid event", { status: 400 });
|
|
113
|
+
const result = await ctx.runMutation(receiveRef, {
|
|
114
|
+
event,
|
|
115
|
+
balanceId: await balanceId(event),
|
|
116
|
+
});
|
|
117
|
+
// Accepted means persisted, never a claim that the balance has changed.
|
|
118
|
+
return Response.json({ status: result }, { status: 200 });
|
|
109
119
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
});
|
|
120
|
+
|
|
121
|
+
export const webhook = createWebhook();
|
|
113
122
|
|
|
114
123
|
export const receiveTransfer = internalMutation({
|
|
115
124
|
args: {
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
complete,
|
|
17
17
|
confirmFullRefund,
|
|
18
18
|
receiveTransfer,
|
|
19
|
+
createWebhook,
|
|
19
20
|
webhookAuthorized,
|
|
20
21
|
webhook,
|
|
21
22
|
dispatchBalance,
|
|
@@ -123,6 +124,137 @@ const scopedClaim = (balanceId: string) => ({
|
|
|
123
124
|
});
|
|
124
125
|
|
|
125
126
|
describe("RevenueCat consumable inbox", () => {
|
|
127
|
+
test("managed monthly events are acknowledged only for valid, disjoint configured routes", async () => {
|
|
128
|
+
const monthly = { app: "app", store: "APP_STORE", product: "monthly" };
|
|
129
|
+
const env = {
|
|
130
|
+
REVENUECAT_CONSUMABLE_OWNER: "custom",
|
|
131
|
+
REVENUECAT_WEBHOOK_AUTH: config.authorization,
|
|
132
|
+
REVENUECAT_PROJECT_ID: config.project,
|
|
133
|
+
REVENUECAT_ENVIRONMENT: config.environment,
|
|
134
|
+
AUTUMN_SECRET_KEY: "am_sk_test_synthetic",
|
|
135
|
+
REVENUECAT_ROUTES: JSON.stringify([
|
|
136
|
+
{ app: "app", store: "APP_STORE", product: "topup" },
|
|
137
|
+
]),
|
|
138
|
+
REVENUECAT_MANAGED_MONTHLY_ROUTES: JSON.stringify([monthly]),
|
|
139
|
+
};
|
|
140
|
+
const cancellation = {
|
|
141
|
+
id: "private-delivery",
|
|
142
|
+
type: "CANCELLATION",
|
|
143
|
+
app_id: "app",
|
|
144
|
+
environment: "SANDBOX",
|
|
145
|
+
store: "APP_STORE",
|
|
146
|
+
product_id: "monthly",
|
|
147
|
+
app_user_id: "private-user",
|
|
148
|
+
transaction_id: "private-transaction",
|
|
149
|
+
};
|
|
150
|
+
const request = (event: object, auth = config.authorization) =>
|
|
151
|
+
new Request("https://example.test", {
|
|
152
|
+
method: "POST",
|
|
153
|
+
headers: { authorization: auth },
|
|
154
|
+
body: JSON.stringify({ api_version: "1.0", event }),
|
|
155
|
+
});
|
|
156
|
+
const f = fixture();
|
|
157
|
+
let mutations = 0;
|
|
158
|
+
const ctx = {
|
|
159
|
+
runMutation: (_ref: unknown, args: unknown) => {
|
|
160
|
+
mutations++;
|
|
161
|
+
return call(receive, f.ctx, args);
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
const handler = createWebhook(true, env);
|
|
165
|
+
for (const type of ["CANCELLATION", "INITIAL_PURCHASE", "RENEWAL"]) {
|
|
166
|
+
const response = await call(
|
|
167
|
+
handler,
|
|
168
|
+
ctx,
|
|
169
|
+
request({ ...cancellation, type }),
|
|
170
|
+
);
|
|
171
|
+
assert.equal(response.status, 200);
|
|
172
|
+
assert.equal(await response.text(), '{"status":"ignored"}');
|
|
173
|
+
}
|
|
174
|
+
assert.equal(mutations, 0);
|
|
175
|
+
assert.equal(f.jobs.length, 0);
|
|
176
|
+
assert.ok(Object.values(f.tables).every((rows) => rows.length === 0));
|
|
177
|
+
for (const change of [
|
|
178
|
+
{ product_id: "unknown" },
|
|
179
|
+
{ app_id: "other" },
|
|
180
|
+
{ store: "PLAY_STORE" },
|
|
181
|
+
{ environment: "PRODUCTION" },
|
|
182
|
+
{ project_id: "other" },
|
|
183
|
+
{ id: "" },
|
|
184
|
+
{ transaction_id: "" },
|
|
185
|
+
{ app_user_id: "$RCAnonymousID:x" },
|
|
186
|
+
{ original_app_user_id: "other" },
|
|
187
|
+
{ type: "UNKNOWN" },
|
|
188
|
+
{ type: "NON_RENEWING_PURCHASE" },
|
|
189
|
+
]) {
|
|
190
|
+
const response = await call(
|
|
191
|
+
handler,
|
|
192
|
+
ctx,
|
|
193
|
+
request({ ...cancellation, ...change }),
|
|
194
|
+
);
|
|
195
|
+
assert.equal(response.status, 400);
|
|
196
|
+
assert.equal(await response.text(), "Invalid event");
|
|
197
|
+
}
|
|
198
|
+
assert.equal(
|
|
199
|
+
(await call(handler, ctx, request(cancellation, "Bearer wrong"))).status,
|
|
200
|
+
401,
|
|
201
|
+
);
|
|
202
|
+
assert.equal(
|
|
203
|
+
(await call(createWebhook(false, env), ctx, request(cancellation)))
|
|
204
|
+
.status,
|
|
205
|
+
503,
|
|
206
|
+
);
|
|
207
|
+
for (const routes of [
|
|
208
|
+
[{ ...monthly, product: "topup" }],
|
|
209
|
+
[monthly, monthly],
|
|
210
|
+
[{ ...monthly, store: "PLAY_STORE" }],
|
|
211
|
+
[{ ...monthly, app: "other" }],
|
|
212
|
+
[{ ...monthly, extra: true }],
|
|
213
|
+
]) {
|
|
214
|
+
assert.equal(
|
|
215
|
+
revenueCatConfigs(true, {
|
|
216
|
+
...env,
|
|
217
|
+
REVENUECAT_MANAGED_MONTHLY_ROUTES: JSON.stringify(routes),
|
|
218
|
+
}),
|
|
219
|
+
null,
|
|
220
|
+
);
|
|
221
|
+
assert.equal(
|
|
222
|
+
(
|
|
223
|
+
await call(
|
|
224
|
+
createWebhook(true, {
|
|
225
|
+
...env,
|
|
226
|
+
REVENUECAT_MANAGED_MONTHLY_ROUTES: JSON.stringify(routes),
|
|
227
|
+
}),
|
|
228
|
+
ctx,
|
|
229
|
+
request(cancellation),
|
|
230
|
+
)
|
|
231
|
+
).status,
|
|
232
|
+
503,
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
assert.equal(
|
|
236
|
+
revenueCatConfigs(true, {
|
|
237
|
+
...env,
|
|
238
|
+
REVENUECAT_MANAGED_MONTHLY_ROUTES: "bad",
|
|
239
|
+
}),
|
|
240
|
+
null,
|
|
241
|
+
);
|
|
242
|
+
const response = await call(
|
|
243
|
+
handler,
|
|
244
|
+
ctx,
|
|
245
|
+
request({
|
|
246
|
+
...cancellation,
|
|
247
|
+
product_id: "topup",
|
|
248
|
+
type: "NON_RENEWING_PURCHASE",
|
|
249
|
+
app_user_id: "user-1",
|
|
250
|
+
}),
|
|
251
|
+
);
|
|
252
|
+
assert.equal(response.status, 200);
|
|
253
|
+
assert.equal(mutations, 1);
|
|
254
|
+
assert.equal(f.tables.revenueCatPurchases!.length, 1);
|
|
255
|
+
assert.equal(f.tables.revenueCatDeliveries!.length, 1);
|
|
256
|
+
assert.equal(f.jobs.length, 1);
|
|
257
|
+
});
|
|
126
258
|
test("validated routes select both stores and reject ambiguous or removed configuration", () => {
|
|
127
259
|
const env = {
|
|
128
260
|
REVENUECAT_CONSUMABLE_OWNER: "custom",
|
|
@@ -396,6 +528,108 @@ describe("RevenueCat consumable inbox", () => {
|
|
|
396
528
|
assert.equal(response.status, 503);
|
|
397
529
|
},
|
|
398
530
|
);
|
|
531
|
+
test("webhook acknowledges durable purchases and transfer holds with HTTP 200", async () => {
|
|
532
|
+
const handler = createWebhook(true, {
|
|
533
|
+
REVENUECAT_CONSUMABLE_OWNER: "custom",
|
|
534
|
+
REVENUECAT_WEBHOOK_AUTH: config.authorization,
|
|
535
|
+
REVENUECAT_PROJECT_ID: config.project,
|
|
536
|
+
REVENUECAT_ENVIRONMENT: config.environment,
|
|
537
|
+
AUTUMN_SECRET_KEY: "am_sk_test_synthetic",
|
|
538
|
+
REVENUECAT_ROUTES: JSON.stringify([
|
|
539
|
+
{ app: config.app, store: config.store, product: config.product },
|
|
540
|
+
]),
|
|
541
|
+
});
|
|
542
|
+
const purchase = {
|
|
543
|
+
id: "delivery",
|
|
544
|
+
type: "NON_RENEWING_PURCHASE",
|
|
545
|
+
app_id: config.app,
|
|
546
|
+
environment: config.environment,
|
|
547
|
+
store: config.store,
|
|
548
|
+
product_id: config.product,
|
|
549
|
+
app_user_id: "user-1",
|
|
550
|
+
transaction_id: "transaction",
|
|
551
|
+
};
|
|
552
|
+
const request = (event: object) =>
|
|
553
|
+
new Request("https://example.test/revenuecat/webhook", {
|
|
554
|
+
method: "POST",
|
|
555
|
+
headers: { authorization: config.authorization },
|
|
556
|
+
body: JSON.stringify({ api_version: "1.0", event }),
|
|
557
|
+
});
|
|
558
|
+
for (const event of [
|
|
559
|
+
purchase,
|
|
560
|
+
{
|
|
561
|
+
...purchase,
|
|
562
|
+
type: "TRANSFER",
|
|
563
|
+
transferred_from: ["user-1"],
|
|
564
|
+
transferred_to: ["user-2"],
|
|
565
|
+
},
|
|
566
|
+
]) {
|
|
567
|
+
let enter!: () => void;
|
|
568
|
+
let persist!: (value: string) => void;
|
|
569
|
+
const entered = new Promise<void>((resolve) => {
|
|
570
|
+
enter = resolve;
|
|
571
|
+
});
|
|
572
|
+
const persisted = new Promise<string>((resolve) => {
|
|
573
|
+
persist = resolve;
|
|
574
|
+
});
|
|
575
|
+
let acknowledged = false;
|
|
576
|
+
const result = call(
|
|
577
|
+
handler,
|
|
578
|
+
{
|
|
579
|
+
runMutation: () => {
|
|
580
|
+
enter();
|
|
581
|
+
return persisted;
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
request(event),
|
|
585
|
+
).then((response: Response) => {
|
|
586
|
+
acknowledged = true;
|
|
587
|
+
return response;
|
|
588
|
+
});
|
|
589
|
+
await entered;
|
|
590
|
+
assert.equal(acknowledged, false);
|
|
591
|
+
persist("pending");
|
|
592
|
+
const response = await result;
|
|
593
|
+
assert.equal(response.status, 200);
|
|
594
|
+
assert.deepEqual(await response.json(), {
|
|
595
|
+
status: event.type === "TRANSFER" ? "operator_review" : "pending",
|
|
596
|
+
});
|
|
597
|
+
await assert.rejects(
|
|
598
|
+
call(
|
|
599
|
+
handler,
|
|
600
|
+
{
|
|
601
|
+
runMutation: async () => {
|
|
602
|
+
throw new Error("persistence failed");
|
|
603
|
+
},
|
|
604
|
+
},
|
|
605
|
+
request(event),
|
|
606
|
+
),
|
|
607
|
+
/persistence failed/,
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
const f = fixture();
|
|
611
|
+
const ctx = {
|
|
612
|
+
runMutation: (_ref: unknown, args: unknown) => call(receive, f.ctx, args),
|
|
613
|
+
};
|
|
614
|
+
assert.equal((await call(handler, ctx, request(purchase))).status, 200);
|
|
615
|
+
assert.equal((await call(handler, ctx, request(purchase))).status, 200);
|
|
616
|
+
assert.equal(f.tables.revenueCatPurchases!.length, 1);
|
|
617
|
+
assert.equal(f.tables.revenueCatDeliveries!.length, 1);
|
|
618
|
+
assert.equal(
|
|
619
|
+
(
|
|
620
|
+
await call(
|
|
621
|
+
handler,
|
|
622
|
+
ctx,
|
|
623
|
+
request({ ...purchase, environment: "PRODUCTION" }),
|
|
624
|
+
)
|
|
625
|
+
).status,
|
|
626
|
+
400,
|
|
627
|
+
);
|
|
628
|
+
assert.equal(
|
|
629
|
+
(await call(handler, ctx, new Request("https://example.test"))).status,
|
|
630
|
+
401,
|
|
631
|
+
);
|
|
632
|
+
});
|
|
399
633
|
test("webhook authorization requires the exact configured header", async () => {
|
|
400
634
|
assert.equal(
|
|
401
635
|
await webhookAuthorized(
|