@thinkform/core (0.1.12)
Installation
@thinkform:registry=npm install @thinkform/core@0.1.12"@thinkform/core": "0.1.12"About this package
@thinkform/core
The foundational Angular library for ThinkForm Studio applications. This library provides centralized API handling, authentication interceptors, and shared business services.
🚀 Features
- Modern Providers: Clean application bootstrapping via
provideThinkformCore(). - Smart API Service: Automated Base URL resolution (Local vs. Prod) and URL normalization.
- Functional Interceptors: Lightweight HTTP interceptor for JWT injection and
withCredentialssupport. - Standalone Ready: All pipes (e.g.,
NewlinePipe) and services are standalone-compatible.
📦 Installation
This library is part of the ThinkForm monorepo. It is automatically linked via Nx path mappings.
To use it in a frontend application, ensure you have the following peer dependencies:
@angular/core(^21.2.0)@angular/common(^21.2.0)rxjs(~7.8.2)
🛠 Usage
1. Bootstrap the Library
In your app.config.ts, add the core providers. This handles HttpClient setup and interceptors automatically.
import { provideThinkformCore } from '@thinkform/core';
export const appConfig: ApplicationConfig = {
providers: [
provideThinkformCore(),
// ... other providers
]
};
2. Using the ApiService
The ApiService should be used for all backend communication to ensure the correct environment URL is used.
import { ApiService } from '@thinkform/core';
@Injectable({ providedIn: 'root' })
export class MyService {
private api = inject(ApiService);
getData() {
return this.api.get('api/my-endpoint');
}
}
3. Contact & Scheduling
The ContactService provides helpers for Calendly-style scheduling and Google Calendar event creation.
import { ContactService } from '@thinkform/core';
@Component({ ... })
export class ContactComponent {
private contact = inject(ContactService);
bookCall() {
this.contact.openDefaultScheduler();
}
}
🏗 Architecture
Environment Resolution
The ApiService resolves the backend URL in the following priority:
Local Development: If the hostname is localhost, it defaults to http://localhost:3000.
Injected Global: Uses window.__PAYLOAD_API_URL__ (Browser) or process.env.PAYLOAD_API_URL (Server).
Authentication
The tokenInterceptor automatically:
Appends Authorization: Bearer <token> if auth_token exists in localStorage.
Sets withCredentials: true for all requests to support secure session cookies.
🧪 Development
Build
Run npx nx build core to generate the Angular Package Format (APF) output in dist/libs/core.
Lint
Run npx nx lint core to check for code style issues.
Test
Run npx nx test core to execute Jest unit tests.
Dependencies
Peer dependencies
| ID | Version |
|---|---|
| @angular/common | ^21.2.0 |
| @angular/core | ^21.2.0 |
| @angular/platform-browser | ^21.2.0 |
| @thinkform/tokens | 0.1.12 |
| @thinkform/types | 0.1.12 |
| rxjs | ~7.8.2 |