@vibiz/app 0.2.4 → 0.3.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.
package/dist/index.d.ts CHANGED
@@ -66,11 +66,16 @@ export interface Payment {
66
66
  object: 'payment';
67
67
  id: string;
68
68
  status: 'succeeded' | 'refunded' | 'partially_refunded' | 'disputed' | 'failed';
69
+ /** In `currency`, its smallest unit (cents; whole units for jpy, krw, clp). */
69
70
  amount_cents: number;
70
71
  refunded_cents: number;
72
+ /** Through Vibiz in another currency: in USD, the balance's (as `net_cents`). */
71
73
  fee_cents: number;
72
74
  net_cents: number;
73
- currency: 'usd';
75
+ /** Lowercase ISO 4217: what the buyer paid in. */
76
+ currency: string;
77
+ /** Through Vibiz: what the sale added to the balance before fees, in US cents; null on your own account. */
78
+ settled_usd_cents: number | null;
74
79
  description: string | null;
75
80
  user: string | null;
76
81
  customer_email: string | null;
@@ -98,19 +103,43 @@ export interface Subscription {
98
103
  user: string | null;
99
104
  customer_email: string | null;
100
105
  price_id: string | null;
101
- /** `own`: billed on the owner's own Stripe account. The app's code is the same either way. */
106
+ /** `own`: billed on the owner's own Stripe account (or paid by a store). The app's code is the same either way. */
102
107
  account: 'vibiz' | 'own';
108
+ /**
109
+ * Where it was bought: `web` (a checkout), or `app_store` / `play_store` (in the app, through
110
+ * the owner's own RevenueCat account; the user cancels those in the store). Older servers leave it out.
111
+ */
112
+ source?: 'web' | 'app_store' | 'play_store';
113
+ /** Store purchases: the store's product id (`com.acme.app.pro_monthly`). */
114
+ store_product_id?: string | null;
115
+ /** Store purchases: the entitlements it gives (`pro`). */
116
+ entitlements?: string[];
103
117
  current_period_end: string | null;
104
118
  cancel_at_period_end: boolean;
105
119
  created_at: string;
106
120
  }
121
+ /** One thing a user has now, and where it comes from (docs: app-store "One answer"). */
122
+ export interface Entitlement {
123
+ object: 'entitlement';
124
+ /** The plan's key, one per product in the catalog (`pro`). */
125
+ key: string;
126
+ active: true;
127
+ source: 'web' | 'app_store' | 'play_store';
128
+ subscription_id: string;
129
+ price_id: string | null;
130
+ lookup_key: string | null;
131
+ store_product_id: string | null;
132
+ expires_at: string | null;
133
+ will_renew: boolean;
134
+ }
107
135
  export interface Price {
108
136
  object: 'price';
109
137
  id: string;
110
138
  product_id: string;
111
139
  active: boolean;
140
+ /** In the smallest unit of `currency`. */
112
141
  unit_amount_cents: number;
113
- currency: 'usd';
142
+ currency: string;
114
143
  type: 'one_time' | 'recurring';
115
144
  interval: 'day' | 'week' | 'month' | 'year' | null;
116
145
  interval_count: number | null;
@@ -129,9 +158,11 @@ export interface CheckoutInput {
129
158
  /** One of these… */
130
159
  price_id?: string;
131
160
  lookup_key?: string;
132
- /** …or an ad-hoc one-time item. */
161
+ /** …or an ad-hoc one-time item, in the smallest unit of `currency` (cents; whole yen for jpy). */
133
162
  amount_cents?: number;
134
163
  name?: string;
164
+ /** With `amount_cents`: lowercase ISO 4217 (`eur`, `gbp`, `jpy`…); left out: usd. A price has its own. */
165
+ currency?: string;
135
166
  quantity?: number;
136
167
  /** Your own user's id: their payments and subscriptions are found by it. */
137
168
  user?: string;
@@ -140,6 +171,25 @@ export interface CheckoutInput {
140
171
  cancel_url: string;
141
172
  /** Up to 20 keys, echoed on the payment and in webhooks. */
142
173
  metadata?: Record<string, string>;
174
+ /** Your business's look on the checkout page, over the project's brand field by field. */
175
+ brand?: CheckoutBrand;
176
+ }
177
+ /**
178
+ * How the hosted checkout page looks. Left out, a field comes from the
179
+ * project's brand (console ▸ Payments, or `PATCH …/payments { brand }`).
180
+ */
181
+ export interface CheckoutBrand {
182
+ /** At the top of the page instead of the business name. */
183
+ name?: string;
184
+ /** https URLs; with both, the logo shows and the (square) icon is the tab's. */
185
+ logo_url?: string;
186
+ icon_url?: string;
187
+ /** Hex: `#rrggbb` or `#rgb`. */
188
+ background_color?: string;
189
+ button_color?: string;
190
+ /** e.g. `inter`, `roboto`, `lato`, `montserrat`, `open_sans`, `default`. */
191
+ font?: string;
192
+ border_style?: 'pill' | 'rectangular' | 'rounded';
143
193
  }
144
194
  /** An event Vibiz sent to your webhook, verified. */
145
195
  /** A connector as the app sees it: what it may call, never a key. */
@@ -471,7 +521,9 @@ export declare class VibizApp {
471
521
  /**
472
522
  * Any action, billed to the project: web data (`web.scrape`, `web.search`, `web.crawl`,
473
523
  * `web.screenshot`, `web.design`, `ads.library`, `places.search`, `reviews`, `social.profile`,
474
- * `social.posts`, `ecommerce.product`, `linkedin.company`) or `email.send`.
524
+ * `social.posts`, `ecommerce.product`, `linkedin.company`, and SEO data: `seo.serp`,
525
+ * `seo.keywords`, `seo.keyword_ideas`, `seo.domain`, `seo.backlinks`, `seo.audit`,
526
+ * `seo.ai_mentions`) or `email.send`.
475
527
  */
476
528
  readonly actions: {
477
529
  run: <O = unknown>(name: string, input: unknown) => Promise<ActionResult<O>>;
@@ -481,6 +533,7 @@ export declare class VibizApp {
481
533
  * first call, before the owner has verified anything. Refunds and
482
534
  * withdrawals are the owner's, in the console.
483
535
  */
536
+ private entitlementList;
484
537
  readonly payments: {
485
538
  /** A hosted checkout page for a price (one-time or a subscription) or an ad-hoc item. */
486
539
  checkout: (input: CheckoutInput) => Promise<{
@@ -491,7 +544,17 @@ export declare class VibizApp {
491
544
  }>;
492
545
  /** The user's live subscription (active, trialing or past due), or null. */
493
546
  subscription: (user: string) => Promise<Subscription | null>;
494
- /** Whether the user has an active (or trialing) subscription, optionally to one price id or lookup key. */
547
+ /**
548
+ * What the user has now, across web checkout subscriptions and App Store / Google Play
549
+ * purchases: one entry per thing it gives, with its `source`. Server-side only.
550
+ */
551
+ entitlements: (user: string) => Promise<Entitlement[]>;
552
+ /**
553
+ * Whether the user has it now: anything (no `key`), or one thing, matched in this order:
554
+ * an entitlement key (`pro`; a string that is one of the project's entitlement keys is
555
+ * matched only as that), else a lookup key (`pro-monthly`), a price id, a store product id.
556
+ * Counts the web checkout and the App Store / Google Play alike.
557
+ */
495
558
  hasActive: (user: string, price?: string) => Promise<boolean>;
496
559
  /** A link where the user manages their subscription and card. */
497
560
  portal: (user: string, opts: {
package/dist/index.js CHANGED
@@ -336,7 +336,9 @@ var VibizApp = class _VibizApp {
336
336
  /**
337
337
  * Any action, billed to the project: web data (`web.scrape`, `web.search`, `web.crawl`,
338
338
  * `web.screenshot`, `web.design`, `ads.library`, `places.search`, `reviews`, `social.profile`,
339
- * `social.posts`, `ecommerce.product`, `linkedin.company`) or `email.send`.
339
+ * `social.posts`, `ecommerce.product`, `linkedin.company`, and SEO data: `seo.serp`,
340
+ * `seo.keywords`, `seo.keyword_ideas`, `seo.domain`, `seo.backlinks`, `seo.audit`,
341
+ * `seo.ai_mentions`) or `email.send`.
340
342
  */
341
343
  actions = {
342
344
  run: (name, input) => this.request(`/app/actions/${encodeURIComponent(name)}`, {
@@ -348,6 +350,11 @@ var VibizApp = class _VibizApp {
348
350
  * first call, before the owner has verified anything. Refunds and
349
351
  * withdrawals are the owner's, in the console.
350
352
  */
353
+ entitlementList(user) {
354
+ return this.request(
355
+ `/app/payments/entitlements?user=${encodeURIComponent(user)}`
356
+ );
357
+ }
351
358
  payments = {
352
359
  /** A hosted checkout page for a price (one-time or a subscription) or an ad-hoc item. */
353
360
  checkout: (input) => this.request(
@@ -361,8 +368,33 @@ var VibizApp = class _VibizApp {
361
368
  );
362
369
  return r.data[0] ?? null;
363
370
  },
364
- /** Whether the user has an active (or trialing) subscription, optionally to one price id or lookup key. */
371
+ /**
372
+ * What the user has now, across web checkout subscriptions and App Store / Google Play
373
+ * purchases: one entry per thing it gives, with its `source`. Server-side only.
374
+ */
375
+ entitlements: async (user) => (await this.entitlementList(user)).data,
376
+ /**
377
+ * Whether the user has it now: anything (no `key`), or one thing, matched in this order:
378
+ * an entitlement key (`pro`; a string that is one of the project's entitlement keys is
379
+ * matched only as that), else a lookup key (`pro-monthly`), a price id, a store product id.
380
+ * Counts the web checkout and the App Store / Google Play alike.
381
+ */
365
382
  hasActive: async (user, price) => {
383
+ let list = null;
384
+ try {
385
+ list = await this.entitlementList(user);
386
+ } catch (err) {
387
+ if (!(err instanceof VibizAppError) || err.status !== 404) throw err;
388
+ }
389
+ if (list) {
390
+ const grants = list.data;
391
+ if (!price) return grants.length > 0;
392
+ if (grants.some((g) => g.key === price)) return true;
393
+ if (list.entitlement_keys?.includes(price)) return false;
394
+ return grants.some(
395
+ (g) => g.lookup_key === price || g.price_id === price || g.store_product_id === price
396
+ );
397
+ }
366
398
  const r = await this.request(
367
399
  `/app/payments/subscriptions?user=${encodeURIComponent(user)}&status=active,trialing`
368
400
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibiz/app",
3
- "version": "0.2.4",
3
+ "version": "0.3.1",
4
4
  "description": "One key for your app: env, AI, email, actions and events from Vibiz Stack.",
5
5
  "keywords": [
6
6
  "vibiz",