backend-manager 5.0.91 → 5.0.93
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 +2 -2
- package/CLAUDE.md +14 -6
- package/README.md +6 -6
- package/TODO-MARKETING.md +3 -0
- package/TODO-PAYMENT-v2.md +71 -0
- package/TODO.md +7 -0
- package/package.json +3 -3
- package/src/cli/commands/{emulators.js → emulator.js} +15 -15
- package/src/cli/commands/index.js +1 -1
- package/src/cli/commands/setup-tests/{emulators-config.js → emulator-config.js} +4 -4
- package/src/cli/commands/setup-tests/index.js +2 -2
- package/src/cli/commands/setup-tests/project-id-consistency.js +1 -1
- package/src/cli/commands/test.js +16 -16
- package/src/cli/index.js +4 -4
- package/src/manager/events/auth/on-create.js +5 -158
- package/src/manager/events/firestore/payments-webhooks/analytics.js +4 -3
- package/src/manager/events/firestore/payments-webhooks/on-write.js +56 -6
- package/src/manager/events/firestore/payments-webhooks/transitions/one-time/purchase-completed.js +3 -3
- package/src/manager/events/firestore/payments-webhooks/transitions/one-time/purchase-failed.js +1 -1
- package/src/manager/events/firestore/payments-webhooks/transitions/send-email.js +32 -28
- package/src/manager/events/firestore/payments-webhooks/transitions/subscription/cancellation-requested.js +3 -3
- package/src/manager/events/firestore/payments-webhooks/transitions/subscription/new-subscription.js +3 -3
- package/src/manager/events/firestore/payments-webhooks/transitions/subscription/payment-failed.js +3 -3
- package/src/manager/events/firestore/payments-webhooks/transitions/subscription/payment-recovered.js +3 -3
- package/src/manager/events/firestore/payments-webhooks/transitions/subscription/plan-changed.js +3 -3
- package/src/manager/events/firestore/payments-webhooks/transitions/subscription/subscription-cancelled.js +3 -3
- package/src/manager/functions/core/actions/api/admin/send-email.js +0 -131
- package/src/manager/functions/core/actions/api/general/add-marketing-contact.js +2 -137
- package/src/manager/functions/core/actions/api/general/emails/general:download-app-link.js +2 -2
- package/src/manager/functions/core/actions/api/user/sign-up.js +1 -1
- package/src/manager/index.js +12 -0
- package/src/manager/libraries/email.js +523 -0
- package/src/manager/libraries/infer-contact.js +140 -0
- package/src/manager/libraries/prompts/infer-contact.md +43 -0
- package/src/manager/routes/admin/backup/post.js +4 -3
- package/src/manager/routes/admin/email/post.js +11 -428
- package/src/manager/routes/admin/hook/post.js +3 -2
- package/src/manager/routes/admin/notification/post.js +14 -12
- package/src/manager/routes/admin/post/post.js +5 -6
- package/src/manager/routes/admin/post/put.js +3 -2
- package/src/manager/routes/admin/stats/get.js +19 -10
- package/src/manager/routes/general/email/post.js +8 -21
- package/src/manager/routes/general/email/templates/download-app-link.js +2 -2
- package/src/manager/routes/marketing/contact/post.js +2 -100
- package/src/manager/routes/payments/intent/post.js +0 -2
- package/src/manager/routes/payments/intent/processors/test.js +9 -10
- package/src/manager/routes/user/oauth2/_helpers.js +3 -2
- package/src/manager/routes/user/oauth2/delete.js +3 -3
- package/src/manager/routes/user/oauth2/get.js +2 -2
- package/src/manager/routes/user/oauth2/post.js +9 -9
- package/src/manager/routes/user/sessions/delete.js +4 -3
- package/src/manager/routes/user/signup/post.js +254 -54
- package/src/manager/schemas/admin/email/post.js +13 -8
- package/src/test/run-tests.js +1 -1
- package/test/functions/admin/send-email.js +1 -88
- package/test/helpers/email.js +421 -0
- package/test/helpers/infer-contact.js +299 -0
- package/test/routes/admin/email.js +41 -90
- package/REFACTOR-BEM-API.md +0 -76
- package/REFACTOR-MIDDLEWARE.md +0 -62
- package/REFACTOR-PAYMENT.md +0 -66
package/REFACTOR-PAYMENT.md
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
PAYMETN SYSTEM REFACTOR
|
|
2
|
-
Question
|
|
3
|
-
Propose a schema for storing user's subscription data in their firestore user document. Currently the user looks like this
|
|
4
|
-
users/{uid}
|
|
5
|
-
{
|
|
6
|
-
auth: {
|
|
7
|
-
uid: string,
|
|
8
|
-
email: string,
|
|
9
|
-
},
|
|
10
|
-
roles: {
|
|
11
|
-
admin: boolean,
|
|
12
|
-
},
|
|
13
|
-
... (other stuff that is not really relevant)
|
|
14
|
-
}
|
|
15
|
-
I will be using a variety of payment processors including Stripe and PayPal, so I need a flexible way to store subscription data that can work with multiple providers.
|
|
16
|
-
Before inserting the subscription data, we wil need to receive the processor webhooks.
|
|
17
|
-
We will be keeping track of the subcsription data in the user doc AS WELL AS a dedicated subscription doc where we can have more information
|
|
18
|
-
Thus, the user doc doesnt need to contain the entire subscription Object, just enough to grant the user access to premium features in the backend or frontend as well as display important info in the user's account page like next billing date, plan name, status, anything else that is important.
|
|
19
|
-
Also, since we will be checking subscription status often, I thought it would be nice to store 2 main objects:
|
|
20
|
-
1. the original subscirpiton object from the payment provider, unmodified
|
|
21
|
-
2. a unified and standardized subscription object that we define, so that when checking subscription status we dont have to deal with the differences between payment providers (both for displaying info and for checking status/plan/etc to grant access when making requests or on the frontend)
|
|
22
|
-
We could store BOTH in both the user doc and the subscription doc, or only store the unified object in the user doc and both in the subscription doc.
|
|
23
|
-
|
|
24
|
-
For our standardized Object, we should be able to get the current plan and whether the subscription is active or not EXTREMELY easily. LIke a single if statement, allowing us to grant access if if the user is premium or whatever.
|
|
25
|
-
|
|
26
|
-
However, i would like it to be flexible enough so that we can show something like:
|
|
27
|
-
- User is on premium plan and paid up --> grant access to premium features, show "You are Premium and your next billing date is X"
|
|
28
|
-
- User is on premium plan but payment failed --> restrict access to premium features, show "Your payment failed, please update your payment method"
|
|
29
|
-
- User was on premium plan but cancelled --> restrict access to premium features, show "You WERE premium but it was cancelled so now youre on Free plan"
|
|
30
|
-
- User was on premium plan but cancellation is pending --> grant access to premium features, show "You are Premium until X date when your plan will be cancelled"
|
|
31
|
-
- User is on trial --> grant access to premium features, show "You are on a free trial that ends on X date"
|
|
32
|
-
So essentially we need a way to be able to determine all of these different scenarios EASILY (SINGLE IF STATEMENT)
|
|
33
|
-
|
|
34
|
-
I know all payment proivders are different and ahve different concepts of how exaclty a subscirption is active, cancelled, past due, trialing, etc but we need to come up with a unified way of representing this data in our standardized object so that we can easily check status and display info regardless of payment provider.
|
|
35
|
-
|
|
36
|
-
Like, i i think stripe you can "cancel at period end" and thus the sub will not actually be cancelled until the end of the billing period, but paypal might be slightly different.
|
|
37
|
-
|
|
38
|
-
BEM API ENDPOINTS
|
|
39
|
-
* For our payment system to work, we shoudl implemnt some BEM API endpoints to create, listen for webhooks, and manage subscriptions.
|
|
40
|
-
* anytime there is an aciton that handles multiple payment providers, we should have the entryppoint import a file for each provider, where each provider handles the request in its own way, but STILL STANDARDIZED and similar across all providers.
|
|
41
|
-
|
|
42
|
-
backend-manager/payments/intent
|
|
43
|
-
* handle creating payment intents or equivalent in other providers
|
|
44
|
-
* various checks like
|
|
45
|
-
* is the user currently subscribed? if so block
|
|
46
|
-
* is the user allowed to have a trial (havent had one before)? if not block their trial
|
|
47
|
-
* validate their gcaptcha token. block if invalid or missing
|
|
48
|
-
* create the payment intent or equivalent at "payments-intents/{id}" in firestore
|
|
49
|
-
|
|
50
|
-
backend-manager/payments/webhook (or something similar)
|
|
51
|
-
* handle receiving webhooks from payment providers to update subscription status
|
|
52
|
-
* different file for processing each paymnt processor (returning some comon things like the event id)
|
|
53
|
-
* various checks like
|
|
54
|
-
* verify the webhook by checking the querystring for the BEM token (same as .env BACKEND_MANAGER_KEY)
|
|
55
|
-
* check for payment-webhooks/{id} doc to see if we already processed this webhook (id is provided by the payment provider in the webhook payload)
|
|
56
|
-
* Immediately save the raw webhook data to "payments-webhooks/{id}" in firestore so we can return a 200 as soon as possible. THe webhook will be processed in a firestore function trigger onWrite for that doc (status === pending)
|
|
57
|
-
|
|
58
|
-
Firestore trigger for payments-webhooks/{id}
|
|
59
|
-
* process the webhook data and update the user's subscription data in both their user doc and their subscription doc
|
|
60
|
-
* various checks like
|
|
61
|
-
* if status === completed, do nothing
|
|
62
|
-
|
|
63
|
-
THen, we need to plan an effective way to test all of these scenarios in our emualted testing environment which you can explore here: /Users/ian/Developer/Repositories/ITW-Creative-Works/backend-manager/src/test
|
|
64
|
-
* we should be able to START with certain subscripton levels (basic/free, premium etc) and then see how events influence and change the subscription status and data in the user doc, subscription doc, webhook event doc, etc
|
|
65
|
-
|
|
66
|
-
So webhook comes in --> save immediateyl to return 200 to the payment provider --> process the webhook in a separate function trigger to update subscription data and user access (reprocess if something goes wrong, etc)
|