@periskope/types 0.6.461 → 0.6.463

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.
@@ -0,0 +1,520 @@
1
+ import { Merge, OverrideProperties } from 'type-fest';
2
+
3
+ import { OrgPlanEnterprise, OrgPlanNonEnterprise } from './types';
4
+
5
+ /* ----------------------------- BILLING V2 PLANS & PACKS ----------------------------- */
6
+
7
+ export type BillingVersion = 'v1' | 'v2';
8
+
9
+ export enum AllPlansV2 {
10
+ FREE_TRIAL = 'v2-free-trial',
11
+ MONTHLY_STARTER = 'v2-monthly-starter',
12
+ YEARLY_STARTER = 'v2-annual-starter',
13
+ MONTHLY_PRO = 'v2-monthly-pro',
14
+ YEARLY_PRO = 'v2-annual-pro',
15
+ }
16
+
17
+ export type AddonPackId = SeatAddonPackId | RecurringAddonPackId;
18
+
19
+ /** V2-only — per-seat user & phone add-ons (tier-specific). */
20
+ export type SeatAddonPackId =
21
+ | 'v2-additional-phone-pro'
22
+ | 'v2-additional-user-pro'
23
+ | 'v2-additional-phone-starter'
24
+ | 'v2-additional-user-starter';
25
+
26
+ /** Shared by v1 and v2 — recurring optional add-ons. */
27
+ export type RecurringAddonPackId = 'priority-support-pack' | 'automation-pack';
28
+
29
+ /** Shared by v1 and v2 — one-time charge packs. */
30
+ export type ChargesPack =
31
+ | 'ai-pack'
32
+ | 'bulk-message-credits'
33
+ | 'guided-onboarding'
34
+ | 'support-call'
35
+ | 'support-call-pack';
36
+
37
+ /** Packs with no billing-version prefix — included under both v1 and v2. */
38
+ export type GenericPackId = RecurringAddonPackId | ChargesPack;
39
+
40
+ export const GENERIC_PACK_IDS: readonly GenericPackId[] = [
41
+ 'priority-support-pack',
42
+ 'automation-pack',
43
+ 'ai-pack',
44
+ 'bulk-message-credits',
45
+ 'guided-onboarding',
46
+ 'support-call',
47
+ 'support-call-pack',
48
+ ];
49
+
50
+ export type UsageType = 'ai_credits' | 'automation_rules';
51
+
52
+ export type UsageAllowances = Partial<Record<UsageType, number>>;
53
+ export type UsageConsumption = Partial<Record<UsageType, number>>;
54
+
55
+ /** Recurring add-on flags derived from subscription line items. */
56
+ export type V2AddonEntitlements = Partial<
57
+ Record<RecurringAddonPackId, boolean>
58
+ >;
59
+
60
+ export type OrgPlanV2 = Merge<
61
+ OverrideProperties<
62
+ OrgPlanEnterprise | OrgPlanNonEnterprise,
63
+ {
64
+ plan_id: AllPlansV2;
65
+ }
66
+ >,
67
+ {
68
+ billing_version: 'v2';
69
+ usage_allowances?: UsageAllowances;
70
+ addon_entitlements?: V2AddonEntitlements;
71
+ }
72
+ >;
73
+
74
+ export type OrgPlanV1 = (OrgPlanEnterprise | OrgPlanNonEnterprise) & {
75
+ billing_version?: 'v1';
76
+ };
77
+
78
+ export type AnyOrgPlan = OrgPlanV1 | OrgPlanV2;
79
+
80
+ export const isV2Plan = (plan: AnyOrgPlan): plan is OrgPlanV2 =>
81
+ plan.billing_version === 'v2';
82
+
83
+ /* ----------------------------- SHARED ----------------------------- */
84
+
85
+ export type BillingEntity = 'IN' | 'US';
86
+
87
+ /** Line item passed to Chargebee item-price / subscription APIs. */
88
+ export type BillingV2LineItem = {
89
+ item_price_id: string;
90
+ quantity?: number;
91
+ unit_price?: number;
92
+ };
93
+
94
+ /** Headers required on all billing V2 requests. */
95
+ export type BillingV2RequestHeaders = {
96
+ org_id: string;
97
+ 'x-periskope-trace-id'?: string;
98
+ };
99
+
100
+ export type BillingFrequency = 'monthly' | 'yearly';
101
+
102
+ export type BillingPlanTier = 'starter' | 'pro';
103
+
104
+ /** Money in major currency units (e.g. 2400 = ₹2,400). */
105
+ export type BillingMoney = {
106
+ amount: number;
107
+ currency_code: string;
108
+ };
109
+
110
+ /* ----------------------------- GET PRICES ----------------------------- */
111
+
112
+ export type BillingPriceItem = {
113
+ item_price_id: string;
114
+ item_id: string;
115
+ lookup_key: string | null;
116
+ name: string;
117
+ description: string | null;
118
+ price: BillingMoney;
119
+ frequency: BillingFrequency | null;
120
+ period: number | null;
121
+ status: string;
122
+ };
123
+
124
+ export type BillingVersionPrices = {
125
+ plan: BillingPriceItem[];
126
+ addons: BillingPriceItem[];
127
+ charges: BillingPriceItem[];
128
+ };
129
+
130
+ export type GetPricesParams = {
131
+ currency: string;
132
+ };
133
+
134
+ export type GetPricesResponse = {
135
+ v1: BillingVersionPrices;
136
+ v2: BillingVersionPrices;
137
+ };
138
+
139
+ /* ----------------------------- UPGRADE FLOW — STEP 2: SEAT ADDONS ----------------------------- */
140
+
141
+ export type SeatAddonConfig = {
142
+ pack_id: SeatAddonPackId;
143
+ label: string;
144
+ unit_price: BillingMoney;
145
+ /** Included in base plan before add-on quantity applies (typically 1). */
146
+ included_quantity: number;
147
+ };
148
+
149
+ export type GetSeatAddonsParams = {
150
+ currency: string;
151
+ plan_key: AllPlansV2;
152
+ };
153
+
154
+ export type GetSeatAddonsResponse = {
155
+ users: SeatAddonConfig;
156
+ phones: SeatAddonConfig;
157
+ credits_per_seat_per_month: number;
158
+ };
159
+
160
+ /* ----------------------------- UPGRADE FLOW — STEP 3: RECURRING ADDONS ----------------------------- */
161
+
162
+ export type RecurringAddonBillingModel = 'quantity' | 'flat';
163
+
164
+ export type RecurringAddonOption = {
165
+ pack_id: RecurringAddonPackId;
166
+ name: string;
167
+ description: string;
168
+ billing_model: RecurringAddonBillingModel;
169
+ unit_price: BillingMoney;
170
+ /** e.g. "pack" for automation rules. */
171
+ unit_label?: string;
172
+ rules_per_pack?: number;
173
+ };
174
+
175
+ export type GetRecurringAddonsParams = {
176
+ currency: string;
177
+ };
178
+
179
+ export type GetRecurringAddonsResponse = {
180
+ automation_pack: RecurringAddonOption;
181
+ priority_support: RecurringAddonOption;
182
+ };
183
+
184
+ /* ----------------------------- ORDER SUMMARY (SIDEBAR + REVIEW) ----------------------------- */
185
+
186
+ export type OrderSummaryItemType = 'plan' | 'addon';
187
+
188
+ export type OrderSummaryItem = {
189
+ type: OrderSummaryItemType;
190
+ item_price_id: string;
191
+ lookup_key: string | null;
192
+ name: string;
193
+ description: string | null;
194
+ quantity: number;
195
+ unit_price: BillingMoney;
196
+ amount: BillingMoney;
197
+ /** null for one-time charge line items */
198
+ frequency: BillingFrequency | null;
199
+ };
200
+
201
+ export type GetOrderSummaryRequestBody = {
202
+ subscription_id?: string;
203
+ line_items: BillingV2LineItem[];
204
+ coupon_id?: string;
205
+ };
206
+
207
+ export type OrderSummaryNextCharge = {
208
+ /** Unix timestamp for the next recurring charge. */
209
+ date: number;
210
+ amount: BillingMoney;
211
+ };
212
+
213
+ export type GetOrderSummaryResponse = {
214
+ frequency: BillingFrequency;
215
+ currency_code: string;
216
+ items: OrderSummaryItem[];
217
+ /** Line items with quantity > 0 — for "Subtotal (N items)". */
218
+ item_count: number;
219
+ /** Pre-adjustment subtotal from Chargebee invoice_estimate.sub_total. */
220
+ subtotal: BillingMoney;
221
+ /** Promotional / account credits applied — null when none on estimate. */
222
+ credits_applied: BillingMoney | null;
223
+ /** null when no coupon on the estimate. */
224
+ coupon: AppliedCouponSummary | null;
225
+ /** Amount due after credits and coupon (invoice_estimate.total). */
226
+ total: BillingMoney;
227
+ /** Prorated amount due now (invoice_estimate.amount_due). */
228
+ due_today: BillingMoney;
229
+ /** Next full recurring charge — null when not available on estimate. */
230
+ next_charge: OrderSummaryNextCharge | null;
231
+ };
232
+
233
+ /* ----------------------------- COUPONS ----------------------------- */
234
+
235
+ export type CouponDiscountType = 'fixed_amount' | 'percentage' | 'offer_quantity';
236
+
237
+ export type GetCouponDetailsRequestBody = {
238
+ coupon_code: string;
239
+ };
240
+
241
+ export type GetCouponDetailsResponse = {
242
+ coupon_id: string;
243
+ coupon_code: string;
244
+ name: string | null;
245
+ discount_type: CouponDiscountType;
246
+ /** Set when discount_type is percentage; otherwise null. */
247
+ discount_percentage: number | null;
248
+ /** Set when discount_type is fixed_amount; otherwise null. */
249
+ discount_amount: BillingMoney | null;
250
+ duration_type: 'one_time' | 'forever' | 'limited_period';
251
+ status: string;
252
+ };
253
+
254
+ export type AppliedCouponSummary = {
255
+ coupon_id: string;
256
+ name: string | null;
257
+ discount_type: CouponDiscountType;
258
+ discount_percentage: number | null;
259
+ discount_amount: BillingMoney | null;
260
+ /** Coupon discount applied on this estimate — null when coupon present but discount is zero. */
261
+ applied_amount: BillingMoney | null;
262
+ };
263
+
264
+ /* ----------------------------- CHECKOUT (POST-CONFIRM) ----------------------------- */
265
+
266
+ export type CreateCheckoutSessionRequestBody = {
267
+ success_url: string;
268
+ cancel_url: string;
269
+ line_items: BillingV2LineItem[];
270
+ subscription_id?: string;
271
+ /** Chargebee coupon ids — resolve via POST /get-coupon-details */
272
+ coupon_ids?: string[];
273
+ /** When upgrading an existing sub with coupons. Default `true`. */
274
+ replace_coupon_list?: boolean;
275
+ };
276
+
277
+ export type CreateCheckoutSessionResponse = {
278
+ url: string;
279
+ hosted_page_id: string | null;
280
+ expires_at: number | null;
281
+ };
282
+
283
+ export type CreateChargeCheckoutSessionRequestBody = {
284
+ line_items: BillingV2LineItem[];
285
+ currency?: string;
286
+ };
287
+
288
+ export type CreateChargeCheckoutSessionResponse = {
289
+ url: string;
290
+ hosted_page_id: string | null;
291
+ expires_at: number | null;
292
+ };
293
+
294
+ export type CreateCustomerPortalRequestBody = {
295
+ redirect_url: string;
296
+ };
297
+
298
+ export type CreateCustomerPortalResponse = {
299
+ url: string;
300
+ expires_at?: number;
301
+ };
302
+
303
+ /* ----------------------------- SUBSCRIPTION ----------------------------- */
304
+
305
+ export type UpdateSubscriptionRequestBody = {
306
+ subscription_id: string;
307
+ line_items: BillingV2LineItem[];
308
+ replace_addon_list?: boolean;
309
+ };
310
+
311
+ export type UpdateSubscriptionResponse = {
312
+ subscription_id: string;
313
+ status: string;
314
+ current_term_start: number | null;
315
+ current_term_end: number | null;
316
+ cancelled_at: number | null;
317
+ };
318
+
319
+ export type CancelSubscriptionRequestBody = {
320
+ subscription_id: string;
321
+ };
322
+
323
+ export type CancelSubscriptionResponse = {
324
+ subscription_id: string;
325
+ status: string;
326
+ cancelled_at?: number;
327
+ };
328
+
329
+ export type ResumeCancelledSubscriptionRequestBody = {
330
+ subscription_id: string;
331
+ };
332
+
333
+ export type ResumeCancelledSubscriptionResponse = {
334
+ subscription_id: string;
335
+ status: string;
336
+ };
337
+
338
+ /* ----------------------------- INVOICES ----------------------------- */
339
+
340
+ export type BillingV2InvoiceSummary = {
341
+ invoice_id: string;
342
+ status: string;
343
+ amount_due: BillingMoney;
344
+ date: number;
345
+ };
346
+
347
+ export type GetUnpaidInvoicesResponse = BillingV2InvoiceSummary[];
348
+
349
+ export type GetLatestNextInvoiceResponse = {
350
+ latest_invoice: BillingV2InvoiceSummary | null;
351
+ next_invoice: {
352
+ amount: BillingMoney;
353
+ date: number;
354
+ } | null;
355
+ };
356
+
357
+ export type GetInvoiceLinkResponse = {
358
+ url: string;
359
+ } | null;
360
+
361
+ export type DownloadInvoiceParams = {
362
+ invoice_id: string;
363
+ };
364
+
365
+ export type DownloadInvoiceResponse = {
366
+ url: string;
367
+ valid_till?: number;
368
+ };
369
+
370
+ export type GetRecentInvoicesParams = {
371
+ /** Max invoices to return (default 10, max 50). Customer resolved from org_id — do not pass customer_id. */
372
+ limit?: number;
373
+ };
374
+
375
+ export type RecentInvoiceLineItem = {
376
+ description: string | null;
377
+ entity_description: string | null;
378
+ quantity: number;
379
+ amount: BillingMoney;
380
+ };
381
+
382
+ /** Chargebee invoice row — aligned with dashboard fields (ID, status, type, total, credits). */
383
+ export type ChargebeeInvoiceSummary = {
384
+ invoice_id: string;
385
+ /** Primary display title — first line item description from Chargebee. */
386
+ name: string;
387
+ description: string | null;
388
+ status: string;
389
+ /** `recurring` → "Recurring"; otherwise "One-time" on Chargebee. */
390
+ type: 'recurring' | 'one_time';
391
+ recurring: boolean;
392
+ /** Invoice created date (Chargebee `date`). */
393
+ date: number | null;
394
+ due_date: number | null;
395
+ paid_at: number | null;
396
+ subscription_id: string | null;
397
+ total: BillingMoney;
398
+ amount_due: BillingMoney;
399
+ amount_paid: BillingMoney;
400
+ /** Promotional / account credits applied ("Credits Issued" on Chargebee). */
401
+ credits_applied: BillingMoney | null;
402
+ line_items: RecentInvoiceLineItem[];
403
+ download_url: string | null;
404
+ download_valid_till: number | null;
405
+ };
406
+
407
+ export type RecentInvoice = ChargebeeInvoiceSummary;
408
+
409
+ export type GetRecentInvoicesResponse = RecentInvoice[];
410
+
411
+ /* ----------------------------- CUSTOMER ----------------------------- */
412
+
413
+ /** Billing address fields accepted by Chargebee customer.updateBillingInfo. */
414
+ export type BillingAddress = {
415
+ first_name?: string;
416
+ last_name?: string;
417
+ email?: string;
418
+ company?: string;
419
+ phone?: string;
420
+ line1?: string;
421
+ line2?: string;
422
+ line3?: string;
423
+ city?: string;
424
+ state_code?: string;
425
+ state?: string;
426
+ country?: string;
427
+ zip?: string;
428
+ vat_number?: string;
429
+ };
430
+
431
+ export type UpdateBillingDetailsRequestBody = {
432
+ billing_address: BillingAddress;
433
+ /** When country is IN, optionally move free-trial customer to IN entity. Defaults to US behaviour otherwise. */
434
+ move_to_entity?: BillingEntity;
435
+ };
436
+
437
+ export type UpdateBillingDetailsResponse = {
438
+ customer_id: string;
439
+ billing_address: BillingAddress;
440
+ preferred_currency_code: string;
441
+ };
442
+
443
+ /* ----------------------------- USAGE ----------------------------- */
444
+
445
+ export type GetUsageResponse = {
446
+ allowances: UsageAllowances;
447
+ consumption: UsageConsumption;
448
+ };
449
+
450
+ /* ----------------------------- PLAN SUMMARY ----------------------------- */
451
+
452
+ /** Upcoming renewal charge — null when no subscription or estimate unavailable. */
453
+ export type PlanSummaryNextInvoice = {
454
+ amount: BillingMoney;
455
+ date: number;
456
+ /** e.g. "USD 56.00 on 18 Jul 2026" */
457
+ label: string;
458
+ };
459
+
460
+ export type PlanSummarySection = {
461
+ current_plan: string;
462
+ /** null when org_plan is not seeded yet */
463
+ plan_id: AllPlansV2 | string | null;
464
+ billing_frequency: BillingFrequency | 'weekly' | 'custom';
465
+ users: number;
466
+ phones: number;
467
+ /** null on free trial — no recurring rules allowance */
468
+ rules_allowance: number | null;
469
+ /** null on free trial — recurring BM only; free trial has top-up via charge_packs */
470
+ bm_credits_allowance: number | null;
471
+ /** null on free trial or when no upcoming renewal */
472
+ next_invoice: PlanSummaryNextInvoice | null;
473
+ };
474
+
475
+ export type PlanSummarySubscriptionStatus = 'active' | 'unpaid' | 'inactive';
476
+
477
+ export type PlanSummaryInvoice = ChargebeeInvoiceSummary & {
478
+ /** Hosted payment page — null unless status is payment_due / not_paid. */
479
+ payment_url: string | null;
480
+ };
481
+
482
+ export type PlanSummaryChargePack = {
483
+ pack_id: 'bulk-message-credits';
484
+ lookup_key: string;
485
+ name: string;
486
+ /** Current top-up balance — null when zero. */
487
+ remaining_credits: number | null;
488
+ };
489
+
490
+ export type GetPlanSummaryResponse = {
491
+ billing_version: BillingVersion;
492
+ summary: PlanSummarySection;
493
+ subscription_status: PlanSummarySubscriptionStatus;
494
+ /** Newest first — empty when customer has no invoices. */
495
+ last_5_invoices: PlanSummaryInvoice[];
496
+ /** BM top-up only — empty when top-up balance is zero. */
497
+ charge_packs: PlanSummaryChargePack[];
498
+ };
499
+
500
+ /* ----------------------------- WEBHOOKS ----------------------------- */
501
+
502
+ /** Raw Chargebee webhook POST body. */
503
+ export type ChargebeeWebhookEventPayload = {
504
+ id: string;
505
+ occurred_at: number;
506
+ event_type: string;
507
+ content: Record<string, unknown>;
508
+ source?: string;
509
+ webhook_status?: string;
510
+ };
511
+
512
+ export type ChargebeeV2EventHandleResult = {
513
+ received: true;
514
+ handled: boolean;
515
+ event_id: string;
516
+ event_type: string;
517
+ billing_version?: BillingVersion;
518
+ org_id?: string;
519
+ reason?: string;
520
+ };
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './billing.types';
1
2
  export * from './object.types';
2
3
  export * from './rules.types';
3
4
  export * from './supabase.types';
@@ -2249,6 +2249,56 @@ export type Database = {
2249
2249
  },
2250
2250
  ]
2251
2251
  }
2252
+ tbl_api_tokens: {
2253
+ Row: {
2254
+ exp: string
2255
+ iat: string
2256
+ id: string
2257
+ is_revealed: boolean
2258
+ name: string
2259
+ org_id: string
2260
+ role: string
2261
+ token: string
2262
+ token_hash: string
2263
+ token_metadata: Json
2264
+ type: Database["public"]["Enums"]["enum_integration_type"]
2265
+ }
2266
+ Insert: {
2267
+ exp: string
2268
+ iat: string
2269
+ id: string
2270
+ is_revealed?: boolean
2271
+ name: string
2272
+ org_id: string
2273
+ role: string
2274
+ token: string
2275
+ token_hash: string
2276
+ token_metadata?: Json
2277
+ type: Database["public"]["Enums"]["enum_integration_type"]
2278
+ }
2279
+ Update: {
2280
+ exp?: string
2281
+ iat?: string
2282
+ id?: string
2283
+ is_revealed?: boolean
2284
+ name?: string
2285
+ org_id?: string
2286
+ role?: string
2287
+ token?: string
2288
+ token_hash?: string
2289
+ token_metadata?: Json
2290
+ type?: Database["public"]["Enums"]["enum_integration_type"]
2291
+ }
2292
+ Relationships: [
2293
+ {
2294
+ foreignKeyName: "tbl_api_tokens_org_id_fkey"
2295
+ columns: ["org_id"]
2296
+ isOneToOne: false
2297
+ referencedRelation: "tbl_org"
2298
+ referencedColumns: ["org_id"]
2299
+ },
2300
+ ]
2301
+ }
2252
2302
  tbl_integration_tokens: {
2253
2303
  Row: {
2254
2304
  exp: string
package/src/types.ts CHANGED
@@ -128,6 +128,7 @@ export type OrgAISettings = {
128
128
  top_p?: string;
129
129
  top_k?: string;
130
130
  ai_maintain_flag_status?: boolean;
131
+ ai_inline_unflag_on_reply?: boolean;
131
132
  enable_shift_timing?: boolean;
132
133
  shift_start_time?: string;
133
134
  shift_end_time?: string;
@@ -1014,6 +1015,7 @@ export type APIAuthDetails = {
1014
1015
  org_details: Tables<'view_org'> | null;
1015
1016
  phone_details: Tables<'tbl_org_phones'> | null;
1016
1017
  token_details: Tables<'tbl_integration_tokens'> | null;
1018
+ api_token_details: Tables<'tbl_api_tokens'> | null;
1017
1019
  };
1018
1020
 
1019
1021
  export type WebhookDataType = OverrideProperties<