@whitewall/blip-sdk 0.0.163 → 0.0.165

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.
@@ -1,7 +1,7 @@
1
1
  import type { BlipClient } from '../client.ts'
2
2
  import type { BlipLanguage } from '../types/account.ts'
3
3
  import type { Identity } from '../types/node.ts'
4
- import type { DetailedPlugin, Plugin, PluginSubscription } from '../types/plugins.ts'
4
+ import type { DetailedPlugin, Plugin, PluginBilling, PluginSubscription } from '../types/plugins.ts'
5
5
  import type { Application } from '../types/portal.ts'
6
6
  import { uri } from '../utils/uri.ts'
7
7
  import { type ConsumeOptions, Namespace, type SendCommandOptions } from './namespace.ts'
@@ -221,11 +221,156 @@ export class PluginsNamespace extends Namespace {
221
221
  )
222
222
  }
223
223
 
224
+ /** This route can only be called by an admin user of blip.ai */
225
+ public deletePluginMedia(mediaId: string, opts?: ConsumeOptions) {
226
+ return this.sendCommand(
227
+ {
228
+ method: 'delete',
229
+ uri: uri`/images/${mediaId}`,
230
+ },
231
+ opts,
232
+ )
233
+ }
234
+
235
+ /** This route can only be called by an admin user of blip.ai */
236
+ public addPluginMedia(pluginId: string, type: 'image' | 'video', url: string, opts?: ConsumeOptions) {
237
+ return this.sendCommand(
238
+ {
239
+ method: 'set',
240
+ type: 'application/vnd.iris.plugins.image-create+json',
241
+ uri: uri`/images`,
242
+ resource: {
243
+ uri: url,
244
+ pluginId,
245
+ imageType: type === 'image' ? 3 : 1,
246
+ },
247
+ },
248
+ opts,
249
+ )
250
+ }
251
+
252
+ /** This route can only be called by an admin user of blip.ai */
253
+ public addPlugin(
254
+ plugin: {
255
+ documentation: DetailedPlugin['documentation']
256
+ url: string
257
+ icon: DetailedPlugin['icon']
258
+ price?: DetailedPlugin['price']
259
+ authorId: number
260
+ media: Array<{ uri: string; type: 'image' | 'video' }>
261
+ tags: Array<number>
262
+ languages: {
263
+ pt: {
264
+ name: string
265
+ overview: string
266
+ description: string
267
+ }
268
+ en: {
269
+ name: string
270
+ overview: string
271
+ description: string
272
+ }
273
+ es: {
274
+ name: string
275
+ overview: string
276
+ description: string
277
+ }
278
+ }
279
+ prices?: Array<
280
+ Omit<PluginBilling, 'billingId' | 'currency' | 'language' | 'isActive' | 'featuresIncluded'> & {
281
+ featuresIncluded: Array<{
282
+ icon: string
283
+ description: string
284
+ }>
285
+ }
286
+ >
287
+ },
288
+ opts?: ConsumeOptions,
289
+ ) {
290
+ const price = plugin.prices?.[0]?.price ?? plugin.price
291
+ return this.sendCommand(
292
+ {
293
+ method: 'set',
294
+ type: 'application/vnd.lime.collection+json',
295
+ uri: uri`/plugins`,
296
+ resource: {
297
+ itemType: 'application/vnd.iris.plugin.resource+json',
298
+ items: [
299
+ {
300
+ name: plugin.languages.pt.name,
301
+ website: plugin.documentation,
302
+ url: plugin.url,
303
+ overview: plugin.languages.pt.overview,
304
+ description: plugin.languages.pt.description,
305
+ version: '1.0.0',
306
+ icon: plugin.icon,
307
+ isPaid: price !== undefined && price > 0,
308
+ price,
309
+ authorId: plugin.authorId,
310
+ installationType: 0,
311
+ configurationLink: '/application/detail/{botId}/plugin/{pluginId}',
312
+ pluginType: 'Frontend',
313
+ images: plugin.media.map((m) => ({
314
+ language: 'pt',
315
+ uri: m.uri,
316
+ imageType: m.type === 'image' ? 3 : 1,
317
+ })),
318
+ chargeType: plugin.prices && plugin.prices.length > 1 ? 3 : 1,
319
+ tags: plugin.tags.map((t) => ({ tagValue: t })),
320
+ languages: [
321
+ {
322
+ language: 0,
323
+ },
324
+ {
325
+ language: 1,
326
+ },
327
+ {
328
+ language: 2,
329
+ },
330
+ ],
331
+ translations: [
332
+ {
333
+ name: plugin.languages.en.name,
334
+ overview: plugin.languages.en.overview,
335
+ description: plugin.languages.en.description,
336
+ language: 'en',
337
+ },
338
+ {
339
+ name: plugin.languages.es.name,
340
+ overview: plugin.languages.es.overview,
341
+ description: plugin.languages.es.description,
342
+ language: 'es',
343
+ },
344
+ ],
345
+ billings: plugin.prices?.map((p) => ({
346
+ name: p.name,
347
+ description: p.description,
348
+ price: p.price,
349
+ // TODO: I don't know exactly what it means yet
350
+ language: 'pt',
351
+ // TODO: This one too
352
+ currency: 1,
353
+ chargeType: 1,
354
+ isRecommended: p.isRecommended,
355
+ featuresIncluded: JSON.stringify(p.featuresIncluded),
356
+ additionalDescription: p.additionalDescription,
357
+ isActive: true,
358
+ })),
359
+ },
360
+ ],
361
+ },
362
+ },
363
+ opts,
364
+ )
365
+ }
366
+
224
367
  /** This route can only be called by an admin user of blip.ai */
225
368
  public updatePlugin(
226
369
  pluginId: string,
227
370
  plugin: Partial<
228
- Pick<DetailedPlugin, 'name' | 'overview' | 'description' | 'icon' | 'documentation'> & { url: string }
371
+ Pick<DetailedPlugin, 'name' | 'overview' | 'description' | 'icon' | 'documentation' | 'price'> & {
372
+ url: string
373
+ }
229
374
  >,
230
375
  opts?: ConsumeOptions,
231
376
  ): Promise<void> {
@@ -241,34 +386,44 @@ export class PluginsNamespace extends Namespace {
241
386
  icon: plugin.icon,
242
387
  website: plugin.documentation,
243
388
  url: plugin.url,
389
+ price: plugin.price,
390
+ isPaid: plugin.price !== undefined && plugin.price > 0,
244
391
  },
245
392
  },
246
393
  opts,
247
394
  )
248
395
  }
249
396
 
250
- /** This route can only be called by an admin user of blip.ai */
251
- public deletePluginMedia(imageId: string, opts?: ConsumeOptions) {
252
- return this.sendCommand(
253
- {
254
- method: 'delete',
255
- uri: uri`/images/${imageId}`,
256
- },
257
- opts,
258
- )
259
- }
260
-
261
- /** This route can only be called by an admin user of blip.ai */
262
- public addPluginMedia(pluginId: string, type: 'image' | 'video', url: string, opts?: ConsumeOptions) {
397
+ public setPluginBilling(
398
+ pluginId: string,
399
+ billingId: string,
400
+ billing: Omit<PluginBilling, 'billingId' | 'currency' | 'language' | 'featuresIncluded'> & {
401
+ featuresIncluded: Array<{
402
+ icon: string
403
+ description: string
404
+ }>
405
+ },
406
+ opts?: ConsumeOptions,
407
+ ) {
263
408
  return this.sendCommand(
264
409
  {
265
410
  method: 'set',
266
- type: 'application/vnd.iris.plugins.image-create+json',
267
- uri: uri`/images`,
411
+ type: 'application/vnd.iris.plugins.billing-update+json',
412
+ uri: uri`/billings/${billingId}`,
268
413
  resource: {
269
- uri: url,
270
- pluginId,
271
- imageType: type === 'image' ? 3 : 1,
414
+ blipPluginId: pluginId,
415
+ name: billing.name,
416
+ description: billing.description,
417
+ featuresIncluded: billing.featuresIncluded ? JSON.stringify(billing.featuresIncluded) : undefined,
418
+ isRecommended: billing.isRecommended,
419
+ price: billing.price,
420
+ additionalDescription: billing.additionalDescription,
421
+ // TODO: add params to this
422
+ language: 'pt',
423
+ // TODO: This one too
424
+ currency: 1,
425
+ chargeType: 3,
426
+ isActive: true,
272
427
  },
273
428
  },
274
429
  opts,
@@ -39,5 +39,6 @@ export class BlipError extends Error {
39
39
  ReasonCodes.GeneralError,
40
40
  ReasonCodes.FailedToSendEnvelopeViaHTTP,
41
41
  ReasonCodes.PendingRequest,
42
+ ReasonCodes.CommandProcessingError,
42
43
  ]
43
44
  }
@@ -33,10 +33,11 @@ export type PluginBilling = {
33
33
  currency: string
34
34
  description: string
35
35
  featuresIncluded: string
36
- isRecommended: boolean
36
+ isRecommended?: boolean
37
37
  language: string
38
38
  name: string
39
39
  price: number
40
+ additionalDescription?: string
40
41
  }
41
42
 
42
43
  export type PluginSubscription = DetailedPlugin & {
@@ -5,6 +5,7 @@ export enum ReasonCodes {
5
5
  FailedToSendEnvelopeViaHTTP = 2105,
6
6
  // Returned on analytics requests when data is not ready but will be soon
7
7
  PendingRequest = 7390,
8
+ CommandProcessingError = 61,
8
9
  }
9
10
 
10
11
  export interface Reason {