@haatlabs-core/templates 0.16.0 → 0.17.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/package.json +3 -3
- package/starter/apps/api/src/app.module.ts +6 -0
- package/starter/apps/api/src/infra/infra.module.ts +6 -0
- package/starter/apps/worker/package.json.tmpl +1 -0
- package/starter/apps/worker/src/runtime.ts +15 -0
- package/starter/dot-env.example +5 -0
- package/starter/packages/database/drizzle/0008_product_and_disposable.sql +46 -0
- package/starter/packages/database/drizzle/meta/0008_snapshot.json +1936 -0
- package/starter/packages/database/drizzle/meta/_journal.json +7 -0
- package/starter/packages/database/src/index.ts +1 -0
- package/starter/packages/database/src/repositories/admin.repository.ts +8 -2
- package/starter/packages/database/src/repositories/disposable-email.repository.ts +10 -0
- package/starter/packages/database/src/schema/billing.ts +2 -0
- package/starter/packages/database/src/schema/identity.ts +10 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haatlabs-core/templates",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "The starter files and shared project files that @haatlabs-core/cli writes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"haatlabs"
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"playwright-core": "1.63.0",
|
|
39
|
-
"@haatlabs-core/
|
|
40
|
-
"@haatlabs-core/
|
|
39
|
+
"@haatlabs-core/tsconfig": "0.17.0",
|
|
40
|
+
"@haatlabs-core/vitest-config": "0.17.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
BillingRepository,
|
|
10
10
|
ExtensionKeyRepository,
|
|
11
11
|
UserIdentityRepository,
|
|
12
|
+
DisposableEmailRepository,
|
|
12
13
|
FeatureRepository,
|
|
13
14
|
IdentityRepository,
|
|
14
15
|
#@if kindShopify
|
|
@@ -120,6 +121,11 @@ export class AppModule {
|
|
|
120
121
|
useFactory: (links: UserIdentityRepository) => links,
|
|
121
122
|
inject: [UserIdentityRepository],
|
|
122
123
|
},
|
|
124
|
+
// New accounts on throwaway mailbox domains are refused where the check is on.
|
|
125
|
+
disposableEmails: {
|
|
126
|
+
useFactory: (list: DisposableEmailRepository) => list,
|
|
127
|
+
inject: [DisposableEmailRepository],
|
|
128
|
+
},
|
|
123
129
|
},
|
|
124
130
|
connectableExtensions: config.extension.ids,
|
|
125
131
|
#@if kindShopify
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
BillingRepository,
|
|
9
9
|
ExtensionKeyRepository,
|
|
10
10
|
UserIdentityRepository,
|
|
11
|
+
DisposableEmailRepository,
|
|
11
12
|
FeatureRepository,
|
|
12
13
|
IdentityRepository,
|
|
13
14
|
WebhookEventRepository,
|
|
@@ -243,6 +244,11 @@ export class InfraModule {
|
|
|
243
244
|
useFactory: (s: DatabaseHandle) => new UserIdentityRepository(s.db),
|
|
244
245
|
inject: [SYSTEM_DB],
|
|
245
246
|
},
|
|
247
|
+
{
|
|
248
|
+
provide: DisposableEmailRepository,
|
|
249
|
+
useFactory: (s: DatabaseHandle) => new DisposableEmailRepository(s.db),
|
|
250
|
+
inject: [SYSTEM_DB],
|
|
251
|
+
},
|
|
246
252
|
#@if kindShopify
|
|
247
253
|
{
|
|
248
254
|
provide: StoreRepository,
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"@@@name@@/config": "workspace:*",
|
|
18
18
|
"@@@name@@/database": "workspace:*",
|
|
19
19
|
"@haatlabs-core/logger": "^@@platformVersion@@",
|
|
20
|
+
"@haatlabs-core/nest-auth": "^@@platformVersion@@",
|
|
20
21
|
"@@@name@@/observability": "workspace:*",
|
|
21
22
|
"@@@name@@/queue": "workspace:*",
|
|
22
23
|
"drizzle-orm": "^0.45.3",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AppConfig } from '@@@name@@/config';
|
|
2
2
|
import {
|
|
3
|
+
DisposableEmailRepository,
|
|
3
4
|
OutboxRepository,
|
|
4
5
|
#@if kindShopify
|
|
5
6
|
SystemBillingRepository,
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
import { ShopifyAdminClient, StoreAccessTokens, TokenCipher } from '@@@name@@/shopify';
|
|
15
16
|
#@end
|
|
16
17
|
import { createLogger, watchRedis } from '@haatlabs-core/logger';
|
|
18
|
+
import { startDisposableDomainRefresh } from '@haatlabs-core/nest-auth/disposable';
|
|
17
19
|
import { createMetrics } from '@@@name@@/observability';
|
|
18
20
|
import type { Metrics } from '@@@name@@/observability';
|
|
19
21
|
import {
|
|
@@ -159,6 +161,18 @@ export async function startWorker(
|
|
|
159
161
|
{ metrics },
|
|
160
162
|
);
|
|
161
163
|
|
|
164
|
+
// The disposable-domain list: filled and refreshed daily, by one process at a time.
|
|
165
|
+
const disposable = config.auth.disposableEmails?.check
|
|
166
|
+
? startDisposableDomainRefresh({
|
|
167
|
+
store: new DisposableEmailRepository(system.db),
|
|
168
|
+
url: config.auth.disposableEmails.url,
|
|
169
|
+
fetch: fetchImpl,
|
|
170
|
+
logger,
|
|
171
|
+
redis,
|
|
172
|
+
appName: '@@name@@',
|
|
173
|
+
})
|
|
174
|
+
: null;
|
|
175
|
+
|
|
162
176
|
logger.info('Worker started');
|
|
163
177
|
|
|
164
178
|
const stop = async (): Promise<void> => {
|
|
@@ -166,6 +180,7 @@ export async function startWorker(
|
|
|
166
180
|
// Takes no more work and finishes what it has in hand.
|
|
167
181
|
await consumer?.stop();
|
|
168
182
|
#@end
|
|
183
|
+
disposable?.stop();
|
|
169
184
|
await relay.stop();
|
|
170
185
|
if (health) {
|
|
171
186
|
await new Promise<void>((resolve) => {
|
package/starter/dot-env.example
CHANGED
|
@@ -118,6 +118,11 @@ SIGN_IN_EMAIL=true
|
|
|
118
118
|
# Signing in with Google and GitHub: the shared Haatlabs Google OAuth client and GitHub App
|
|
119
119
|
# (see social-sign-in-setup.md). Both of a pair set turns that button on; leave a pair empty
|
|
120
120
|
# and it is not offered. The callback is <API_BASE_URL>/api/v1/auth/oauth/<google|github>/callback.
|
|
121
|
+
# New accounts on throwaway mailbox domains (mailinator and ~98,000 others) are refused:
|
|
122
|
+
# on|off, default on in production only. The list is refreshed daily from
|
|
123
|
+
# DISPOSABLE_EMAIL_DOMAINS_URL (https; the community list when empty).
|
|
124
|
+
DISPOSABLE_EMAIL_CHECK=
|
|
125
|
+
DISPOSABLE_EMAIL_DOMAINS_URL=
|
|
121
126
|
GOOGLE_OAUTH_CLIENT_ID=
|
|
122
127
|
GOOGLE_OAUTH_CLIENT_SECRET=
|
|
123
128
|
GITHUB_OAUTH_CLIENT_ID=
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
CREATE TABLE "disposable_email_domains" (
|
|
2
|
+
"domain" text PRIMARY KEY NOT NULL
|
|
3
|
+
);
|
|
4
|
+
--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "subscriptions" DROP CONSTRAINT "subscriptions_organization_id_unique";--> statement-breakpoint
|
|
6
|
+
DROP INDEX "plans_one_default_idx";--> statement-breakpoint
|
|
7
|
+
ALTER TABLE "plans" ADD COLUMN "product" text DEFAULT 'app' NOT NULL;--> statement-breakpoint
|
|
8
|
+
ALTER TABLE "subscriptions" ADD COLUMN "product" text DEFAULT 'app' NOT NULL;--> statement-breakpoint
|
|
9
|
+
CREATE UNIQUE INDEX "plans_one_default_idx" ON "plans" USING btree ("product") WHERE "plans"."is_default";--> statement-breakpoint
|
|
10
|
+
ALTER TABLE "subscriptions" ADD CONSTRAINT "subscriptions_org_product_unique" UNIQUE("organization_id","product");--> statement-breakpoint
|
|
11
|
+
-- The app's own plan decides priority: a plan of another product never does.
|
|
12
|
+
CREATE OR REPLACE FUNCTION organization_goes_first() RETURNS boolean
|
|
13
|
+
LANGUAGE sql STABLE
|
|
14
|
+
AS $$
|
|
15
|
+
WITH org AS (
|
|
16
|
+
SELECT NULLIF(current_setting('app.organization_id', true), '')::uuid AS id
|
|
17
|
+
),
|
|
18
|
+
held AS (
|
|
19
|
+
SELECT s.plan_id
|
|
20
|
+
FROM subscriptions s
|
|
21
|
+
JOIN org ON s.organization_id = org.id
|
|
22
|
+
WHERE s.status = 'ACTIVE'
|
|
23
|
+
AND s.product = 'app'
|
|
24
|
+
AND s.period_start <= now()
|
|
25
|
+
AND (now() < s.period_end OR (s.provider = 'shopify' AND s.provider_ended_at IS NULL))
|
|
26
|
+
LIMIT 1
|
|
27
|
+
),
|
|
28
|
+
plan AS (
|
|
29
|
+
SELECT COALESCE(
|
|
30
|
+
(SELECT plan_id FROM held),
|
|
31
|
+
(SELECT id FROM plans WHERE is_default AND product = 'app' LIMIT 1)
|
|
32
|
+
) AS id
|
|
33
|
+
)
|
|
34
|
+
SELECT CASE
|
|
35
|
+
WHEN (SELECT id FROM org) IS NULL THEN false
|
|
36
|
+
ELSE COALESCE(
|
|
37
|
+
(
|
|
38
|
+
SELECT f.limit_value = 1
|
|
39
|
+
FROM plan_features f
|
|
40
|
+
JOIN plan ON f.plan_id = plan.id
|
|
41
|
+
WHERE f.feature_key = 'PRIORITY'
|
|
42
|
+
),
|
|
43
|
+
false
|
|
44
|
+
)
|
|
45
|
+
END
|
|
46
|
+
$$;
|