@progalaxyelabs/ngx-stonescriptphp-client 0.0.8 → 0.0.10

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 (2) hide show
  1. package/README.md +175 -13
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,24 +1,186 @@
1
- # NgxStoneScriptPhpClient
1
+ # ngx-stonescriptphp-client
2
2
 
3
- This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 16.2.0.
3
+ > Official Angular client library for StoneScriptPHP backend framework
4
4
 
5
- ## Code scaffolding
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)
6
7
 
7
- Run `ng generate component component-name --project ngx-stonescriptphp-client` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project ngx-stonescriptphp-client`.
8
- > Note: Don't forget to add `--project ngx-stonescriptphp-client` or else it will be added to the default project in your `angular.json` file.
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
- ## Build
10
+ ---
11
11
 
12
- Run `ng build ngx-stonescriptphp-client` to build the project. The build artifacts will be stored in the `dist/` directory.
12
+ ## What is this?
13
13
 
14
- ## Publishing
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
15
 
16
- After building your library with `ng build ngx-stonescriptphp-client`, go to the dist folder `cd dist/ngx-stonescriptphp-client` and run `npm publish`.
16
+ When you build APIs with StoneScriptPHP, you define:
17
+ - Request DTOs (TypeScript interfaces)
18
+ - Response DTOs (TypeScript interfaces)
19
+ - Route contracts (interfaces)
17
20
 
18
- ## Running unit tests
21
+ This library provides the HTTP client that consumes those contracts, giving you **100% type-safe** API calls with zero manual typing.
19
22
 
20
- Run `ng test ngx-stonescriptphp-client` to execute the unit tests via [Karma](https://karma-runner.github.io).
23
+ ## Features
21
24
 
22
- ## Further help
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
23
31
 
24
- To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
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**
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@progalaxyelabs/ngx-stonescriptphp-client",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "peerDependencies": {
5
- "@angular/common": "^16.2.0",
6
- "@angular/core": "^16.2.0"
5
+ "@angular/common": "^16.2.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0",
6
+ "@angular/core": "^16.2.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0"
7
7
  },
8
8
  "dependencies": {
9
9
  "tslib": "^2.3.0"