oblien 1.3.0 → 2.0.1

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 (187) hide show
  1. package/README.md +482 -422
  2. package/dist/client.d.ts +31 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +33 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/error.d.ts +29 -0
  7. package/dist/error.d.ts.map +1 -0
  8. package/dist/error.js +52 -0
  9. package/dist/error.js.map +1 -0
  10. package/dist/http.d.ts +20 -0
  11. package/dist/http.d.ts.map +1 -0
  12. package/dist/http.js +108 -0
  13. package/dist/http.js.map +1 -0
  14. package/dist/index.d.ts +8 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +10 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/resources/api-access.d.ts +21 -0
  19. package/dist/resources/api-access.d.ts.map +1 -0
  20. package/dist/resources/api-access.js +32 -0
  21. package/dist/resources/api-access.js.map +1 -0
  22. package/dist/resources/base.d.ts +17 -0
  23. package/dist/resources/base.d.ts.map +1 -0
  24. package/dist/resources/base.js +21 -0
  25. package/dist/resources/base.js.map +1 -0
  26. package/dist/resources/images.d.ts +11 -0
  27. package/dist/resources/images.d.ts.map +1 -0
  28. package/dist/resources/images.js +16 -0
  29. package/dist/resources/images.js.map +1 -0
  30. package/dist/resources/lifecycle.d.ts +23 -0
  31. package/dist/resources/lifecycle.d.ts.map +1 -0
  32. package/dist/resources/lifecycle.js +32 -0
  33. package/dist/resources/lifecycle.js.map +1 -0
  34. package/dist/resources/logs.d.ts +25 -0
  35. package/dist/resources/logs.d.ts.map +1 -0
  36. package/dist/resources/logs.js +51 -0
  37. package/dist/resources/logs.js.map +1 -0
  38. package/dist/resources/metadata.d.ts +15 -0
  39. package/dist/resources/metadata.d.ts.map +1 -0
  40. package/dist/resources/metadata.js +20 -0
  41. package/dist/resources/metadata.js.map +1 -0
  42. package/dist/resources/metrics.d.ts +17 -0
  43. package/dist/resources/metrics.d.ts.map +1 -0
  44. package/dist/resources/metrics.js +27 -0
  45. package/dist/resources/metrics.js.map +1 -0
  46. package/dist/resources/network.d.ts +17 -0
  47. package/dist/resources/network.d.ts.map +1 -0
  48. package/dist/resources/network.js +20 -0
  49. package/dist/resources/network.js.map +1 -0
  50. package/dist/resources/public-access.d.ts +15 -0
  51. package/dist/resources/public-access.d.ts.map +1 -0
  52. package/dist/resources/public-access.js +21 -0
  53. package/dist/resources/public-access.js.map +1 -0
  54. package/dist/resources/resources.d.ts +15 -0
  55. package/dist/resources/resources.d.ts.map +1 -0
  56. package/dist/resources/resources.js +20 -0
  57. package/dist/resources/resources.js.map +1 -0
  58. package/dist/resources/snapshots.d.ts +27 -0
  59. package/dist/resources/snapshots.d.ts.map +1 -0
  60. package/dist/resources/snapshots.js +45 -0
  61. package/dist/resources/snapshots.js.map +1 -0
  62. package/dist/resources/ssh.d.ts +19 -0
  63. package/dist/resources/ssh.d.ts.map +1 -0
  64. package/dist/resources/ssh.js +28 -0
  65. package/dist/resources/ssh.js.map +1 -0
  66. package/dist/resources/usage.d.ts +25 -0
  67. package/dist/resources/usage.d.ts.map +1 -0
  68. package/dist/resources/usage.js +44 -0
  69. package/dist/resources/usage.js.map +1 -0
  70. package/dist/resources/workloads.d.ts +39 -0
  71. package/dist/resources/workloads.d.ts.map +1 -0
  72. package/dist/resources/workloads.js +83 -0
  73. package/dist/resources/workloads.js.map +1 -0
  74. package/dist/runtime/exec.d.ts +71 -0
  75. package/dist/runtime/exec.d.ts.map +1 -0
  76. package/dist/runtime/exec.js +163 -0
  77. package/dist/runtime/exec.js.map +1 -0
  78. package/dist/runtime/files.d.ts +39 -0
  79. package/dist/runtime/files.d.ts.map +1 -0
  80. package/dist/runtime/files.js +143 -0
  81. package/dist/runtime/files.js.map +1 -0
  82. package/dist/runtime/search.d.ts +23 -0
  83. package/dist/runtime/search.d.ts.map +1 -0
  84. package/dist/runtime/search.js +65 -0
  85. package/dist/runtime/search.js.map +1 -0
  86. package/dist/runtime/terminal.d.ts +29 -0
  87. package/dist/runtime/terminal.d.ts.map +1 -0
  88. package/dist/runtime/terminal.js +58 -0
  89. package/dist/runtime/terminal.js.map +1 -0
  90. package/dist/runtime/watcher.d.ts +27 -0
  91. package/dist/runtime/watcher.d.ts.map +1 -0
  92. package/dist/runtime/watcher.js +53 -0
  93. package/dist/runtime/watcher.js.map +1 -0
  94. package/dist/runtime/ws.d.ts +92 -0
  95. package/dist/runtime/ws.d.ts.map +1 -0
  96. package/dist/runtime/ws.js +228 -0
  97. package/dist/runtime/ws.js.map +1 -0
  98. package/dist/runtime-http.d.ts +35 -0
  99. package/dist/runtime-http.d.ts.map +1 -0
  100. package/dist/runtime-http.js +99 -0
  101. package/dist/runtime-http.js.map +1 -0
  102. package/dist/runtime.d.ts +77 -0
  103. package/dist/runtime.d.ts.map +1 -0
  104. package/dist/runtime.js +97 -0
  105. package/dist/runtime.js.map +1 -0
  106. package/dist/types/client.d.ts +7 -0
  107. package/dist/types/client.d.ts.map +1 -0
  108. package/dist/types/client.js +3 -0
  109. package/dist/types/client.js.map +1 -0
  110. package/dist/types/common.d.ts +13 -0
  111. package/dist/types/common.d.ts.map +1 -0
  112. package/dist/types/common.js +3 -0
  113. package/dist/types/common.js.map +1 -0
  114. package/dist/types/index.d.ts +8 -0
  115. package/dist/types/index.d.ts.map +1 -0
  116. package/dist/types/index.js +2 -0
  117. package/dist/types/index.js.map +1 -0
  118. package/dist/types/network.d.ts +15 -0
  119. package/dist/types/network.d.ts.map +1 -0
  120. package/dist/types/network.js +3 -0
  121. package/dist/types/network.js.map +1 -0
  122. package/dist/types/resources.d.ts +10 -0
  123. package/dist/types/resources.d.ts.map +1 -0
  124. package/dist/types/resources.js +3 -0
  125. package/dist/types/resources.js.map +1 -0
  126. package/dist/types/runtime.d.ts +302 -0
  127. package/dist/types/runtime.d.ts.map +1 -0
  128. package/dist/types/runtime.js +3 -0
  129. package/dist/types/runtime.js.map +1 -0
  130. package/dist/types/workspace-resources.d.ts +186 -0
  131. package/dist/types/workspace-resources.d.ts.map +1 -0
  132. package/dist/types/workspace-resources.js +3 -0
  133. package/dist/types/workspace-resources.js.map +1 -0
  134. package/dist/types/workspace.d.ts +41 -0
  135. package/dist/types/workspace.d.ts.map +1 -0
  136. package/dist/types/workspace.js +3 -0
  137. package/dist/types/workspace.js.map +1 -0
  138. package/dist/workspace.d.ts +135 -0
  139. package/dist/workspace.d.ts.map +1 -0
  140. package/dist/workspace.js +194 -0
  141. package/dist/workspace.js.map +1 -0
  142. package/package.json +30 -69
  143. package/LICENSE +0 -21
  144. package/agents.js +0 -14
  145. package/browser.js +0 -6
  146. package/cdn.js +0 -6
  147. package/chat.js +0 -21
  148. package/credits.js +0 -11
  149. package/icons.js +0 -11
  150. package/index.d.ts +0 -986
  151. package/index.js +0 -63
  152. package/namespaces.js +0 -12
  153. package/sandbox.js +0 -12
  154. package/search.js +0 -11
  155. package/src/agents/agent.js +0 -229
  156. package/src/agents/index.js +0 -227
  157. package/src/agents/settings.js +0 -100
  158. package/src/agents/tools.js +0 -155
  159. package/src/browser/index.js +0 -474
  160. package/src/cdn/index.js +0 -769
  161. package/src/chat/index.js +0 -724
  162. package/src/chat/session.js +0 -93
  163. package/src/client.js +0 -175
  164. package/src/credits/index.js +0 -492
  165. package/src/icons/index.js +0 -185
  166. package/src/namespaces/index.js +0 -236
  167. package/src/namespaces/namespace.js +0 -274
  168. package/src/sandbox/core/api/base.js +0 -89
  169. package/src/sandbox/core/api/database.js +0 -340
  170. package/src/sandbox/core/api/files.js +0 -141
  171. package/src/sandbox/core/api/git.js +0 -174
  172. package/src/sandbox/core/api/search.js +0 -29
  173. package/src/sandbox/core/api/snapshots.js +0 -132
  174. package/src/sandbox/core/api/terminal.js +0 -20
  175. package/src/sandbox/core/auth.js +0 -256
  176. package/src/sandbox/core/client.js +0 -197
  177. package/src/sandbox/core/index.js +0 -22
  178. package/src/sandbox/core/managers/terminal.js +0 -453
  179. package/src/sandbox/core/managers/watcher.js +0 -197
  180. package/src/sandbox/core/types.js +0 -92
  181. package/src/sandbox/core/utils/http.js +0 -89
  182. package/src/sandbox/core/websocket/connection.js +0 -479
  183. package/src/sandbox/index.d.ts +0 -542
  184. package/src/sandbox/index.js +0 -234
  185. package/src/sandbox/sandbox.js +0 -313
  186. package/src/search/index.js +0 -206
  187. package/src/utils/guest-manager.js +0 -454
@@ -1,492 +0,0 @@
1
- /**
2
- * Credits Module
3
- * Manages credits, quotas, usage tracking, and transactions
4
- */
5
-
6
- import { OblienClient } from '../client.js';
7
-
8
- export class OblienCredits {
9
- /**
10
- * @param {import('../client.js').OblienClient|Object} clientOrConfig - Oblien client instance or { clientId, clientSecret }
11
- */
12
- constructor(clientOrConfig) {
13
- if (!clientOrConfig) {
14
- throw new Error('Either provide OblienClient instance or { clientId, clientSecret }');
15
- }
16
-
17
- // If it's already a client instance
18
- if (clientOrConfig.clientId && clientOrConfig.clientSecret && typeof clientOrConfig.get === 'function') {
19
- this.client = clientOrConfig;
20
- }
21
- // If credentials provided, create client
22
- else if (clientOrConfig.clientId && clientOrConfig.clientSecret) {
23
- this.client = new OblienClient(clientOrConfig);
24
- }
25
- else {
26
- throw new Error('Either provide OblienClient instance or { clientId, clientSecret }');
27
- }
28
- }
29
-
30
- // =============================================================================
31
- // Balance Management
32
- // =============================================================================
33
-
34
- /**
35
- * Get client's total credit balance
36
- * @returns {Promise<number>} Current credit balance
37
- */
38
- async getBalance() {
39
- const response = await this.client.get('credits/balance');
40
- return response.balance;
41
- }
42
-
43
- /**
44
- * Add credits to client (internal use - requires admin permissions)
45
- * @param {number} amount - Amount of credits to add
46
- * @param {string} [reason] - Reason for adding credits
47
- * @param {Object} [metadata] - Additional metadata
48
- * @returns {Promise<Object>} Result with new balance
49
- */
50
- async addCredits(amount, reason = 'manual', metadata = {}) {
51
- const response = await this.client.post('credits/add', {
52
- amount,
53
- reason,
54
- metadata
55
- });
56
- return response;
57
- }
58
-
59
- // =============================================================================
60
- // Quota Management
61
- // =============================================================================
62
-
63
- /**
64
- * Get all namespace quotas with pagination and filtering
65
- * @param {Object} [options] - Query options
66
- * @param {number} [options.limit] - Max results (default: 100, max: 500)
67
- * @param {number} [options.offset] - Offset for pagination
68
- * @param {string} [options.after] - Cursor for pagination (format: "namespace:service")
69
- * @param {string} [options.search] - Search query
70
- * @param {string} [options.status] - Filter by status: 'active', 'warning', 'exceeded'
71
- * @returns {Promise<Object>} Namespaces with quotas and pagination info
72
- */
73
- async getNamespaceQuotas(options = {}) {
74
- const response = await this.client.get('credits/namespaces', options);
75
- return response;
76
- }
77
-
78
- /**
79
- * Get detailed namespace quota information
80
- * @param {string} namespace - Namespace slug or ID
81
- * @param {Object} [options] - Query options
82
- * @param {number} [options.days] - Number of days for stats (default: 7, max: 90)
83
- * @returns {Promise<Object>} Namespace details with quotas, usage, and transactions
84
- */
85
- async getNamespaceDetails(namespace, options = {}) {
86
- const response = await this.client.get(`credits/namespaces/${namespace}`, options);
87
- return response;
88
- }
89
-
90
- /**
91
- * Set quota for a namespace and service
92
- * @param {Object} options - Quota options
93
- * @param {string} options.namespace - Namespace slug
94
- * @param {string} options.service - Service name (e.g., 'ai', 'deployment', 'sandbox')
95
- * @param {number} options.quotaLimit - Quota limit (null or 0 for unlimited)
96
- * @param {string} [options.period] - Quota period: 'daily', 'monthly', 'unlimited'
97
- * @returns {Promise<Object>} Created/updated quota
98
- */
99
- async setQuota(options) {
100
- if (!options.namespace || !options.service) {
101
- throw new Error('namespace and service are required');
102
- }
103
-
104
- if (options.quotaLimit === undefined) {
105
- throw new Error('quotaLimit is required');
106
- }
107
-
108
- const response = await this.client.post('credits/namespace-quota', {
109
- namespace: options.namespace,
110
- service: options.service,
111
- quotaLimit: options.quotaLimit,
112
- period: options.period || 'unlimited'
113
- });
114
-
115
- return response;
116
- }
117
-
118
- /**
119
- * Reset namespace quota (e.g., for monthly reset)
120
- * @param {string} namespace - Namespace slug
121
- * @param {string} service - Service name
122
- * @returns {Promise<Object>} Reset result
123
- */
124
- async resetQuota(namespace, service) {
125
- if (!namespace || !service) {
126
- throw new Error('namespace and service are required');
127
- }
128
-
129
- const response = await this.client.post('credits/reset-quota', {
130
- namespace,
131
- service
132
- });
133
-
134
- return response;
135
- }
136
-
137
- // =============================================================================
138
- // End User Quota Management (Optional Third Level)
139
- // =============================================================================
140
-
141
- /**
142
- * Set quota for an end user within a namespace
143
- * @param {Object} options - Quota options
144
- * @param {string} options.namespace - Namespace slug
145
- * @param {string} options.endUserId - End user ID
146
- * @param {string} options.service - Service name (e.g., 'ai_chat', 'deployment', 'sandbox')
147
- * @param {number} options.quotaLimit - Quota limit (null or 0 for unlimited)
148
- * @param {string} [options.period] - Quota period: 'daily', 'monthly', 'unlimited'
149
- * @returns {Promise<Object>} Created/updated end user quota
150
- */
151
- async setEndUserQuota(options) {
152
- if (!options.namespace || !options.endUserId || !options.service) {
153
- throw new Error('namespace, endUserId, and service are required');
154
- }
155
-
156
- if (options.quotaLimit === undefined) {
157
- throw new Error('quotaLimit is required');
158
- }
159
-
160
- const response = await this.client.post('credits/end-users/quota', {
161
- namespace: options.namespace,
162
- endUserId: options.endUserId,
163
- service: options.service,
164
- quotaLimit: options.quotaLimit,
165
- period: options.period || 'unlimited'
166
- });
167
-
168
- return response;
169
- }
170
-
171
- /**
172
- * Get end user quota
173
- * @param {string} namespace - Namespace slug
174
- * @param {string} endUserId - End user ID
175
- * @param {string} service - Service name
176
- * @returns {Promise<Object>} End user quota details
177
- */
178
- async getEndUserQuota(namespace, endUserId, service) {
179
- if (!namespace || !endUserId || !service) {
180
- throw new Error('namespace, endUserId, and service are required');
181
- }
182
-
183
- const response = await this.client.get('credits/end-users/quota', {
184
- namespace,
185
- endUserId,
186
- service
187
- });
188
-
189
- return response;
190
- }
191
-
192
- /**
193
- * Reset end user quota usage
194
- * @param {string} namespace - Namespace slug
195
- * @param {string} endUserId - End user ID
196
- * @param {string} service - Service name
197
- * @returns {Promise<Object>} Reset result
198
- */
199
- async resetEndUserQuota(namespace, endUserId, service) {
200
- if (!namespace || !endUserId || !service) {
201
- throw new Error('namespace, endUserId, and service are required');
202
- }
203
-
204
- const response = await this.client.post('credits/end-users/reset', {
205
- namespace,
206
- endUserId,
207
- service
208
- });
209
-
210
- return response;
211
- }
212
-
213
- // =============================================================================
214
- // Default Quota Configuration (Dynamic, per client)
215
- // =============================================================================
216
-
217
- /**
218
- * Set default quota configuration
219
- * @param {Object} options - Configuration options
220
- * @param {string} options.level - 'namespace' or 'end_user'
221
- * @param {string} options.service - Service name (e.g., 'ai_chat', 'deployment')
222
- * @param {number} options.quotaLimit - Default quota limit (null for unlimited)
223
- * @param {string} [options.period] - 'daily', 'monthly', or 'unlimited'
224
- * @param {boolean} [options.autoApply] - Auto-apply to new namespaces/users
225
- * @returns {Promise<Object>} Configuration result
226
- */
227
- async setDefaultQuota(options) {
228
- if (!options.level || !options.service || options.quotaLimit === undefined) {
229
- throw new Error('level, service, and quotaLimit are required');
230
- }
231
-
232
- if (!['namespace', 'end_user'].includes(options.level)) {
233
- throw new Error('level must be "namespace" or "end_user"');
234
- }
235
-
236
- const response = await this.client.post('credits/defaults', {
237
- level: options.level,
238
- service: options.service,
239
- quotaLimit: options.quotaLimit,
240
- period: options.period || 'unlimited',
241
- autoApply: options.autoApply !== undefined ? options.autoApply : true,
242
- });
243
-
244
- return response;
245
- }
246
-
247
- /**
248
- * Get default quota configuration
249
- * @param {string} level - 'namespace' or 'end_user'
250
- * @param {string} service - Service name
251
- * @returns {Promise<Object>} Configuration details
252
- */
253
- async getDefaultQuota(level, service) {
254
- if (!level || !service) {
255
- throw new Error('level and service are required');
256
- }
257
-
258
- const response = await this.client.get('credits/defaults', {
259
- level,
260
- service,
261
- });
262
-
263
- return response;
264
- }
265
-
266
- /**
267
- * Get all default quota configurations
268
- * @param {string} [level] - Optional: filter by 'namespace' or 'end_user'
269
- * @returns {Promise<Object>} All configurations
270
- */
271
- async getAllDefaultQuotas(level = null) {
272
- const params = level ? { level } : {};
273
- const response = await this.client.get('credits/defaults/all', params);
274
- return response;
275
- }
276
-
277
- /**
278
- * Delete default quota configuration
279
- * @param {string} level - 'namespace' or 'end_user'
280
- * @param {string} service - Service name
281
- * @returns {Promise<Object>} Deletion result
282
- */
283
- async deleteDefaultQuota(level, service) {
284
- if (!level || !service) {
285
- throw new Error('level and service are required');
286
- }
287
-
288
- // DELETE with body
289
- const response = await this.client.delete('credits/defaults', {
290
- level,
291
- service,
292
- });
293
-
294
- return response;
295
- }
296
-
297
- /**
298
- * Toggle auto-apply for default quota
299
- * @param {string} level - 'namespace' or 'end_user'
300
- * @param {string} service - Service name
301
- * @param {boolean} autoApply - Enable/disable auto-apply
302
- * @returns {Promise<Object>} Toggle result
303
- */
304
- async toggleDefaultQuotaAutoApply(level, service, autoApply) {
305
- if (!level || !service || autoApply === undefined) {
306
- throw new Error('level, service, and autoApply are required');
307
- }
308
-
309
- const response = await this.client.post('credits/defaults/toggle-auto-apply', {
310
- level,
311
- service,
312
- autoApply,
313
- });
314
-
315
- return response;
316
- }
317
-
318
- // =============================================================================
319
- // Usage History & Transactions
320
- // =============================================================================
321
-
322
- /**
323
- * Get credit usage history with filtering and pagination
324
- * @param {Object} [options] - Query options
325
- * @param {string} [options.namespace] - Filter by namespace
326
- * @param {string} [options.endUserId] - Filter by end user ID
327
- * @param {string} [options.service] - Filter by service
328
- * @param {string} [options.type] - Filter by type: 'deduction', 'addition', 'refund', 'adjustment'
329
- * @param {string} [options.startDate] - Start date (ISO string)
330
- * @param {string} [options.endDate] - End date (ISO string)
331
- * @param {number} [options.limit] - Max results (default: 50)
332
- * @param {number} [options.offset] - Offset for pagination
333
- * @param {string} [options.after] - Cursor for pagination (timestamp)
334
- * @param {number} [options.afterId] - Cursor ID for pagination
335
- * @returns {Promise<Object>} History with transactions and pagination
336
- */
337
- async getHistory(options = {}) {
338
- const response = await this.client.get('credits/history', options);
339
- return response;
340
- }
341
-
342
- /**
343
- * Get available filter options for history
344
- * @returns {Promise<Object>} Available namespaces and services
345
- */
346
- async getHistoryFilters() {
347
- const response = await this.client.get('credits/history/filters');
348
- return response;
349
- }
350
-
351
- /**
352
- * Get usage summary by namespace/service
353
- * @param {Object} [options] - Query options
354
- * @param {string} [options.namespace] - Filter by namespace
355
- * @param {number} [options.days] - Number of days to look back (default: 30)
356
- * @param {number} [options.limit] - Max results (default: 50, max: 500)
357
- * @param {number} [options.offset] - Offset for pagination
358
- * @param {number} [options.after] - Cursor for pagination (total_spent value)
359
- * @returns {Promise<Object>} Summary with aggregated usage
360
- */
361
- async getSummary(options = {}) {
362
- const response = await this.client.get('credits/summary', options);
363
- return response;
364
- }
365
-
366
- /**
367
- * Get daily usage statistics (for charts)
368
- * @param {Object} [options] - Query options
369
- * @param {number} [options.days] - Number of days (default: 7)
370
- * @returns {Promise<Object>} Daily usage statistics
371
- */
372
- async getUsageStats(options = {}) {
373
- const response = await this.client.get('credits/usage-stats', options);
374
- return response;
375
- }
376
-
377
- // =============================================================================
378
- // Pricing & Packages
379
- // =============================================================================
380
-
381
- /**
382
- * Get available credit packages
383
- * @returns {Promise<Array>} Array of credit packages
384
- */
385
- async getPackages() {
386
- const response = await this.client.get('credits/packages');
387
- return response.packages || response.data || response;
388
- }
389
-
390
- /**
391
- * Get pricing information and limits
392
- * @returns {Promise<Object>} Pricing info with rates and limits
393
- */
394
- async getPricingInfo() {
395
- const response = await this.client.get('credits/pricing-info');
396
- return response;
397
- }
398
-
399
- /**
400
- * Calculate credits from money or vice versa
401
- * @param {Object} options - Calculation options
402
- * @param {string} [options.packageId] - Package ID to calculate
403
- * @param {number} [options.amount] - Money amount to convert to credits
404
- * @param {number} [options.credits] - Credits to convert to money
405
- * @returns {Promise<Object>} Calculation result with amount and credits
406
- */
407
- async calculateCost(options) {
408
- if (!options.packageId && !options.amount && !options.credits) {
409
- throw new Error('Must provide either packageId, amount, or credits');
410
- }
411
-
412
- const response = await this.client.post('credits/calculate-cost', options);
413
- return response;
414
- }
415
-
416
- /**
417
- * Calculate credits for a given amount (preview)
418
- * @param {number} amount - Money amount
419
- * @returns {Promise<Object>} Credits calculation
420
- */
421
- async calculateCredits(amount) {
422
- const response = await this.client.get('credits/calculate', { amount });
423
- return response;
424
- }
425
-
426
- // =============================================================================
427
- // Purchase Management
428
- // =============================================================================
429
-
430
- /**
431
- * Create Stripe checkout to purchase credits
432
- * @param {Object} options - Purchase options
433
- * @param {string} [options.packageId] - Package ID to purchase
434
- * @param {number} [options.amount] - Custom amount to purchase
435
- * @param {Object} [options.metadata] - Additional metadata
436
- * @returns {Promise<Object>} Checkout session with URL
437
- */
438
- async createCheckout(options) {
439
- if (!options.packageId && !options.amount) {
440
- throw new Error('Must provide either packageId or amount');
441
- }
442
-
443
- const response = await this.client.post('credits/purchase', options);
444
- return response;
445
- }
446
-
447
- /**
448
- * Get purchase history
449
- * @param {Object} [options] - Query options
450
- * @param {number} [options.limit] - Max results (default: 50, max: 100)
451
- * @param {number} [options.offset] - Offset for pagination
452
- * @param {boolean} [options.light] - If true, returns basic data only (faster)
453
- * @returns {Promise<Object>} Purchase history with pagination
454
- */
455
- async getPurchaseHistory(options = {}) {
456
- const response = await this.client.get('credits/purchases', options);
457
- return response;
458
- }
459
-
460
- /**
461
- * Get single purchase details
462
- * @param {string} purchaseId - Purchase ID
463
- * @returns {Promise<Object>} Purchase details
464
- */
465
- async getPurchaseDetails(purchaseId) {
466
- const response = await this.client.get(`credits/purchases/${purchaseId}`);
467
- return response;
468
- }
469
-
470
- /**
471
- * Get Stripe checkout session URL for pending purchase
472
- * @param {string} purchaseId - Purchase ID
473
- * @returns {Promise<Object>} Session with checkout URL
474
- */
475
- async getPurchaseSession(purchaseId) {
476
- const response = await this.client.get(`credits/purchases/${purchaseId}/session`);
477
- return response;
478
- }
479
-
480
- /**
481
- * Cancel a pending purchase
482
- * @param {string} purchaseId - Purchase ID
483
- * @returns {Promise<Object>} Cancellation result
484
- */
485
- async cancelPurchase(purchaseId) {
486
- const response = await this.client.post(`credits/purchases/${purchaseId}/cancel`);
487
- return response;
488
- }
489
- }
490
-
491
- export default OblienCredits;
492
-
@@ -1,185 +0,0 @@
1
- /**
2
- * Oblien Icons Module
3
- * Search and fetch icons, images, and videos
4
- */
5
-
6
- export class OblienIcons {
7
- constructor(client) {
8
- if (!client) throw new Error('Oblien client is required');
9
- this.client = client;
10
- }
11
-
12
- /**
13
- * Search for icons using semantic search
14
- *
15
- * @param {string} query - Search query
16
- * @param {Object} options - Search options
17
- * @param {number} options.offset - Pagination offset (default: 0)
18
- * @param {number} options.limit - Number of results (default: 100)
19
- * @returns {Promise<Object>} Search results with pagination info
20
- *
21
- * @example
22
- * const results = await icons.search('home', { limit: 50 });
23
- * // Returns:
24
- * // {
25
- * // results: [
26
- * // {
27
- * // url: 'https://cdn.oblien.com/static/png-icons/...',
28
- * // filename: 'home-outline.png',
29
- * // name: 'home',
30
- * // description: 'home',
31
- * // style: 'Outline',
32
- * // score: 0.95,
33
- * // success: true
34
- * // }
35
- * // ],
36
- * // hasMore: true,
37
- * // offset: 50,
38
- * // total: 245
39
- * // }
40
- */
41
- async search(query, options = {}) {
42
- if (!query || typeof query !== 'string') {
43
- throw new Error('Query must be a non-empty string');
44
- }
45
-
46
- const { offset = 0, limit = 100 } = options;
47
-
48
- return this.client.post('icons/search-icons', {
49
- query: query.trim(),
50
- offset,
51
- limit
52
- });
53
- }
54
-
55
- /**
56
- * Fetch multiple items (icons, images, videos) with semantic matching
57
- *
58
- * @param {Array<Object>} items - Array of items to fetch
59
- * @param {string} items[].type - Type: 'icon', 'image', or 'video'
60
- * @param {string} items[].description - Description for semantic matching
61
- * @param {boolean} items[].is_vector - Whether the item is a vector (optional)
62
- * @param {string} items[].variant - Variant type (optional, for images/videos)
63
- * @returns {Promise<Array>} Array of fetched items with URLs
64
- *
65
- * @example
66
- * const items = await icons.fetch([
67
- * { type: 'icon', description: 'user profile' },
68
- * { type: 'icon', description: 'settings gear' },
69
- * { type: 'image', description: 'mountain landscape' },
70
- * { type: 'video', description: 'ocean waves' }
71
- * ]);
72
- *
73
- * // Returns:
74
- * // [
75
- * // {
76
- * // url: 'https://cdn.oblien.com/static/icons/...',
77
- * // description: 'user profile',
78
- * // style: 'Outline',
79
- * // success: true
80
- * // },
81
- * // {
82
- * // url: 'https://cdn.oblien.com/static/assets/...',
83
- * // type: 'image',
84
- * // description: 'mountain landscape',
85
- * // variant: 'regular',
86
- * // success: true
87
- * // }
88
- * // ]
89
- */
90
- async fetch(items) {
91
- if (!Array.isArray(items) || items.length === 0) {
92
- throw new Error('Items must be a non-empty array');
93
- }
94
-
95
- // Validate items
96
- for (const item of items) {
97
- if (!item.type || !['icon', 'image', 'video'].includes(item.type)) {
98
- throw new Error('Each item must have a valid type: icon, image, or video');
99
- }
100
- if (!item.description || typeof item.description !== 'string') {
101
- throw new Error('Each item must have a description string');
102
- }
103
- }
104
-
105
- return this.client.post('icons/fetch', { data: items });
106
- }
107
-
108
- /**
109
- * Fetch a single icon
110
- * Convenience method for fetching one icon
111
- *
112
- * @param {string} description - Icon description
113
- * @returns {Promise<Object>} Icon object with URL
114
- *
115
- * @example
116
- * const icon = await icons.fetchIcon('home');
117
- * // Returns: { url: '...', description: 'home', style: 'Outline', success: true }
118
- */
119
- async fetchIcon(description) {
120
- if (!description || typeof description !== 'string') {
121
- throw new Error('Description must be a non-empty string');
122
- }
123
-
124
- const result = await this.fetch([{ type: 'icon', description }]);
125
- return result[0] || null;
126
- }
127
-
128
- /**
129
- * Fetch multiple icons at once
130
- * Convenience method for fetching multiple icons
131
- *
132
- * @param {Array<string>} descriptions - Array of icon descriptions
133
- * @returns {Promise<Array>} Array of icon objects
134
- *
135
- * @example
136
- * const icons = await icons.fetchIcons(['home', 'settings', 'user']);
137
- * // Returns: [{ url: '...', description: 'home', ... }, ...]
138
- */
139
- async fetchIcons(descriptions) {
140
- if (!Array.isArray(descriptions) || descriptions.length === 0) {
141
- throw new Error('Descriptions must be a non-empty array');
142
- }
143
-
144
- const items = descriptions.map(desc => ({ type: 'icon', description: desc }));
145
- return this.fetch(items);
146
- }
147
-
148
- /**
149
- * Search icons with pagination helper
150
- * Automatically handles pagination and returns all results
151
- *
152
- * @param {string} query - Search query
153
- * @param {Object} options - Search options
154
- * @param {number} options.maxResults - Maximum results to fetch (default: 500)
155
- * @param {number} options.batchSize - Results per batch (default: 100)
156
- * @returns {Promise<Array>} All matching icons
157
- *
158
- * @example
159
- * const allIcons = await icons.searchAll('home', { maxResults: 200 });
160
- * // Returns: [{ url: '...', name: 'home', ... }, ...]
161
- */
162
- async searchAll(query, options = {}) {
163
- const { maxResults = 500, batchSize = 100 } = options;
164
- const allResults = [];
165
- let offset = 0;
166
- let hasMore = true;
167
-
168
- while (hasMore && allResults.length < maxResults) {
169
- const response = await this.search(query, {
170
- offset,
171
- limit: Math.min(batchSize, maxResults - allResults.length)
172
- });
173
-
174
- if (response.results && response.results.length > 0) {
175
- allResults.push(...response.results);
176
- }
177
-
178
- hasMore = response.hasMore && allResults.length < maxResults;
179
- offset = response.offset;
180
- }
181
-
182
- return allResults;
183
- }
184
- }
185
-