Skip to content

Commit a26b4f2

Browse files
authored
Add trial, purchase handlers (#934)
- **add config loading from window.__SKUILDER_CONFIG__** - **bump: version 0.1.13-10**
2 parents de6c1a6 + dd4d752 commit a26b4f2

File tree

16 files changed

+302
-17
lines changed

16 files changed

+302
-17
lines changed

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "0.1.13-9",
6+
"version": "0.1.13-10",
77
"type": "module",
88
"description": "CLI scaffolding tool for vue-skuilder projects",
99
"bin": {

packages/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "0.1.13-9",
6+
"version": "0.1.13-10",
77
"license": "MIT",
88
"main": "dist/index.js",
99
"module": "dist/index.esm.js",
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Runtime Configuration
2+
3+
## Overview
4+
5+
The `common-ui` library supports runtime configuration through a global `window.__SKUILDER_CONFIG__` object. This is necessary because library code is pre-built and cannot access build-time environment variables from consuming applications.
6+
7+
## Configuration Priority
8+
9+
Configuration values are resolved in this order:
10+
1. **Build-time env vars** (`import.meta.env.VITE_*`) - Only works if the consuming app's bundler processes the library code
11+
2. **Runtime config** (`window.__SKUILDER_CONFIG__`) - Always works, set by consuming app at startup
12+
3. **Fallback** - Empty string or default values
13+
14+
## Usage in Consuming Apps
15+
16+
Set `window.__SKUILDER_CONFIG__` **before** importing any `@vue-skuilder` packages:
17+
18+
```typescript
19+
// In your main.ts / main.js - BEFORE imports
20+
window.__SKUILDER_CONFIG__ = {
21+
apiBase: '/express', // API base path for auth/backend calls
22+
// Add other runtime config here as needed
23+
};
24+
25+
// Now import vue-skuilder packages
26+
import { useAuthStore } from '@vue-skuilder/common-ui';
27+
```
28+
29+
## Available Configuration
30+
31+
### `apiBase` (string)
32+
33+
Base path for API calls to the Express backend.
34+
35+
- **Default**: `''` (empty string, uses relative paths)
36+
- **Example**: `'/express'` - prepends `/express` to all auth API calls
37+
- **Used by**: `authAPI.ts` service functions
38+
39+
**Example**:
40+
```typescript
41+
window.__SKUILDER_CONFIG__ = {
42+
apiBase: '/express',
43+
};
44+
45+
// Results in calls like:
46+
// - /express/auth/send-verification
47+
// - /express/auth/verify
48+
// - /express/auth/status
49+
```
50+
51+
## Debugging
52+
53+
All services that use runtime config will log their configuration source and resolved values:
54+
55+
```
56+
[authAPI] getApiBase() called
57+
[authAPI] source: window.__SKUILDER_CONFIG__.apiBase
58+
[authAPI] result: /express
59+
```
60+
61+
## TypeScript Support
62+
63+
The global type declaration is included in the library:
64+
65+
```typescript
66+
declare global {
67+
interface Window {
68+
__SKUILDER_CONFIG__?: {
69+
apiBase?: string;
70+
[key: string]: any;
71+
};
72+
}
73+
}
74+
```
75+
76+
## Adding New Config Values
77+
78+
When adding new runtime config values:
79+
80+
1. Add the property to the `Window.__SKUILDER_CONFIG__` interface
81+
2. Document it in this file
82+
3. Add appropriate logging when the value is accessed
83+
4. Consider build-time env var as primary source, runtime config as fallback

packages/common-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "0.1.13-9",
6+
"version": "0.1.13-10",
77
"main": "./dist/common-ui.umd.js",
88
"module": "./dist/common-ui.es.js",
99
"types": "./dist/index.d.ts",

packages/common-ui/src/services/authAPI.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,46 @@
11
/**
22
* Authentication API service for interacting with Express backend auth endpoints.
3-
* Uses configurable API base path from environment or falls back to relative paths.
3+
* Uses configurable API base path from environment or runtime config.
44
*/
55

6-
// Get API base path from environment, defaulting to empty string for relative paths
6+
// Global runtime configuration (set by consuming app)
7+
declare global {
8+
interface Window {
9+
__SKUILDER_CONFIG__?: {
10+
apiBase?: string;
11+
[key: string]: any;
12+
};
13+
}
14+
}
15+
16+
// Get API base path: check env first, then runtime config, then fallback to empty
717
const getApiBase = (): string => {
18+
let source = 'fallback (empty string)';
19+
let result = '';
20+
21+
// Try import.meta.env first (build-time, only works in consuming app builds)
822
if (typeof import.meta !== 'undefined' && import.meta.env) {
923
const base = import.meta.env.VITE_API_BASE_URL;
1024
if (base) {
11-
// Remove trailing slash if present, ensure leading slash
1225
const cleaned = base.replace(/\/$/, '');
13-
return cleaned.startsWith('/') ? cleaned : `/${cleaned}`;
26+
result = cleaned.startsWith('/') ? cleaned : `/${cleaned}`;
27+
source = 'import.meta.env.VITE_API_BASE_URL';
1428
}
1529
}
16-
return '';
30+
31+
// Fallback to runtime config (works in library builds)
32+
if (!result && typeof window !== 'undefined' && window.__SKUILDER_CONFIG__?.apiBase) {
33+
const base = window.__SKUILDER_CONFIG__.apiBase;
34+
const cleaned = base.replace(/\/$/, '');
35+
result = cleaned.startsWith('/') ? cleaned : `/${cleaned}`;
36+
source = 'window.__SKUILDER_CONFIG__.apiBase';
37+
}
38+
39+
console.log('[authAPI] getApiBase() called');
40+
console.log('[authAPI] source:', source);
41+
console.log('[authAPI] result:', result);
42+
43+
return result;
1744
};
1845

1946
export interface AuthResponse {

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "0.1.13-9",
6+
"version": "0.1.13-10",
77
"type": "module",
88
"main": "dist/index.js",
99
"module": "dist/index.mjs",

packages/courseware/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "0.1.13-9",
6+
"version": "0.1.13-10",
77
"type": "module",
88
"main": "./dist/index.cjs.js",
99
"module": "./dist/index.mjs",

packages/db/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "0.1.13-9",
6+
"version": "0.1.13-10",
77
"description": "Database layer for vue-skuilder",
88
"main": "dist/index.js",
99
"module": "dist/index.mjs",

packages/edit-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "0.1.13-9",
6+
"version": "0.1.13-10",
77
"main": "./dist/edit-ui.umd.js",
88
"module": "./dist/edit-ui.es.js",
99
"types": "./dist/index.d.ts",

packages/express/.env.development

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ COUCHDB_PASSWORD=password
99
NODE_ENV=platform
1010

1111
VERSION=localdev
12+
13+
# Shared secret for payment webhook authorization (Stripe → /express/permissions)
14+
# Must match PERMISSIONS_SECRET in business backend .env
15+
PERMISSIONS_SECRET=dev-permissions-secret-12345

0 commit comments

Comments
 (0)