@maccesar/titools 2.10.1 → 3.2.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.
Files changed (95) hide show
  1. package/AGENTS-VERCEL-RESEARCH.md +23 -12
  2. package/README.md +81 -182
  3. package/agents/ti-pro.md +8 -14
  4. package/lib/cleanup.js +13 -0
  5. package/lib/commands/skills.js +2 -1
  6. package/lib/config.js +9 -11
  7. package/lib/platform.js +1 -1
  8. package/package.json +2 -3
  9. package/skills/purgetss/SKILL.md +44 -57
  10. package/skills/purgetss/references/EXAMPLES.md +8 -1
  11. package/skills/purgetss/references/app-branding.md +96 -16
  12. package/skills/purgetss/references/apply-directive.md +26 -1
  13. package/skills/purgetss/references/arbitrary-values.md +72 -2
  14. package/skills/purgetss/references/class-categories.md +1 -1
  15. package/skills/purgetss/references/cli-commands.md +37 -13
  16. package/skills/purgetss/references/customization-deep-dive.md +18 -11
  17. package/skills/purgetss/references/dynamic-component-creation.md +0 -1
  18. package/skills/purgetss/references/migration-guide.md +162 -1
  19. package/skills/purgetss/references/multi-density-images.md +69 -0
  20. package/skills/purgetss/references/version-history.md +82 -0
  21. package/skills/ti-expert/SKILL.md +1 -1
  22. package/skills/ti-ui/SKILL.md +1 -1
  23. package/skills/alloy-guides/SKILL.md +0 -190
  24. package/skills/alloy-guides/references/CLI_TASKS.md +0 -233
  25. package/skills/alloy-guides/references/CONCEPTS.md +0 -171
  26. package/skills/alloy-guides/references/CONTROLLERS.md +0 -279
  27. package/skills/alloy-guides/references/MODELS.md +0 -1214
  28. package/skills/alloy-guides/references/PURGETSS.md +0 -46
  29. package/skills/alloy-guides/references/VIEWS_DYNAMIC.md +0 -235
  30. package/skills/alloy-guides/references/VIEWS_STYLES.md +0 -375
  31. package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +0 -102
  32. package/skills/alloy-guides/references/VIEWS_XML.md +0 -581
  33. package/skills/alloy-guides/references/WIDGETS.md +0 -160
  34. package/skills/alloy-howtos/SKILL.md +0 -181
  35. package/skills/alloy-howtos/references/best_practices.md +0 -121
  36. package/skills/alloy-howtos/references/cli_reference.md +0 -230
  37. package/skills/alloy-howtos/references/config_files.md +0 -158
  38. package/skills/alloy-howtos/references/custom_tags.md +0 -148
  39. package/skills/alloy-howtos/references/debugging_troubleshooting.md +0 -78
  40. package/skills/alloy-howtos/references/samples.md +0 -156
  41. package/skills/ti-api/SKILL.md +0 -109
  42. package/skills/ti-api/references/api-android.md +0 -675
  43. package/skills/ti-api/references/api-app-platform.md +0 -636
  44. package/skills/ti-api/references/api-core.md +0 -764
  45. package/skills/ti-api/references/api-data-network.md +0 -641
  46. package/skills/ti-api/references/api-media.md +0 -655
  47. package/skills/ti-api/references/api-modules-ble-bluetooth.md +0 -657
  48. package/skills/ti-api/references/api-modules-coremotion-urlsession.md +0 -411
  49. package/skills/ti-api/references/api-modules-map.md +0 -632
  50. package/skills/ti-api/references/api-modules-nfc.md +0 -725
  51. package/skills/ti-api/references/api-modules-social-misc.md +0 -526
  52. package/skills/ti-api/references/api-services.md +0 -700
  53. package/skills/ti-api/references/api-ui-android.md +0 -499
  54. package/skills/ti-api/references/api-ui-extras.md +0 -702
  55. package/skills/ti-api/references/api-ui-ios-animator.md +0 -378
  56. package/skills/ti-api/references/api-ui-ios.md +0 -756
  57. package/skills/ti-api/references/api-ui-lists.md +0 -581
  58. package/skills/ti-api/references/api-ui-text-input.md +0 -607
  59. package/skills/ti-api/references/api-ui-views.md +0 -572
  60. package/skills/ti-api/references/api-ui-windows-navigation.md +0 -676
  61. package/skills/ti-api/references/api-xml-global.md +0 -743
  62. package/skills/ti-guides/SKILL.md +0 -75
  63. package/skills/ti-guides/references/advanced-data-and-images.md +0 -155
  64. package/skills/ti-guides/references/android-manifest.md +0 -97
  65. package/skills/ti-guides/references/app-distribution.md +0 -373
  66. package/skills/ti-guides/references/application-frameworks.md +0 -366
  67. package/skills/ti-guides/references/cli-reference.md +0 -700
  68. package/skills/ti-guides/references/coding-best-practices.md +0 -150
  69. package/skills/ti-guides/references/commonjs-advanced.md +0 -279
  70. package/skills/ti-guides/references/hello-world.md +0 -99
  71. package/skills/ti-guides/references/hyperloop-native-access.md +0 -458
  72. package/skills/ti-guides/references/javascript-primer.md +0 -402
  73. package/skills/ti-guides/references/reserved-words.md +0 -36
  74. package/skills/ti-guides/references/resources.md +0 -172
  75. package/skills/ti-guides/references/style-and-conventions.md +0 -104
  76. package/skills/ti-guides/references/tiapp-config.md +0 -655
  77. package/skills/ti-howtos/SKILL.md +0 -143
  78. package/skills/ti-howtos/references/android-platform-deep-dives.md +0 -609
  79. package/skills/ti-howtos/references/automation-fastlane-appium.md +0 -96
  80. package/skills/ti-howtos/references/buffer-codec-streams.md +0 -162
  81. package/skills/ti-howtos/references/cross-platform-development.md +0 -358
  82. package/skills/ti-howtos/references/debugging-profiling.md +0 -473
  83. package/skills/ti-howtos/references/extending-titanium.md +0 -684
  84. package/skills/ti-howtos/references/google-maps-v2.md +0 -172
  85. package/skills/ti-howtos/references/ios-map-kit.md +0 -149
  86. package/skills/ti-howtos/references/ios-platform-deep-dives.md +0 -595
  87. package/skills/ti-howtos/references/local-data-sources.md +0 -310
  88. package/skills/ti-howtos/references/location-and-maps.md +0 -267
  89. package/skills/ti-howtos/references/media-apis.md +0 -268
  90. package/skills/ti-howtos/references/notification-services.md +0 -539
  91. package/skills/ti-howtos/references/remote-data-sources.md +0 -339
  92. package/skills/ti-howtos/references/tutorials.md +0 -552
  93. package/skills/ti-howtos/references/using-modules.md +0 -182
  94. package/skills/ti-howtos/references/web-content-integration.md +0 -288
  95. package/skills/ti-howtos/references/webpack-build-pipeline.md +0 -125
@@ -1,339 +0,0 @@
1
- # Remote data sources
2
-
3
- ## 1. HTTPClient and request lifecycle
4
-
5
- ### Basic pattern
6
- `Ti.Network.HTTPClient` mirrors the XHR (XMLHttpRequest) API. Always handle both success and error paths.
7
-
8
- ```javascript
9
- const xhr = Ti.Network.createHTTPClient({
10
- onload: (e) => {
11
- // this.responseText - raw text (JSON/text)
12
- // this.responseXML - XML document (including SOAP)
13
- // this.responseData - binary data (Blob)
14
- Ti.API.debug(xhr.responseText);
15
- },
16
- onerror: (e) => {
17
- Ti.API.debug(e.error);
18
- },
19
- timeout: 5000
20
- });
21
- xhr.open('GET', 'https://api.example.com/data');
22
- xhr.send();
23
- ```
24
-
25
- ### HTTP methods
26
- - GET: `xhr.open('GET', url)` then `xhr.send()`
27
- - POST: `xhr.open('POST', url)` then `xhr.send({key: 'value'})`
28
- - PUT/DELETE/PATCH: all supported (PATCH since 4.1.0 on Android)
29
-
30
- ### Setting headers
31
- Headers must be set after `open()` but before `send()`.
32
-
33
- ```javascript
34
- const client = Ti.Network.createHTTPClient();
35
- client.open('POST', 'http://server.com/upload');
36
- client.setRequestHeader('Content-Type', 'text/csv');
37
- client.setRequestHeader('Authorization', `Bearer ${token}`);
38
- client.send('data');
39
- ```
40
-
41
- ### XHR lifecycle states
42
- Monitor with `onreadystatechange`:
43
- - `UNSENT` - object constructed
44
- - `OPENED` - `open()` called successfully
45
- - `HEADERS_RECEIVED` - all redirects followed, headers received
46
- - `LOADING` - response body being received
47
- - `DONE` - transfer complete or error occurred
48
-
49
- ```javascript
50
- xhr.onreadystatechange = (e) => {
51
- switch (xhr.readyState) {
52
- case Ti.Network.HTTPClient.HEADERS_RECEIVED:
53
- Ti.API.info(`Headers: ${xhr.getResponseHeader('Content-Type')}`);
54
- break;
55
- case Ti.Network.HTTPClient.DONE:
56
- Ti.API.info('Complete');
57
- break;
58
- }
59
- };
60
- ```
61
-
62
- ### Progress monitoring
63
- - `onsendstream`: upload progress (0.0-1.0)
64
- - `ondatastream`: download progress (0.0-1.0)
65
-
66
- ```javascript
67
- xhr.onsendstream = (e) => {
68
- progressBar.value = e.progress;
69
- };
70
- xhr.ondatastream = (e) => {
71
- progressBar.value = e.progress;
72
- };
73
- ```
74
-
75
- ## 2. Working with JSON data
76
-
77
- ### Receiving JSON
78
- ```javascript
79
- xhr.onload = () => {
80
- const data = JSON.parse(xhr.responseText);
81
- Ti.API.info(data.users[0].name);
82
- };
83
- ```
84
-
85
- ### Sending JSON
86
- `send()` stringifies objects for you.
87
-
88
- ```javascript
89
- const postData = { title: 'My Post', body: 'Content' };
90
- xhr.open('POST', 'http://blog.com/api/posts');
91
- xhr.send(postData); // Auto-stringified
92
- ```
93
-
94
- For GET query strings, stringify and encode yourself.
95
-
96
- ```javascript
97
- const data = { search: 'titanium' };
98
- const queryString = encodeURIComponent(JSON.stringify(data));
99
- xhr.open('GET', `http://api.com/search?q=${queryString}`);
100
- xhr.send();
101
- ```
102
-
103
- ### Important limitation
104
- JSON cannot represent methods. Stringifying Titanium objects returns an empty representation.
105
-
106
- ## 3. Working with XML data
107
-
108
- ### Parsing XML
109
- Titanium provides XML DOM Level 2. If the response is XML and the server sends the correct Content-Type, Titanium auto-parses it.
110
-
111
- ```javascript
112
- xhr.onload = () => {
113
- const doc = xhr.responseXML.documentElement;
114
- const items = doc.getElementsByTagName('item');
115
- for (let i = 0; i < items.length; i++) {
116
- const title = items.item(i)
117
- .getElementsByTagName('title').item(0)
118
- .textContent;
119
- Ti.API.info(title);
120
- }
121
- };
122
- ```
123
-
124
- ### Common DOM methods
125
- - `getElementsByTagName(name)` - returns array of nodes
126
- - `item(index)` - selects a specific node from the array
127
- - `getAttribute(name)` - gets an attribute value
128
- - `textContent` / `nodeValue` - gets a leaf node value
129
-
130
- ### Important: know your DTD
131
- You must understand the XML structure (node hierarchy) to parse correctly. Use tools like apigee.com to inspect API responses.
132
-
133
- ## 4. File uploads and downloads
134
-
135
- ### File upload
136
- Pass a Blob to `send()`.
137
-
138
- ```javascript
139
- Ti.Media.openPhotoGallery({
140
- success: (event) => {
141
- const xhr = Ti.Network.createHTTPClient({
142
- onload: () => {
143
- Ti.API.info(`Upload complete: ${xhr.status}`);
144
- }
145
- });
146
- xhr.open('POST', 'https://server.com/upload');
147
- xhr.send({
148
- file: event.media, // Blob from gallery
149
- username: 'user'
150
- });
151
- }
152
- });
153
- ```
154
-
155
- For file uploads with actual file contents:
156
-
157
- ```javascript
158
- const file = Ti.Filesystem.getFile(event.media.nativePath);
159
- if (file.exists()) {
160
- xhr.send({ file: file.read() });
161
- }
162
- ```
163
-
164
- Note: when uploading from the photo gallery, `event.media` is a Blob. For filesystem uploads, use `Ti.Filesystem.getFile(path).read()` to get a Blob.
165
-
166
- ### File download (cross-platform)
167
-
168
- Option 1: write manually to the filesystem.
169
-
170
- ```javascript
171
- const xhr = Ti.Network.createHTTPClient({
172
- onload: () => {
173
- const file = Ti.Filesystem.getFile(
174
- Ti.Filesystem.applicationDataDirectory,
175
- 'downloaded.png'
176
- );
177
- file.write(xhr.responseData);
178
- Ti.App.fireEvent('download_complete', { path: file.nativePath });
179
- },
180
- timeout: 10000
181
- });
182
- xhr.open('GET', 'http://example.com/image.png');
183
- xhr.send();
184
- ```
185
-
186
- Option 2 (iOS only): set `xhr.file` to save directly without buffering.
187
-
188
- ```javascript
189
- xhr.file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'download.zip');
190
- ```
191
-
192
- ```javascript
193
- const xhr = Ti.Network.createHTTPClient({
194
- onload: () => {
195
- Ti.API.info('Saved to applicationDataDirectory/test.pdf');
196
- }
197
- });
198
- xhr.open('GET', 'http://example.com/file.pdf');
199
- xhr.file = Ti.Filesystem.getFile(
200
- Ti.Filesystem.applicationDataDirectory,
201
- 'test.pdf'
202
- );
203
- xhr.send();
204
- ```
205
-
206
- ### File storage locations
207
- - `applicationDataDirectory` - primary read/write location for app files
208
- - `resourcesDirectory` - read-only app resources (writeable in simulator only)
209
- - `tempDirectory` - temporary files, OS may delete when app closes
210
- - `externalCacheDirectory` - Android SD card cache (check `isExternalStoragePresent()`)
211
- - `applicationCacheDirectory` - cache data, persists but OS may clean it up
212
-
213
- ## 5. Sockets
214
-
215
- Titanium supports TCP sockets via `Ti.Network.Socket`.
216
-
217
- ### Creating a TCP socket
218
-
219
- ```javascript
220
- const socket = Ti.Network.Socket.createTCP({
221
- host: 'example.com',
222
- port: 80,
223
- connected: function (e) {
224
- Ti.API.info('Socket connected');
225
- // Write data
226
- this.write(Ti.createBuffer({
227
- value: 'GET / HTTP/1.1\r\nHost: example.com\r\n\r\n'
228
- }));
229
- },
230
- error: (e) => {
231
- Ti.API.error(`Socket error: ${e.error}`);
232
- }
233
- });
234
-
235
- socket.connect();
236
- ```
237
-
238
- ### Socket listening (Android/iOS)
239
- To create a socket server that accepts connections:
240
-
241
- ```javascript
242
- const listenSocket = Ti.Network.Socket.createTCP({
243
- host: '127.0.0.1', // localhost
244
- port: 40404,
245
- accepted: (e) => {
246
- Ti.API.info(`Incoming connection accepted: ${e.inbound}`);
247
- e.inbound.close();
248
- }
249
- });
250
- listenSocket.listen();
251
- listenSocket.accept(); // Asynchronous, waits for next connection
252
- ```
253
-
254
- Platform note: on iOS, `Ti.Platform.address` returns the WiFi interface address. On Android, only the loopback address (`127.0.0.1`) is available for listening sockets.
255
-
256
- ## 6. Dealing with SOAP web services
257
-
258
- JSON is recommended, but you can consume legacy SOAP services by sending the XML envelope manually.
259
-
260
- ### Manual approach (SOAP envelope)
261
- ```javascript
262
- const client = Ti.Network.createHTTPClient();
263
- client.onload = () => {
264
- const doc = client.responseXML.documentElement;
265
- // Parse the response XML manually
266
- };
267
-
268
- const soapRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" +
269
- "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n" +
270
- "<SOAP-ENV:Body> \n" +
271
- " <GetUserDetailsReq> \n" +
272
- " <SessionToken>XXXX</SessionToken> \n" +
273
- " </GetUserDetailsReq> \n" +
274
- "</SOAP-ENV:Body> \n" +
275
- "</SOAP-ENV:Envelope>";
276
-
277
- client.open('POST', 'https://server.com/service.asmx');
278
- client.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
279
- client.send({ xml: soapRequest });
280
- ```
281
-
282
- ## 7. SSL certificate and SecurityManager
283
-
284
- For SSL pinning, use the `securityManager` property.
285
-
286
- ### SSL pinning (TiSDK 3.3.0+)
287
- Pinning ensures the app only communicates with a server that presents a specific certificate.
288
-
289
- ```javascript
290
- const xhr = Ti.Network.createHTTPClient({
291
- validatesSecureCertificate: true,
292
- // securityManager allows custom validation logic
293
- securityManager: mySecurityModule
294
- });
295
- ```
296
-
297
- ### SSL certificate store (Android)
298
- ```javascript
299
- const certificateStore = require('ti.certificatestore');
300
- const httpClient = Ti.Network.createHTTPClient({
301
- securityManager: certificateStore.createX509CertificatePinningSecurityManager([
302
- {
303
- url: 'https://api.example.com',
304
- serverCertificate: 'api_cert.der'
305
- }
306
- ])
307
- });
308
- ```
309
-
310
- ### Android: addTrustManager
311
- Use this for development environments or private networks with custom certs.
312
-
313
- ```javascript
314
- const certificateStore = require('ti.certificatestore');
315
- const xhr = Ti.Network.createHTTPClient();
316
-
317
- certificateStore.addCertificate('server.p12', 'password');
318
- xhr.addTrustManager(certificateStore.getTrustManager());
319
-
320
- xhr.open('GET', url);
321
- xhr.send();
322
- ```
323
-
324
- ## 8. CORS considerations for Mobile Web
325
-
326
- For Mobile Web targets accessing cross-domain resources:
327
- - Enable CORS headers on the server
328
- - Or configure a proxy service
329
- - Use custom `Ti.Network.httpURLFormatter`
330
-
331
- ## Best practices
332
-
333
- 1. Set timeouts to prevent hanging requests.
334
- 2. Handle both `onload` and `onerror`.
335
- 3. Use progress callbacks for large file operations.
336
- 4. Save large downloads to disk using `file` (iOS) or `write()` to avoid memory exhaustion.
337
- 5. For complex JSON, validate schema before parsing.
338
- 6. For XML, test with real responses to verify node hierarchy.
339
- 7. Use `onsendstream` and `ondatastream` for user feedback during transfers.