@progalaxyelabs/ngx-stonescriptphp-client 0.0.10 → 1.0.4

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.
Files changed (31) hide show
  1. package/HLD.md +31 -0
  2. package/LICENSE +21 -0
  3. package/README.md +89 -2
  4. package/dist/ngx-stonescriptphp-client/README.md +186 -0
  5. package/{fesm2022 → dist/ngx-stonescriptphp-client/fesm2022}/progalaxyelabs-ngx-stonescriptphp-client.mjs +262 -46
  6. package/dist/ngx-stonescriptphp-client/fesm2022/progalaxyelabs-ngx-stonescriptphp-client.mjs.map +1 -0
  7. package/dist/ngx-stonescriptphp-client/index.d.ts +184 -0
  8. package/docs/AUTH_COMPATIBILITY.md +310 -0
  9. package/docs/CHANGELOG.md +261 -0
  10. package/package.json +75 -18
  11. package/esm2022/lib/api-connection.service.mjs +0 -169
  12. package/esm2022/lib/api-response.model.mjs +0 -26
  13. package/esm2022/lib/auth.service.mjs +0 -14
  14. package/esm2022/lib/db.service.mjs +0 -14
  15. package/esm2022/lib/my-environment.model.mjs +0 -19
  16. package/esm2022/lib/ngx-stonescriptphp-client/ngx-stonescriptphp-client.module.mjs +0 -27
  17. package/esm2022/lib/signin-status.service.mjs +0 -23
  18. package/esm2022/lib/token.service.mjs +0 -55
  19. package/esm2022/progalaxyelabs-ngx-stonescriptphp-client.mjs +0 -5
  20. package/esm2022/public-api.mjs +0 -12
  21. package/fesm2022/progalaxyelabs-ngx-stonescriptphp-client.mjs.map +0 -1
  22. package/index.d.ts +0 -5
  23. package/lib/api-connection.service.d.ts +0 -23
  24. package/lib/api-response.model.d.ts +0 -9
  25. package/lib/auth.service.d.ts +0 -6
  26. package/lib/db.service.d.ts +0 -6
  27. package/lib/my-environment.model.d.ts +0 -20
  28. package/lib/ngx-stonescriptphp-client/ngx-stonescriptphp-client.module.d.ts +0 -10
  29. package/lib/signin-status.service.d.ts +0 -10
  30. package/lib/token.service.d.ts +0 -14
  31. package/public-api.d.ts +0 -8
package/HLD.md ADDED
@@ -0,0 +1,31 @@
1
+ # ngx-stonescriptphp-client - High Level Design
2
+
3
+ ## Overview
4
+ Official Angular HTTP client library for StoneScriptPHP backend framework.
5
+
6
+ ## Purpose
7
+ Provides type-safe HTTP calls to StoneScriptPHP APIs using auto-generated TypeScript interfaces.
8
+
9
+ ## Architecture
10
+
11
+ ### Components
12
+ - **ApiConnectionService** - HTTP client wrapper with error handling
13
+ - **AuthService** - JWT token management
14
+ - **DbService** - IndexedDB offline storage integration
15
+ - **TokenService** - Token storage and refresh logic
16
+ - **SigninStatusService** - Authentication state management
17
+
18
+ ### Flow
19
+ 1. StoneScriptPHP generates TypeScript DTOs from PHP
20
+ 2. Angular imports generated interfaces
21
+ 3. HTTP calls use interfaces for type safety
22
+ 4. Responses validated against DTOs
23
+
24
+ ## Tech Stack
25
+ - Angular >= 19.0
26
+ - RxJS >= 7.8
27
+ - TypeScript >= 5.8
28
+
29
+ ## Distribution
30
+ - Published to npm as @progalaxyelabs/ngx-stonescriptphp-client
31
+ - Future migration to @stonescriptphp namespace planned
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ProGalaxy eLabs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -7,6 +7,19 @@
7
7
 
8
8
  **Note:** While published as `@progalaxyelabs/ngx-stonescriptphp-client`, this is the official client for [StoneScriptPHP](https://stonescriptphp.org). Future versions will migrate to the `@stonescriptphp` namespace.
9
9
 
10
+ ## ✅ Authentication Support (v1.0.0+)
11
+
12
+ **Fully compatible with StoneScriptPHP Framework v2.1.x authentication!**
13
+
14
+ - ✅ **Cookie-based auth**: Secure httpOnly cookies + CSRF (StoneScriptPHP v2.1.x default)
15
+ - ✅ **Body-based auth**: Legacy mode for custom backends
16
+ - ✅ **Configurable**: Choose your auth strategy via environment config
17
+ - ✅ **All HTTP methods**: GET, POST, PUT, PATCH, DELETE with automatic token refresh
18
+
19
+ See [Configuration](#configuration) section below for setup details.
20
+
21
+ 📖 **Documentation**: [CHANGELOG](docs/CHANGELOG.md) | [Auth Compatibility](docs/AUTH_COMPATIBILITY.md)
22
+
10
23
  ---
11
24
 
12
25
  ## What is this?
@@ -27,7 +40,7 @@ This library provides the HTTP client that consumes those contracts, giving you
27
40
  - ✅ **RxJS observables** - Native Angular integration
28
41
  - ✅ **Error handling** - Consistent error responses
29
42
  - ✅ **Interceptors ready** - Add auth, logging, retry logic
30
- - ✅ **Angular 19+** - Modern Angular standalone components
43
+ - ✅ **Angular 19+ & 20+** - Modern Angular standalone components
31
44
 
32
45
  ## Installation
33
46
 
@@ -105,6 +118,80 @@ PHP Backend (StoneScriptPHP) Angular Frontend
105
118
  3. Import generated TypeScript interfaces in Angular
106
119
  4. Make type-safe HTTP calls
107
120
 
121
+ ## Configuration
122
+
123
+ ### Authentication Modes (v1.0.0+)
124
+
125
+ Choose your authentication strategy based on your backend:
126
+
127
+ #### Cookie-based Auth (Recommended - StoneScriptPHP v2.1.x)
128
+
129
+ ```typescript
130
+ // environment.ts
131
+ export const environment = {
132
+ production: false,
133
+ apiServer: {
134
+ host: 'http://localhost:8000/'
135
+ },
136
+ auth: {
137
+ mode: 'cookie', // Default mode
138
+ refreshEndpoint: '/auth/refresh', // Default endpoint
139
+ useCsrf: true, // Default for cookie mode
140
+ refreshTokenCookieName: 'refresh_token', // Default
141
+ csrfTokenCookieName: 'csrf_token', // Default
142
+ csrfHeaderName: 'X-CSRF-Token' // Default
143
+ }
144
+ }
145
+ ```
146
+
147
+ **Features:**
148
+ - Secure httpOnly cookies prevent XSS attacks
149
+ - CSRF token protection
150
+ - Token rotation on refresh
151
+ - Works with StoneScriptPHP `AuthRoutes::register($router)`
152
+
153
+ #### Body-based Auth (Legacy/Custom Backends)
154
+
155
+ ```typescript
156
+ // environment.ts
157
+ export const environment = {
158
+ production: false,
159
+ apiServer: {
160
+ host: 'http://localhost:8000/'
161
+ },
162
+ auth: {
163
+ mode: 'body',
164
+ refreshEndpoint: '/user/refresh_access',
165
+ useCsrf: false
166
+ }
167
+ }
168
+ ```
169
+
170
+ **Use when:**
171
+ - Your backend accepts tokens in request body
172
+ - Custom authentication implementation
173
+ - Migrating from older systems
174
+
175
+ #### Manual Auth (No Auto-Refresh)
176
+
177
+ ```typescript
178
+ // environment.ts
179
+ export const environment = {
180
+ production: false,
181
+ apiServer: {
182
+ host: 'http://localhost:8000/'
183
+ },
184
+ auth: {
185
+ mode: 'none'
186
+ }
187
+ }
188
+ ```
189
+
190
+ **Use when:**
191
+ - You handle token refresh manually
192
+ - No authentication needed
193
+ - Custom auth logic
194
+
108
195
  ## Advanced Usage
109
196
 
110
197
  ### With Interceptors
@@ -151,7 +238,7 @@ StoneScriptPHP responses follow this structure:
151
238
 
152
239
  ## Requirements
153
240
 
154
- - Angular >= 19.0.0
241
+ - Angular >= 19.0.0 or 20.0.0
155
242
  - RxJS >= 7.8.0
156
243
  - TypeScript >= 5.8.0
157
244
 
@@ -0,0 +1,186 @@
1
+ # ngx-stonescriptphp-client
2
+
3
+ > Official Angular client library for StoneScriptPHP backend framework
4
+
5
+ [![npm version](https://badge.fury.io/js/%40progalaxyelabs%2Fngx-stonescriptphp-client.svg)](https://www.npmjs.com/package/@progalaxyelabs/ngx-stonescriptphp-client)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ **Note:** While published as `@progalaxyelabs/ngx-stonescriptphp-client`, this is the official client for [StoneScriptPHP](https://stonescriptphp.org). Future versions will migrate to the `@stonescriptphp` namespace.
9
+
10
+ ---
11
+
12
+ ## What is this?
13
+
14
+ The Angular HTTP client library for **StoneScriptPHP** - a modern PHP backend framework that auto-generates TypeScript clients from your backend DTOs and contracts.
15
+
16
+ When you build APIs with StoneScriptPHP, you define:
17
+ - Request DTOs (TypeScript interfaces)
18
+ - Response DTOs (TypeScript interfaces)
19
+ - Route contracts (interfaces)
20
+
21
+ This library provides the HTTP client that consumes those contracts, giving you **100% type-safe** API calls with zero manual typing.
22
+
23
+ ## Features
24
+
25
+ - ✅ **Type-safe HTTP calls** - Full TypeScript support from backend DTOs
26
+ - ✅ **Auto-generated clients** - StoneScriptPHP generates TypeScript from PHP
27
+ - ✅ **RxJS observables** - Native Angular integration
28
+ - ✅ **Error handling** - Consistent error responses
29
+ - ✅ **Interceptors ready** - Add auth, logging, retry logic
30
+ - ✅ **Angular 19+** - Modern Angular standalone components
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ npm install @progalaxyelabs/ngx-stonescriptphp-client
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ ### 1. Generate TypeScript Client from Backend
41
+
42
+ In your StoneScriptPHP project:
43
+
44
+ ```bash
45
+ php stone generate typescript-client
46
+ ```
47
+
48
+ This generates TypeScript interfaces from your PHP DTOs.
49
+
50
+ ### 2. Use in Angular
51
+
52
+ ```typescript
53
+ import { Component } from '@angular/core';
54
+ import { HttpClient } from '@angular/common/http';
55
+ import { Observable } from 'rxjs';
56
+
57
+ // Auto-generated from StoneScriptPHP backend
58
+ interface ProductRequest {
59
+ name: string;
60
+ price: number;
61
+ }
62
+
63
+ interface ProductResponse {
64
+ productId: number;
65
+ status: string;
66
+ }
67
+
68
+ @Component({
69
+ selector: 'app-products',
70
+ standalone: true,
71
+ template: `<button (click)="createProduct()">Create Product</button>`
72
+ })
73
+ export class ProductsComponent {
74
+ constructor(private http: HttpClient) {}
75
+
76
+ createProduct(): void {
77
+ const request: ProductRequest = {
78
+ name: 'Widget',
79
+ price: 99.99
80
+ };
81
+
82
+ this.http.post<ProductResponse>('http://localhost:9100/products', request)
83
+ .subscribe(response => {
84
+ console.log('Product created:', response.productId);
85
+ });
86
+ }
87
+ }
88
+ ```
89
+
90
+ ## How it Works
91
+
92
+ StoneScriptPHP follows a **contract-first** approach:
93
+
94
+ ```
95
+ PHP Backend (StoneScriptPHP) Angular Frontend
96
+ ┌─────────────────────────┐ ┌──────────────────────┐
97
+ │ ProductRequest DTO │ ──────> │ ProductRequest.ts │
98
+ │ ProductResponse DTO │ ──────> │ ProductResponse.ts │
99
+ │ IProductRoute contract │ ──────> │ Type-safe HTTP calls │
100
+ └─────────────────────────┘ └──────────────────────┘
101
+ ```
102
+
103
+ 1. Define DTOs in PHP
104
+ 2. Run `php stone generate typescript-client`
105
+ 3. Import generated TypeScript interfaces in Angular
106
+ 4. Make type-safe HTTP calls
107
+
108
+ ## Advanced Usage
109
+
110
+ ### With Interceptors
111
+
112
+ ```typescript
113
+ import { HttpInterceptor, HttpRequest, HttpHandler } from '@angular/common/http';
114
+
115
+ export class AuthInterceptor implements HttpInterceptor {
116
+ intercept(req: HttpRequest<any>, next: HttpHandler) {
117
+ const authReq = req.clone({
118
+ headers: req.headers.set('Authorization', 'Bearer ' + getToken())
119
+ });
120
+ return next.handle(authReq);
121
+ }
122
+ }
123
+ ```
124
+
125
+ ### With Error Handling
126
+
127
+ ```typescript
128
+ this.http.post<ProductResponse>('/products', request)
129
+ .pipe(
130
+ catchError(error => {
131
+ console.error('API Error:', error);
132
+ return throwError(() => error);
133
+ })
134
+ )
135
+ .subscribe(response => {
136
+ // Handle success
137
+ });
138
+ ```
139
+
140
+ ## API Response Format
141
+
142
+ StoneScriptPHP responses follow this structure:
143
+
144
+ ```typescript
145
+ {
146
+ "status": "ok" | "error",
147
+ "message": "Success message",
148
+ "data": { /* Your DTO */ }
149
+ }
150
+ ```
151
+
152
+ ## Requirements
153
+
154
+ - Angular >= 19.0.0
155
+ - RxJS >= 7.8.0
156
+ - TypeScript >= 5.8.0
157
+
158
+ ## Documentation
159
+
160
+ - **Framework Docs:** [stonescriptphp.org](https://stonescriptphp.org)
161
+ - **Getting Started:** [stonescriptphp.org/docs/getting-started](https://stonescriptphp.org/docs/getting-started)
162
+ - **TypeScript Client Guide:** [stonescriptphp.org/docs/typescript-client](https://stonescriptphp.org/docs/typescript-client)
163
+
164
+ ## Example Projects
165
+
166
+ Check out the [StoneScriptPHP examples repository](https://github.com/progalaxyelabs/StoneScriptPHP/tree/main/examples) for full-stack example apps.
167
+
168
+ ## Contributing
169
+
170
+ This is part of the StoneScriptPHP ecosystem. Contributions welcome!
171
+
172
+ - Report issues: [GitHub Issues](https://github.com/progalaxyelabs/ngx-stonescriptphp-client/issues)
173
+ - Framework repo: [StoneScriptPHP](https://github.com/progalaxyelabs/StoneScriptPHP)
174
+
175
+ ## License
176
+
177
+ MIT
178
+
179
+ ## Related Projects
180
+
181
+ - [StoneScriptPHP](https://github.com/progalaxyelabs/StoneScriptPHP) - The PHP backend framework
182
+ - [sunbird-garden](https://github.com/progalaxyelabs/sunbird-garden) - Reference implementation
183
+
184
+ ---
185
+
186
+ **Made with ❤️ by the StoneScriptPHP team**