@haatlabs-core/templates 0.15.0 → 0.16.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,13 @@
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
53
60
  }
54
61
  ]
55
- }
62
+ }
@@ -4,6 +4,7 @@ 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';
7
8
  export * from './repositories/api-key.repository';
8
9
  export * from './repositories/extension-key.repository';
9
10
  export * from './repositories/system-store.repository';
@@ -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
+ }
@@ -10,6 +10,8 @@ import {
10
10
  platformAdminColumns,
11
11
  timestamps as sharedTimestamps,
12
12
  userColumns,
13
+ userIdentityColumns,
14
+ userIdentityIndexes,
13
15
  } from '@haatlabs-core/db-core';
14
16
 
15
17
  // The shared tables are built from the platform's columns (@haatlabs-core/db-core); the columns
@@ -38,6 +40,16 @@ export const extensionKeys = pgTable(
38
40
  (t) => extensionKeyIndexes(t),
39
41
  );
40
42
 
43
+ /**
44
+ * The Google or GitHub accounts that sign in as a user: which provider and its ID, never its
45
+ * tokens. Read through the system connection only.
46
+ */
47
+ export const userIdentities = pgTable(
48
+ 'user_identities',
49
+ userIdentityColumns({ users }),
50
+ (t) => userIdentityIndexes(t),
51
+ );
52
+
41
53
  /**
42
54
  * The people who run the platform. Not merchants' users: they belong to no organization,
43
55
  * 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({