@maccesar/titools 3.3.0 → 4.0.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 (101) hide show
  1. package/README.md +27 -61
  2. package/lib/cleanup.js +29 -0
  3. package/lib/commands/agents.js +8 -7
  4. package/lib/commands/skills.js +118 -23
  5. package/lib/config.js +13 -15
  6. package/lib/installer.js +5 -3
  7. package/lib/utils.js +36 -0
  8. package/package.json +1 -1
  9. package/skills/alloy-guides/SKILL.md +188 -0
  10. package/skills/alloy-guides/references/CLI_TASKS.md +233 -0
  11. package/skills/alloy-guides/references/CONCEPTS.md +171 -0
  12. package/skills/alloy-guides/references/CONTROLLERS.md +279 -0
  13. package/skills/alloy-guides/references/MODELS.md +742 -0
  14. package/skills/alloy-guides/references/MODELS_ADVANCED.md +482 -0
  15. package/skills/alloy-guides/references/PURGETSS.md +57 -0
  16. package/skills/alloy-guides/references/VIEWS_DYNAMIC.md +235 -0
  17. package/skills/alloy-guides/references/VIEWS_STYLES.md +375 -0
  18. package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +102 -0
  19. package/skills/alloy-guides/references/VIEWS_XML.md +581 -0
  20. package/skills/alloy-guides/references/WIDGETS.md +160 -0
  21. package/skills/alloy-howtos/SKILL.md +179 -0
  22. package/skills/alloy-howtos/references/best_practices.md +121 -0
  23. package/skills/alloy-howtos/references/cli_reference.md +230 -0
  24. package/skills/alloy-howtos/references/config_files.md +158 -0
  25. package/skills/alloy-howtos/references/custom_tags.md +148 -0
  26. package/skills/alloy-howtos/references/debugging_troubleshooting.md +78 -0
  27. package/skills/alloy-howtos/references/samples.md +156 -0
  28. package/skills/purgetss/SKILL.md +6 -3
  29. package/skills/purgetss/references/EXAMPLES.md +8 -6
  30. package/skills/purgetss/references/app-branding.md +5 -0
  31. package/skills/purgetss/references/apply-directive.md +1 -1
  32. package/skills/purgetss/references/class-categories.md +1 -1
  33. package/skills/purgetss/references/class-index-properties.md +618 -0
  34. package/skills/purgetss/references/class-index.md +4 -610
  35. package/skills/purgetss/references/cli-commands.md +15 -0
  36. package/skills/purgetss/references/custom-fonts.md +39 -36
  37. package/skills/purgetss/references/custom-rules.md +1 -1
  38. package/skills/purgetss/references/customization-deep-dive.md +64 -1
  39. package/skills/purgetss/references/icon-fonts.md +2 -0
  40. package/skills/purgetss/references/migration-guide.md +53 -1
  41. package/skills/purgetss/references/multi-density-images.md +53 -2
  42. package/skills/purgetss/references/svg-pipeline.md +249 -0
  43. package/skills/purgetss/references/tikit-components.md +2 -2
  44. package/skills/purgetss/references/titanium-resets.md +2 -2
  45. package/skills/purgetss/references/ui-ux-design.md +7 -5
  46. package/skills/purgetss/references/version-history.md +12 -0
  47. package/skills/ti-api/SKILL.md +128 -0
  48. package/skills/ti-api/references/api-android.md +675 -0
  49. package/skills/ti-api/references/api-app-platform.md +636 -0
  50. package/skills/ti-api/references/api-core.md +764 -0
  51. package/skills/ti-api/references/api-data-network.md +641 -0
  52. package/skills/ti-api/references/api-media.md +655 -0
  53. package/skills/ti-api/references/api-modules-ble-bluetooth.md +657 -0
  54. package/skills/ti-api/references/api-modules-coremotion-urlsession.md +411 -0
  55. package/skills/ti-api/references/api-modules-map.md +632 -0
  56. package/skills/ti-api/references/api-modules-nfc.md +725 -0
  57. package/skills/ti-api/references/api-modules-social-misc.md +526 -0
  58. package/skills/ti-api/references/api-services.md +700 -0
  59. package/skills/ti-api/references/api-ui-android.md +499 -0
  60. package/skills/ti-api/references/api-ui-extras.md +702 -0
  61. package/skills/ti-api/references/api-ui-ios-animator.md +378 -0
  62. package/skills/ti-api/references/api-ui-ios.md +756 -0
  63. package/skills/ti-api/references/api-ui-lists.md +581 -0
  64. package/skills/ti-api/references/api-ui-text-input.md +607 -0
  65. package/skills/ti-api/references/api-ui-views.md +572 -0
  66. package/skills/ti-api/references/api-ui-windows-navigation.md +676 -0
  67. package/skills/ti-api/references/api-xml-global.md +743 -0
  68. package/skills/ti-guides/SKILL.md +82 -0
  69. package/skills/ti-guides/references/advanced-data-and-images.md +155 -0
  70. package/skills/ti-guides/references/android-manifest.md +97 -0
  71. package/skills/ti-guides/references/app-distribution.md +373 -0
  72. package/skills/ti-guides/references/application-frameworks.md +366 -0
  73. package/skills/ti-guides/references/cli-reference.md +700 -0
  74. package/skills/ti-guides/references/coding-best-practices.md +150 -0
  75. package/skills/ti-guides/references/commonjs-advanced.md +279 -0
  76. package/skills/ti-guides/references/hello-world.md +99 -0
  77. package/skills/ti-guides/references/hyperloop-native-access.md +458 -0
  78. package/skills/ti-guides/references/javascript-primer.md +402 -0
  79. package/skills/ti-guides/references/reserved-words.md +36 -0
  80. package/skills/ti-guides/references/resources.md +172 -0
  81. package/skills/ti-guides/references/style-and-conventions.md +104 -0
  82. package/skills/ti-guides/references/tiapp-config.md +655 -0
  83. package/skills/ti-howtos/SKILL.md +131 -0
  84. package/skills/ti-howtos/references/android-platform-deep-dives.md +609 -0
  85. package/skills/ti-howtos/references/automation-fastlane-appium.md +96 -0
  86. package/skills/ti-howtos/references/buffer-codec-streams.md +162 -0
  87. package/skills/ti-howtos/references/cross-platform-development.md +358 -0
  88. package/skills/ti-howtos/references/debugging-profiling.md +473 -0
  89. package/skills/ti-howtos/references/extending-titanium.md +684 -0
  90. package/skills/ti-howtos/references/google-maps-v2.md +172 -0
  91. package/skills/ti-howtos/references/ios-map-kit.md +149 -0
  92. package/skills/ti-howtos/references/ios-platform-deep-dives.md +595 -0
  93. package/skills/ti-howtos/references/local-data-sources.md +310 -0
  94. package/skills/ti-howtos/references/location-and-maps.md +267 -0
  95. package/skills/ti-howtos/references/media-apis.md +268 -0
  96. package/skills/ti-howtos/references/notification-services.md +539 -0
  97. package/skills/ti-howtos/references/remote-data-sources.md +339 -0
  98. package/skills/ti-howtos/references/tutorials.md +552 -0
  99. package/skills/ti-howtos/references/using-modules.md +182 -0
  100. package/skills/ti-howtos/references/web-content-integration.md +288 -0
  101. package/skills/ti-howtos/references/webpack-build-pipeline.md +125 -0
@@ -0,0 +1,339 @@
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.