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