@haatlabs-core/templates 0.21.0 → 0.22.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haatlabs-core/templates",
3
- "version": "0.21.0",
3
+ "version": "0.22.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/tsconfig": "0.21.0",
40
- "@haatlabs-core/vitest-config": "0.21.0"
39
+ "@haatlabs-core/tsconfig": "0.22.0",
40
+ "@haatlabs-core/vitest-config": "0.22.0"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "rm -rf dist && tsc -p tsconfig.build.json",
@@ -81,6 +81,11 @@ const ROUTES: Record<
81
81
 
82
82
  'GET /api/v1/auth/me': { access: 'authenticated' },
83
83
  'POST /api/v1/auth/logout': { access: 'authenticated' },
84
+ // Several organizations per person: list them and move the session to another.
85
+ 'GET /api/v1/auth/organizations': { access: 'authenticated' },
86
+ 'POST /api/v1/auth/organization': { access: 'authenticated', body: ['organizationId'] },
87
+ // Spends the one-time code "Open dashboard" made; the code is the credential.
88
+ 'POST /api/v1/auth/handoff': { access: 'public', body: ['code'] },
84
89
  // The embedded app only; acts on the caller's own organization (email-sign-in.int.test.ts).
85
90
  'GET /api/v1/auth/email-sign-in': {
86
91
  access: 'authenticated',
@@ -164,6 +169,12 @@ const ROUTES: Record<
164
169
  'GET /api/v1/auth/shopify/install': { access: 'public' },
165
170
  'GET /api/v1/auth/shopify/callback': { access: 'public' },
166
171
  'POST /api/v1/webhooks/shopify': { access: 'public' },
172
+ // "Open dashboard": the embedded app's owner asks for a one-time link into the dashboard.
173
+ 'POST /api/v1/auth/shopify/dashboard-handoff': {
174
+ access: 'authenticated',
175
+ embeddedOnly: true,
176
+ wholeOrganization: true,
177
+ },
167
178
 
168
179
  'POST /api/v1/admin/login': { access: 'public' },
169
180
  'POST /api/v1/admin/logout': { access: 'admin' },
@@ -411,7 +422,7 @@ describe('security sweep', () => {
411
422
 
412
423
  it("refuses the organization's own routes to the staff of a store a dashboard account connected, and only those", async () => {
413
424
  const routes = [...routesWith('authenticated'), ...routesWith('tenant')];
414
- expect(routes.filter(wholeOrganization).length).toBe(8);
425
+ expect(routes.filter(wholeOrganization).length).toBe(9);
415
426
  for (const route of routes.filter(wholeOrganization)) {
416
427
  const res = await send(route, aliceEmbedded);
417
428
  expect(res.statusCode, route).toBe(403);
@@ -444,7 +455,7 @@ describe('security sweep', () => {
444
455
 
445
456
  it('refuses the embedded-only routes to a dashboard session, and asks Shopify nothing', async () => {
446
457
  const routes = Object.keys(ROUTES).filter(embeddedOnly);
447
- expect(routes.length).toBe(6);
458
+ expect(routes.length).toBe(7);
448
459
  for (const route of routes) {
449
460
  const res = await send(route, alice.headers);
450
461
  expect(res.statusCode, route).toBe(403);
@@ -567,6 +578,11 @@ const ROUTES: Record<
567
578
 
568
579
  'GET /api/v1/auth/me': { access: 'authenticated' },
569
580
  'POST /api/v1/auth/logout': { access: 'authenticated' },
581
+ // Several organizations per person: list them and move the session to another.
582
+ 'GET /api/v1/auth/organizations': { access: 'authenticated' },
583
+ 'POST /api/v1/auth/organization': { access: 'authenticated', body: ['organizationId'] },
584
+ // Spends the one-time code "Open dashboard" made; the code is the credential.
585
+ 'POST /api/v1/auth/handoff': { access: 'public', body: ['code'] },
570
586
  'GET /api/v1/plans': { access: 'authenticated' },
571
587
  'GET /api/v1/usage': { access: 'authenticated' },
572
588
  #@if standalone
@@ -38,11 +38,18 @@ describe('seeding the plans file', () => {
38
38
  priceRef: 'shopify_starter_monthly',
39
39
  currency: 'USD',
40
40
  amountMinor: 1900,
41
+ interval: 'MONTH',
41
42
  planName: 'Starter',
42
43
  },
43
44
  ]);
44
45
  expect(await billing.pricesFor('pro', 'shopify')).toEqual([
45
- { priceRef: 'shopify_pro_monthly', currency: 'USD', amountMinor: 4900, planName: 'Pro' },
46
+ {
47
+ priceRef: 'shopify_pro_monthly',
48
+ currency: 'USD',
49
+ amountMinor: 4900,
50
+ interval: 'MONTH',
51
+ planName: 'Pro',
52
+ },
46
53
  ]);
47
54
  expect(await billing.pricesFor('pro', 'razorpay')).toHaveLength(1);
48
55
  expect((await billing.pricesOf('shopify')).map((price) => price.planCode).sort()).toEqual([
@@ -6,6 +6,8 @@
6
6
  <meta name="shopify-api-key" content="%VITE_SHOPIFY_API_KEY%" />
7
7
  <!-- App Bridge must load from Shopify's CDN, before any other script. -->
8
8
  <script src="https://cdn.shopify.com/shopifycloud/app-bridge.js"></script>
9
+ <!-- Sets the chosen light or dark theme before the page paints (a file: the CSP forbids inline scripts). -->
10
+ <script src="/theme-boot.js"></script>
9
11
  <title>@@Name@@</title>
10
12
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
11
13
  </head>
@@ -0,0 +1,6 @@
1
+ (function () {
2
+ try {
3
+ var choice = window.localStorage.getItem('haatlabs:theme');
4
+ if (choice === 'light' || choice === 'dark') document.documentElement.setAttribute('data-theme', choice);
5
+ } catch {}
6
+ })();
@@ -0,0 +1,5 @@
1
+ ALTER TABLE "plan_prices" DROP CONSTRAINT "plan_prices_plan_provider_currency_unique";--> statement-breakpoint
2
+ ALTER TABLE "memberships" ADD COLUMN "last_used_at" timestamp with time zone;--> statement-breakpoint
3
+ ALTER TABLE "plan_prices" ADD COLUMN "interval" text DEFAULT 'MONTH' NOT NULL;--> statement-breakpoint
4
+ ALTER TABLE "subscriptions" ADD COLUMN "price_interval" text DEFAULT 'MONTH' NOT NULL;--> statement-breakpoint
5
+ ALTER TABLE "plan_prices" ADD CONSTRAINT "plan_prices_plan_provider_currency_interval_unique" UNIQUE("plan_id","provider","currency","interval");