@haatlabs-core/templates 0.15.1 → 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.
@@ -50,6 +50,20 @@
50
50
  "when": 1792579465890,
51
51
  "tag": "0006_platform_audit",
52
52
  "breakpoints": true
53
+ },
54
+ {
55
+ "idx": 7,
56
+ "version": "7",
57
+ "when": 1794494308207,
58
+ "tag": "0007_user_identities",
59
+ "breakpoints": true
60
+ },
61
+ {
62
+ "idx": 8,
63
+ "version": "7",
64
+ "when": 1794501701224,
65
+ "tag": "0008_product_and_disposable",
66
+ "breakpoints": true
53
67
  }
54
68
  ]
55
- }
69
+ }
@@ -4,6 +4,8 @@ export * from './tenant';
4
4
  export { runMigrations } from './migrate';
5
5
  export * from './repositories/shared';
6
6
  export * from './repositories/identity.repository';
7
+ export * from './repositories/user-identity.repository';
8
+ export * from './repositories/disposable-email.repository';
7
9
  export * from './repositories/api-key.repository';
8
10
  export * from './repositories/extension-key.repository';
9
11
  export * from './repositories/system-store.repository';
@@ -72,6 +72,9 @@ const quantity = sql<number>`coalesce(sum(${usageRecords.quantity}), 0)::int`;
72
72
  * The platform administrators' accounts (the shared PlatformAdminRepository: sign-in,
73
73
  * the operator's command) and what they see across every tenant.
74
74
  */
75
+ /** The app's own product (`@haatlabs-core/billing`'s DEFAULT_PRODUCT): what the panel shows. */
76
+ const DEFAULT_PRODUCT = 'app';
77
+
75
78
  export class SystemAdminRepository extends PlatformAdminRepository {
76
79
  constructor(systemDb: Database) {
77
80
  super(systemDb, { platformAdmins });
@@ -167,11 +170,13 @@ export class SystemAdminRepository extends PlatformAdminRepository {
167
170
  updatedAt: subscriptions.updatedAt,
168
171
  })
169
172
  .from(subscriptions)
170
- .innerJoin(plans, eq(plans.id, subscriptions.planId)),
173
+ .innerJoin(plans, eq(plans.id, subscriptions.planId))
174
+ // The panel shows the app's own product: one subscription per organization.
175
+ .where(eq(subscriptions.product, DEFAULT_PRODUCT)),
171
176
  db
172
177
  .select({ planId: plans.id, code: plans.code, name: plans.name })
173
178
  .from(plans)
174
- .where(eq(plans.isDefault, true)),
179
+ .where(and(eq(plans.isDefault, true), eq(plans.product, DEFAULT_PRODUCT))),
175
180
  db.select().from(organizationFeatures),
176
181
  db
177
182
  .select({
@@ -295,6 +300,7 @@ export class SystemAdminRepository extends PlatformAdminRepository {
295
300
  return this.systemDb
296
301
  .select({ code: plans.code, name: plans.name, isDefault: plans.isDefault })
297
302
  .from(plans)
303
+ .where(eq(plans.product, DEFAULT_PRODUCT))
298
304
  .orderBy(asc(plans.position), asc(plans.code));
299
305
  }
300
306
  }
@@ -0,0 +1,10 @@
1
+ import { DisposableEmailRepository as SharedDisposableEmailRepository } from '@haatlabs-core/db-core';
2
+ import type { Database } from '../client';
3
+ import { disposableEmailDomains } from '../schema';
4
+
5
+ /** The throwaway mailbox domains a new account's address is checked against. */
6
+ export class DisposableEmailRepository extends SharedDisposableEmailRepository {
7
+ constructor(systemDb: Database) {
8
+ super(systemDb, { disposableEmailDomains });
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ import { UserIdentityRepository as SharedUserIdentityRepository } from '@haatlabs-core/db-core';
2
+ import type { Database } from '../client';
3
+ import { auditLogs, userIdentities } from '../schema';
4
+
5
+ /** Which user a Google or GitHub account signs in as. */
6
+ export class UserIdentityRepository extends SharedUserIdentityRepository {
7
+ constructor(systemDb: Database) {
8
+ super(systemDb, { userIdentities, auditLogs });
9
+ }
10
+ }
@@ -14,6 +14,7 @@ import {
14
14
  planPriceColumns,
15
15
  planPriceIndexes,
16
16
  subscriptionColumns,
17
+ subscriptionIndexes,
17
18
  usageRecordColumns,
18
19
  usageRecordIndexes,
19
20
  } from '@haatlabs-core/db-core';
@@ -34,6 +35,7 @@ export const planFeatures = pgTable('plan_features', planFeatureColumns({ plans
34
35
  export const subscriptions = pgTable(
35
36
  'subscriptions',
36
37
  subscriptionColumns({ organizations, plans }),
38
+ (t) => subscriptionIndexes(t),
37
39
  );
38
40
 
39
41
  /** What a plan costs through each gateway, per currency, and the gateway's own ID for it. */
@@ -10,6 +10,9 @@ import {
10
10
  platformAdminColumns,
11
11
  timestamps as sharedTimestamps,
12
12
  userColumns,
13
+ userIdentityColumns,
14
+ disposableEmailDomainColumns,
15
+ userIdentityIndexes,
13
16
  } from '@haatlabs-core/db-core';
14
17
 
15
18
  // The shared tables are built from the platform's columns (@haatlabs-core/db-core); the columns
@@ -38,6 +41,25 @@ export const extensionKeys = pgTable(
38
41
  (t) => extensionKeyIndexes(t),
39
42
  );
40
43
 
44
+ /**
45
+ * Throwaway mailbox domains: no account is made for an address on one. Replaced whole by the
46
+ * worker's daily refresh; read through the system connection only.
47
+ */
48
+ export const disposableEmailDomains = pgTable(
49
+ 'disposable_email_domains',
50
+ disposableEmailDomainColumns(),
51
+ );
52
+
53
+ /**
54
+ * The Google or GitHub accounts that sign in as a user: which provider and its ID, never its
55
+ * tokens. Read through the system connection only.
56
+ */
57
+ export const userIdentities = pgTable(
58
+ 'user_identities',
59
+ userIdentityColumns({ users }),
60
+ (t) => userIdentityIndexes(t),
61
+ );
62
+
41
63
  /**
42
64
  * The people who run the platform. Not merchants' users: they belong to no organization,
43
65
  * sign in apart, and are created by an operator's command only. The runtime role has no
@@ -20,6 +20,7 @@ import {
20
20
  StoreListResponseSchema,
21
21
  #@end
22
22
  } from '@@@name@@/contracts';
23
+ import { SignInProvidersResponseSchema } from '@haatlabs-core/auth-contracts';
23
24
  import type {
24
25
  #@if kindShopify
25
26
  StoreListResponse,
@@ -90,6 +91,10 @@ export interface ApiClient {
90
91
  requestSignInCode(body: SignInCodeRequest): Promise<void>;
91
92
  /** Signs in with the code; an email with no account gets one. */
92
93
  signInWithCode(body: SignInVerifyRequest): Promise<MeResponse>;
94
+ /** The social sign-in providers the API offers (Google, GitHub). */
95
+ signInProviders(): Promise<{ providers: ('google' | 'github')[] }>;
96
+ /** Where the browser goes to sign in with one of them. */
97
+ oauthStartUrl(provider: 'google' | 'github'): string;
93
98
  logout(): Promise<void>;
94
99
  #@if kindShopify
95
100
  /**
@@ -187,6 +192,8 @@ export function createApiClient(options: {
187
192
  void (await call('POST', '/api/v1/auth/code', OkSchema, body)),
188
193
  signInWithCode: async (body) =>
189
194
  remember(await call('POST', '/api/v1/auth/verify', MeResponseSchema, body)),
195
+ signInProviders: () => call('GET', '/api/v1/auth/providers', SignInProvidersResponseSchema),
196
+ oauthStartUrl: (provider) => `${options.baseUrl ?? ''}/api/v1/auth/oauth/${provider}/start`,
190
197
  logout: async () => void (await call('POST', '/api/v1/auth/logout', OkSchema)),
191
198
  #@if kindShopify
192
199
  emailSignIn: () => call('GET', '/api/v1/auth/email-sign-in', EmailSignInResponseSchema),
@@ -221,10 +221,10 @@ describe('UsagePage', () => {
221
221
  within(table)
222
222
  .getAllByRole('button')
223
223
  .map((button) => button.getAttribute('aria-label')),
224
- ).toEqual(['Pay ₹3,999.00 with Razorpay: Pro', 'Pay $49.00 with Stripe: Pro']);
224
+ ).toEqual(['Upgrade to Pro: ₹3,999.00 a month', 'Upgrade to Pro: $49.00 a month']);
225
225
 
226
226
  await userEvent.click(
227
- within(table).getByRole('button', { name: 'Pay $49.00 with Stripe: Pro' }),
227
+ within(table).getByRole('button', { name: 'Upgrade to Pro: $49.00 a month' }),
228
228
  );
229
229
  await waitFor(() =>
230
230
  expect(client.startCheckout).toHaveBeenCalledWith({
@@ -254,7 +254,7 @@ describe('UsagePage', () => {
254
254
  );
255
255
  const table = await plansTable();
256
256
  await userEvent.click(
257
- within(table).getByRole('button', { name: 'Pay ₹3,999.00 with Razorpay: Pro' }),
257
+ within(table).getByRole('button', { name: 'Upgrade to Pro: ₹3,999.00 a month' }),
258
258
  );
259
259
  expect((await screen.findByRole('alert')).textContent).toBe(
260
260
  'This plan cannot be bought through that provider',
@@ -87,6 +87,8 @@ export const fakeClient = (overrides: Partial<ApiClient> = {}): ApiClient => ({
87
87
  me: vi.fn().mockResolvedValue(me),
88
88
  requestSignInCode: vi.fn().mockResolvedValue(undefined),
89
89
  signInWithCode: vi.fn().mockResolvedValue(me),
90
+ signInProviders: vi.fn().mockResolvedValue({ providers: [] }),
91
+ oauthStartUrl: (provider) => `/api/v1/auth/oauth/${provider}/start`,
90
92
  logout: vi.fn().mockResolvedValue(undefined),
91
93
  #@if kindShopify
92
94
  emailSignIn: vi.fn().mockResolvedValue({