@first-to-fly/crm-sdk 1.5.0 → 1.9.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.
- package/README.md +185 -6
- package/dist/api.d.cts +2 -2
- package/dist/api.d.ts +2 -2
- package/dist/{crm-contracts-DLY_TSwy.d.cts → crm-contracts-BiR0JbKC.d.cts} +83 -1
- package/dist/{crm-contracts-DLY_TSwy.d.ts → crm-contracts-BiR0JbKC.d.ts} +83 -1
- package/dist/embed-host.cjs +1 -1
- package/dist/embed-host.cjs.map +1 -1
- package/dist/embed-host.d.cts +77 -1
- package/dist/embed-host.d.ts +77 -1
- package/dist/embed-host.js +1 -1
- package/dist/embed-host.js.map +1 -1
- package/dist/embed-react.cjs +1 -1
- package/dist/embed-react.cjs.map +1 -1
- package/dist/embed-react.d.cts +52 -1
- package/dist/embed-react.d.ts +52 -1
- package/dist/embed-react.js +1 -1
- package/dist/embed-react.js.map +1 -1
- package/dist/partner.cjs +1 -1
- package/dist/partner.cjs.map +1 -1
- package/dist/partner.d.cts +72 -8
- package/dist/partner.d.ts +72 -8
- package/dist/partner.js +1 -1
- package/dist/partner.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -463,6 +463,117 @@ function Shell() {
|
|
|
463
463
|
}
|
|
464
464
|
```
|
|
465
465
|
|
|
466
|
+
#### Host theme and language
|
|
467
|
+
|
|
468
|
+
Pass the host's current look and language so the embedded CRM matches your app:
|
|
469
|
+
|
|
470
|
+
- **`theme?`** — `'light' | 'dark' | 'system'`. `system` follows the visitor's OS setting.
|
|
471
|
+
- **`locale?`** — a BCP 47 tag such as `'en'` or `'zh-CN'`.
|
|
472
|
+
- **`brand?`** — see Host brand below.
|
|
473
|
+
|
|
474
|
+
```tsx
|
|
475
|
+
<CrmEmbed
|
|
476
|
+
crmEmbedOrigin="https://crm.example.com"
|
|
477
|
+
getSession={crmSession('/api/crm/session')}
|
|
478
|
+
theme={isDark ? 'dark' : 'light'}
|
|
479
|
+
locale={i18n.language}
|
|
480
|
+
/>
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
The first values go on the iframe URL (`?theme=dark&locale=zh-CN`), so the frame paints
|
|
484
|
+
in the right theme from the start. When either prop changes later, the component posts
|
|
485
|
+
`{ type: 'crm:host-context', theme?, locale? }` to the frame over the already
|
|
486
|
+
established, origin-checked channel (no reload, no wildcard `postMessage`).
|
|
487
|
+
Non-React hosts call `host.setContext({ theme, locale })` on the `createCrmEmbedHost`
|
|
488
|
+
handle and may pass `hostContext` to it. Omit both props and the CRM behaves as before.
|
|
489
|
+
The CRM applies them for the embed only and never saves them to the user's account.
|
|
490
|
+
The CRM currently ships English text only, so `locale` sets the frame's `lang`
|
|
491
|
+
attribute for now and translated screens follow as they are added.
|
|
492
|
+
|
|
493
|
+
#### Host brand (look native, not framed)
|
|
494
|
+
|
|
495
|
+
Pass `brand` and set `hostProvidesNav` so the CRM reads as part of your app: the CRM
|
|
496
|
+
drops its own tab bar, the tinted "Welcome back" band becomes a plain page header, page
|
|
497
|
+
backgrounds follow your surface, and every button, tab, selected state, chart accent and
|
|
498
|
+
focus ring uses your accent.
|
|
499
|
+
|
|
500
|
+
```tsx
|
|
501
|
+
<CrmEmbed
|
|
502
|
+
crmEmbedOrigin="https://crm.example.com"
|
|
503
|
+
getSession={crmSession('/api/crm/session')}
|
|
504
|
+
hostProvidesNav
|
|
505
|
+
theme={isDark ? 'dark' : 'light'}
|
|
506
|
+
brand={isDark ? DARK_BRAND : LIGHT_BRAND}
|
|
507
|
+
/>
|
|
508
|
+
|
|
509
|
+
const LIGHT_BRAND = {
|
|
510
|
+
accent: '#1f2a44',
|
|
511
|
+
background: '#f6f5f2',
|
|
512
|
+
surface: '#ffffff',
|
|
513
|
+
border: '#e6e3dd',
|
|
514
|
+
foreground: '#1a1a1a',
|
|
515
|
+
radius: '6px',
|
|
516
|
+
fontFamily: 'Inter, system-ui',
|
|
517
|
+
displayFontFamily: 'Georgia, serif',
|
|
518
|
+
};
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
`brand` fields (all optional; absent means the CRM keeps its own look):
|
|
522
|
+
|
|
523
|
+
| Field | Value | Used for |
|
|
524
|
+
| --- | --- | --- |
|
|
525
|
+
| `accent` | `#rgb` or `#rrggbb` | buttons, selected tabs and pills, focus ring, chart accent |
|
|
526
|
+
| `accentForeground` | hex | text on the accent (default: white or near-black, whichever reads better) |
|
|
527
|
+
| `background` | hex | page background |
|
|
528
|
+
| `surface` | hex | cards, popovers (default: `background`) |
|
|
529
|
+
| `border` | hex | hairlines and input borders (default: derived) |
|
|
530
|
+
| `foreground` | hex | body text |
|
|
531
|
+
| `mutedForeground` | hex | secondary text (default: derived) |
|
|
532
|
+
| `radius` | `0px` to `24px`, e.g. `6px` | control corners; larger surfaces scale from it |
|
|
533
|
+
| `fontFamily` | font-family list | UI text, e.g. `Inter, system-ui` |
|
|
534
|
+
| `displayFontFamily` | font-family list | page titles, e.g. `Fraunces, Georgia, serif` |
|
|
535
|
+
|
|
536
|
+
Rules:
|
|
537
|
+
|
|
538
|
+
- Invalid fields are dropped on both sides (the SDK before sending, the CRM on receipt):
|
|
539
|
+
colours must be hex, `radius` a `px` value from 0 to 24, and font lists may contain only
|
|
540
|
+
letters, digits, spaces, commas, quotes, hyphens and underscores (max 160 characters,
|
|
541
|
+
quotes balanced).
|
|
542
|
+
- Pass the tokens for your CURRENT theme and give `brand` a new value when your theme
|
|
543
|
+
toggles. A new brand replaces the previous one; remove the prop (React) or call
|
|
544
|
+
`host.setContext({ brand: null })` to return the CRM to its own look.
|
|
545
|
+
- The first brand rides on the iframe URL as `?brand=` (base64url JSON, at most 1500
|
|
546
|
+
characters, otherwise it is not sent in the URL), so the first paint is already
|
|
547
|
+
on-brand. Later changes go over the channel as
|
|
548
|
+
`{ type: 'crm:host-context', theme?, locale?, brand? }`, no reload.
|
|
549
|
+
- No remote font is ever loaded. The frame is a separate document, so a family that is
|
|
550
|
+
not installed on the visitor's device falls back to the CRM's system font stack.
|
|
551
|
+
Use a family that is also available on the device, or accept the fallback.
|
|
552
|
+
- Nothing is saved to the user's account.
|
|
553
|
+
|
|
554
|
+
#### Routes for your own navigation
|
|
555
|
+
|
|
556
|
+
With `hostProvidesNav`, render your own nav and call the ref's `navigate(path)` (or set
|
|
557
|
+
`initialPath`). These paths are stable:
|
|
558
|
+
|
|
559
|
+
| Section | Path | Notes |
|
|
560
|
+
| --- | --- | --- |
|
|
561
|
+
| Dashboard | `/` | |
|
|
562
|
+
| Inbox (conversations) | `/comms` | `/conversations` is an alias |
|
|
563
|
+
| Contacts | `/contacts` | detail at `/contacts/:id`; `/contacts/email-suppressions` |
|
|
564
|
+
| Leads (pipeline) | `/leads` | `/pipelines` is an alias; detail at `/leads/:id` |
|
|
565
|
+
| Activities | `/activities` | |
|
|
566
|
+
| Settings | `/settings` | opens `/settings/profile`; also `/settings/business`, `/settings/appearance` |
|
|
567
|
+
|
|
568
|
+
AI settings, Workflows, Templates and Knowledge bases are not routes of the embed today,
|
|
569
|
+
so there is nothing to link to. Sections the workspace's plan does not include are
|
|
570
|
+
rejected by the CRM itself.
|
|
571
|
+
|
|
572
|
+
`onRouteChange(path)` is the navigation event: it fires on first load and on every
|
|
573
|
+
in-frame navigation with the sub-path under the embed base (for example `/`, `/comms`,
|
|
574
|
+
`/contacts/42`, `/settings/business`), without a query string. Match by prefix to
|
|
575
|
+
highlight your own nav item, e.g. `/comms` and `/conversations` both mean Inbox.
|
|
576
|
+
|
|
466
577
|
React is an **optional peer dependency** — only pull in this entry if you use
|
|
467
578
|
React. The low-level `embed-host` remains available for non-React consumers.
|
|
468
579
|
|
|
@@ -486,27 +597,86 @@ const partner = createCrmPartnerClient({
|
|
|
486
597
|
});
|
|
487
598
|
|
|
488
599
|
// Idempotent. HTTP 201 the first time (secret shown once), 200 afterwards (no secret).
|
|
489
|
-
const ws = await partner.upsertWorkspace(tenantId, {
|
|
600
|
+
const ws = await partner.upsertWorkspace(tenantId, {
|
|
601
|
+
name: 'Acme School',
|
|
602
|
+
currency: 'SGD', // optional, ISO 4217; new workspaces otherwise start as USD
|
|
603
|
+
timezone: 'Asia/Singapore', // optional, IANA name; otherwise UTC
|
|
604
|
+
aiMonthlyCapCredits: 5000, // optional, monthly AI cap in credits; see "AI cap and usage" below
|
|
605
|
+
});
|
|
490
606
|
if (ws.created) store(tenantId, ws.embedAppId, ws.embedAppSecret);
|
|
491
607
|
|
|
608
|
+
// currency and timezone are applied on create and on any later call that sends them;
|
|
609
|
+
// leaving them out never changes what the workspace already has. An invalid code or zone is a 400.
|
|
610
|
+
|
|
492
611
|
const status = await partner.getWorkspace(tenantId); // null when the CRM does not know the ref
|
|
493
|
-
await partner.updateWorkspace(tenantId, { enabled: false }); // or { name } or
|
|
612
|
+
await partner.updateWorkspace(tenantId, { enabled: false }); // or { name }, { aiMonthlyCapCredits }, or several
|
|
494
613
|
const { embedAppId, embedAppSecret } = await partner.rotateWorkspaceSecret(tenantId); // old secret dies now
|
|
495
614
|
```
|
|
496
615
|
|
|
497
616
|
Every failure is a `CrmPartnerError` with `status` (HTTP status, `0` for network
|
|
498
617
|
failure or timeout) and `code` (the CRM's error code, or `timeout`, `network`,
|
|
499
|
-
`bad_response`, `invalid_external_ref`, `invalid_contact_ref`, `invalid_limit`, `
|
|
618
|
+
`bad_response`, `invalid_external_ref`, `invalid_contact_ref`, `invalid_limit`, `invalid_cap`,
|
|
619
|
+
`invalid_date`, `HTTP_<status>`). Its message never
|
|
500
620
|
contains the key, a secret or a response body. `externalRef` is validated before
|
|
501
621
|
any request is made.
|
|
502
622
|
|
|
623
|
+
### AI cap and usage
|
|
624
|
+
|
|
625
|
+
AI in a provisioned workspace needs no CRM plan. It is metered in **credits**
|
|
626
|
+
(1 credit = US$0.001) and you set a monthly cap per workspace with
|
|
627
|
+
`aiMonthlyCapCredits`:
|
|
628
|
+
|
|
629
|
+
| value | meaning |
|
|
630
|
+
| --- | --- |
|
|
631
|
+
| omitted on create | the default, 5000 credits per month |
|
|
632
|
+
| `N` (integer, 0 to 100,000,000) | N credits per UTC calendar month |
|
|
633
|
+
| `0` | AI off |
|
|
634
|
+
| `null` | no cap |
|
|
635
|
+
|
|
636
|
+
Omitting it on a later `upsertWorkspace` leaves the cap as it is. The month is the
|
|
637
|
+
UTC calendar month. A call that would pass the cap is refused and the workspace's AI
|
|
638
|
+
features say so (an auto-reply hands the conversation to staff and pauses AI on it).
|
|
639
|
+
The check happens on the estimate before a call and again on the real cost after it,
|
|
640
|
+
so one operation can land slightly over the cap; background AI (summaries, intent
|
|
641
|
+
detection) also pauses once 80 percent is used. The embedded assistant is recorded
|
|
642
|
+
but never capped.
|
|
643
|
+
|
|
644
|
+
```typescript
|
|
645
|
+
await partner.updateWorkspace(tenantId, { aiMonthlyCapCredits: 20000 }); // or 0, or null
|
|
646
|
+
|
|
647
|
+
const ws = await partner.getWorkspace(tenantId);
|
|
648
|
+
ws?.aiMonthlyCapCredits; // 20000
|
|
649
|
+
ws?.ai; // { period: '2026-11', usedCredits: 1234 }
|
|
650
|
+
|
|
651
|
+
// Usage over a range: UTC dates, `to` inclusive, at most 12 months. Strings or Dates.
|
|
652
|
+
const usage = await partner.getWorkspaceUsage(tenantId, { from: '2026-11-01', to: '2026-11-30' });
|
|
653
|
+
usage?.totals; // { credits, cost_usd, input_tokens, output_tokens, events, blocked_count }
|
|
654
|
+
usage?.by_operation; // same figures per operation, then by_model and by_day
|
|
655
|
+
usage?.cap; // the CURRENT month: { ai_monthly_cap_credits, period, used_credits, remaining_credits }
|
|
656
|
+
usage?.assistant; // { input_tokens, output_tokens, cost_usd } (estimate); not capped, not in the totals
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
`credits` is the net movement of the credit counter (what the cap counts);
|
|
660
|
+
`cost_usd` is the provider cost. `getWorkspaceUsage` resolves `null` for an unknown
|
|
661
|
+
ref. The report keeps the CRM's snake_case field names, like the contact calls.
|
|
662
|
+
|
|
663
|
+
### Roles
|
|
664
|
+
|
|
665
|
+
The sub-app the CRM creates for you allows sessions up to `admin`. You decide each
|
|
666
|
+
person's role on every sign-in (`user.role` in the exchange); the CRM never grants
|
|
667
|
+
more than you asked for or the sub-app allows. In a provisioned workspace the CRM
|
|
668
|
+
follows you both ways: a person you now assert as `member` is demoted when they next
|
|
669
|
+
sign in, and every request after that uses the lower role (permissions are read from
|
|
670
|
+
the membership on each request, not frozen in the token). Sub-apps created earlier with a `member` ceiling are raised to `admin` by
|
|
671
|
+
the next `upsertWorkspace` for that ref.
|
|
672
|
+
|
|
503
673
|
### Contact sync
|
|
504
674
|
|
|
505
675
|
The same client keeps your own people (parents, guardians, customers) in sync with
|
|
506
676
|
the contacts of a workspace you provisioned, using your own key per contact
|
|
507
677
|
(`contactRef`, `[A-Za-z0-9._:-]{1,200}`). These calls use the **partner key** and act
|
|
508
|
-
as your product: no embed session is involved, and
|
|
509
|
-
|
|
678
|
+
as your product: no embed session is involved, and a session is still one person's
|
|
679
|
+
role. Setting `team_ref` or WhatsApp consent and erasing are allowed here
|
|
510
680
|
because the product, not a staff member, is making the call.
|
|
511
681
|
|
|
512
682
|
```typescript
|
|
@@ -523,6 +693,14 @@ const { contact, created, matched_by, consent_applied } = await partner.upsertCo
|
|
|
523
693
|
// PDPA erasure. Resolves null when there is nothing to erase (404). Works even while the workspace is disabled.
|
|
524
694
|
await partner.eraseContact(tenantId, 'guardian:42');
|
|
525
695
|
|
|
696
|
+
// PDPA erasure of contacts you never linked by ref (a parent who wrote first on WhatsApp).
|
|
697
|
+
// Matches phone digits or email (case-insensitive). Send `ref` so a contact linked only to
|
|
698
|
+
// that ref goes too. A contact with any other ref (another person of yours, or another
|
|
699
|
+
// product) is left alone and counted in skipped_linked_elsewhere. Resolves null for an
|
|
700
|
+
// unknown workspace; works while the workspace is disabled.
|
|
701
|
+
const r = await partner.eraseContactsByIdentity(tenantId, { phone: '+6591234567', email: 'mei@example.com', ref: 'guardian:42' });
|
|
702
|
+
// r = { erased: 1, contact_ids: ['...'], skipped_linked_elsewhere: 0 }
|
|
703
|
+
|
|
526
704
|
// Changes feed: oldest first, includes deleted contacts. Page until next_cursor is null.
|
|
527
705
|
let page = await partner.listContactChanges(tenantId, { since: '2026-01-01T00:00:00Z', limit: 100 });
|
|
528
706
|
while (true) {
|
|
@@ -533,12 +711,13 @@ while (true) {
|
|
|
533
711
|
```
|
|
534
712
|
|
|
535
713
|
- `upsertContact` on a disabled workspace (`updateWorkspace(..., { enabled: false })`)
|
|
536
|
-
fails with `409` / `WORKSPACE_DISABLED`; `eraseContact` and `listContactChanges` still work.
|
|
714
|
+
fails with `409` / `WORKSPACE_DISABLED`; `eraseContact`, `eraseContactsByIdentity` and `listContactChanges` still work.
|
|
537
715
|
- A parent's inbound STOP is never overridden by a product opt-in, unless its
|
|
538
716
|
`source` is `parent_request`; an older consent record never replaces a newer one
|
|
539
717
|
(`consent_applied` says whether yours was written).
|
|
540
718
|
- An unknown workspace is `404` / `NOT_FOUND`; a plan limit on a new contact is `402`
|
|
541
719
|
/ `SUBSCRIPTION_LIMIT_EXCEEDED`.
|
|
720
|
+
- `eraseContactsByIdentity` needs a phone (with digits) or an email, else `invalid_identity` (400) before any request.
|
|
542
721
|
- `contactRef` and `limit` (1 to 200) are validated before any request is made
|
|
543
722
|
(`invalid_contact_ref`, `invalid_limit`).
|
|
544
723
|
|
package/dist/api.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ContactQuery, a as ContactList, b as Contact, c as ContactCreate, d as ContactUpdate, L as LeadQuery, e as ListEnvelope, f as Lead, g as LeadCreate, h as LeadUpdate, T as TaskQuery, i as Task, j as LegacyTaskUpdate, k as LegacyTask, P as ProductQuery, l as Product, m as ProductCreate, n as ProductUpdate, o as ConversationQuery, p as Conversation, q as ConversationUpdate, M as MessageQuery, r as Message, s as MessageCreate, t as TagQuery, u as TagWithUsage, v as TagCreate, w as Tag } from './crm-contracts-
|
|
2
|
-
export { x as ContactChanges, y as ContactChangesQuery, z as ContactRefUpsertBody, A as ContactRefUpsertResult, B as LeadCapture, D as LeadNote, E as LeadNoteCreate, F as
|
|
1
|
+
import { C as ContactQuery, a as ContactList, b as Contact, c as ContactCreate, d as ContactUpdate, L as LeadQuery, e as ListEnvelope, f as Lead, g as LeadCreate, h as LeadUpdate, T as TaskQuery, i as Task, j as LegacyTaskUpdate, k as LegacyTask, P as ProductQuery, l as Product, m as ProductCreate, n as ProductUpdate, o as ConversationQuery, p as Conversation, q as ConversationUpdate, M as MessageQuery, r as Message, s as MessageCreate, t as TagQuery, u as TagWithUsage, v as TagCreate, w as Tag } from './crm-contracts-BiR0JbKC.cjs';
|
|
2
|
+
export { x as ContactChanges, y as ContactChangesQuery, z as ContactRefUpsertBody, A as ContactRefUpsertResult, B as LeadCapture, D as LeadNote, E as LeadNoteCreate, F as PartnerContactEraseByIdentityBody, G as PartnerContactEraseByIdentityResult, H as PartnerContactEraseResult, I as PartnerWorkspaceCreated, J as PartnerWorkspaceDetail, K as PartnerWorkspaceExisting, N as PartnerWorkspacePatchBody, O as PartnerWorkspaceSecret, Q as PartnerWorkspaceStatus, R as PartnerWorkspaceUpsertBody, S as PartnerWorkspaceUsage, U as PartnerWorkspaceUsageQuery, V as TagList } from './crm-contracts-BiR0JbKC.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Typed CRM REST API client for SaaS backends.
|
package/dist/api.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ContactQuery, a as ContactList, b as Contact, c as ContactCreate, d as ContactUpdate, L as LeadQuery, e as ListEnvelope, f as Lead, g as LeadCreate, h as LeadUpdate, T as TaskQuery, i as Task, j as LegacyTaskUpdate, k as LegacyTask, P as ProductQuery, l as Product, m as ProductCreate, n as ProductUpdate, o as ConversationQuery, p as Conversation, q as ConversationUpdate, M as MessageQuery, r as Message, s as MessageCreate, t as TagQuery, u as TagWithUsage, v as TagCreate, w as Tag } from './crm-contracts-
|
|
2
|
-
export { x as ContactChanges, y as ContactChangesQuery, z as ContactRefUpsertBody, A as ContactRefUpsertResult, B as LeadCapture, D as LeadNote, E as LeadNoteCreate, F as
|
|
1
|
+
import { C as ContactQuery, a as ContactList, b as Contact, c as ContactCreate, d as ContactUpdate, L as LeadQuery, e as ListEnvelope, f as Lead, g as LeadCreate, h as LeadUpdate, T as TaskQuery, i as Task, j as LegacyTaskUpdate, k as LegacyTask, P as ProductQuery, l as Product, m as ProductCreate, n as ProductUpdate, o as ConversationQuery, p as Conversation, q as ConversationUpdate, M as MessageQuery, r as Message, s as MessageCreate, t as TagQuery, u as TagWithUsage, v as TagCreate, w as Tag } from './crm-contracts-BiR0JbKC.js';
|
|
2
|
+
export { x as ContactChanges, y as ContactChangesQuery, z as ContactRefUpsertBody, A as ContactRefUpsertResult, B as LeadCapture, D as LeadNote, E as LeadNoteCreate, F as PartnerContactEraseByIdentityBody, G as PartnerContactEraseByIdentityResult, H as PartnerContactEraseResult, I as PartnerWorkspaceCreated, J as PartnerWorkspaceDetail, K as PartnerWorkspaceExisting, N as PartnerWorkspacePatchBody, O as PartnerWorkspaceSecret, Q as PartnerWorkspaceStatus, R as PartnerWorkspaceUpsertBody, S as PartnerWorkspaceUsage, U as PartnerWorkspaceUsageQuery, V as TagList } from './crm-contracts-BiR0JbKC.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Typed CRM REST API client for SaaS backends.
|
|
@@ -126,6 +126,7 @@ type Contact = {
|
|
|
126
126
|
whatsapp_consent?: ("opted_in" | "opted_out" | "unknown") | undefined;
|
|
127
127
|
whatsapp_consent_source?: (string | undefined) | null;
|
|
128
128
|
whatsapp_consent_at?: (string | undefined) | null;
|
|
129
|
+
product_synced?: boolean | undefined;
|
|
129
130
|
metadata?: {
|
|
130
131
|
[x: string]: unknown;
|
|
131
132
|
} | undefined;
|
|
@@ -193,6 +194,7 @@ type ContactList = {
|
|
|
193
194
|
whatsapp_consent?: ("opted_in" | "opted_out" | "unknown") | undefined;
|
|
194
195
|
whatsapp_consent_source?: (string | undefined) | null;
|
|
195
196
|
whatsapp_consent_at?: (string | undefined) | null;
|
|
197
|
+
product_synced?: boolean | undefined;
|
|
196
198
|
metadata?: {
|
|
197
199
|
[x: string]: unknown;
|
|
198
200
|
} | undefined;
|
|
@@ -281,6 +283,7 @@ type ContactRefUpsertResult = {
|
|
|
281
283
|
whatsapp_consent?: ("opted_in" | "opted_out" | "unknown") | undefined;
|
|
282
284
|
whatsapp_consent_source?: (string | undefined) | null;
|
|
283
285
|
whatsapp_consent_at?: (string | undefined) | null;
|
|
286
|
+
product_synced?: boolean | undefined;
|
|
284
287
|
metadata?: {
|
|
285
288
|
[x: string]: unknown;
|
|
286
289
|
} | undefined;
|
|
@@ -343,16 +346,21 @@ type ContactChanges = {
|
|
|
343
346
|
};
|
|
344
347
|
type PartnerWorkspaceUpsertBody = {
|
|
345
348
|
name: string;
|
|
349
|
+
ai_monthly_cap_credits?: (number | null) | undefined;
|
|
350
|
+
currency?: string | undefined;
|
|
351
|
+
timezone?: string | undefined;
|
|
346
352
|
};
|
|
347
353
|
type PartnerWorkspacePatchBody = {
|
|
348
354
|
enabled?: boolean | undefined;
|
|
349
355
|
name?: string | undefined;
|
|
356
|
+
ai_monthly_cap_credits?: (number | null) | undefined;
|
|
350
357
|
};
|
|
351
358
|
type PartnerWorkspaceCreated = {
|
|
352
359
|
external_ref: string;
|
|
353
360
|
workspace_id: string | null;
|
|
354
361
|
embed_app_id: string | null;
|
|
355
362
|
enabled: boolean;
|
|
363
|
+
ai_monthly_cap_credits: number | null;
|
|
356
364
|
embed_app_secret: string;
|
|
357
365
|
created: true;
|
|
358
366
|
};
|
|
@@ -361,6 +369,7 @@ type PartnerWorkspaceExisting = {
|
|
|
361
369
|
workspace_id: string | null;
|
|
362
370
|
embed_app_id: string | null;
|
|
363
371
|
enabled: boolean;
|
|
372
|
+
ai_monthly_cap_credits: number | null;
|
|
364
373
|
created: false;
|
|
365
374
|
};
|
|
366
375
|
type PartnerWorkspaceStatus = {
|
|
@@ -368,13 +377,19 @@ type PartnerWorkspaceStatus = {
|
|
|
368
377
|
workspace_id: string | null;
|
|
369
378
|
embed_app_id: string | null;
|
|
370
379
|
enabled: boolean;
|
|
380
|
+
ai_monthly_cap_credits: number | null;
|
|
371
381
|
};
|
|
372
382
|
type PartnerWorkspaceDetail = {
|
|
373
383
|
external_ref: string;
|
|
374
384
|
workspace_id: string | null;
|
|
375
385
|
embed_app_id: string | null;
|
|
376
386
|
enabled: boolean;
|
|
387
|
+
ai_monthly_cap_credits: number | null;
|
|
377
388
|
state: "pending" | "owner_created" | "workspace_created" | "app_installed" | "sub_app_created" | "active";
|
|
389
|
+
ai: {
|
|
390
|
+
period: string;
|
|
391
|
+
used_credits: number;
|
|
392
|
+
} | null;
|
|
378
393
|
};
|
|
379
394
|
type PartnerWorkspaceSecret = {
|
|
380
395
|
embed_app_id: string;
|
|
@@ -385,6 +400,73 @@ type PartnerContactEraseResult = {
|
|
|
385
400
|
contact_id: string;
|
|
386
401
|
other_sources_removed: number;
|
|
387
402
|
};
|
|
403
|
+
type PartnerWorkspaceUsageQuery = {
|
|
404
|
+
from: string;
|
|
405
|
+
to: string;
|
|
406
|
+
};
|
|
407
|
+
type PartnerWorkspaceUsage = {
|
|
408
|
+
external_ref: string;
|
|
409
|
+
workspace_id: string;
|
|
410
|
+
from: string;
|
|
411
|
+
to: string;
|
|
412
|
+
timezone: "UTC";
|
|
413
|
+
cap: {
|
|
414
|
+
ai_monthly_cap_credits: number | null;
|
|
415
|
+
period: string;
|
|
416
|
+
used_credits: number;
|
|
417
|
+
remaining_credits: number | null;
|
|
418
|
+
};
|
|
419
|
+
totals: {
|
|
420
|
+
credits: number;
|
|
421
|
+
cost_usd: number;
|
|
422
|
+
input_tokens: number;
|
|
423
|
+
output_tokens: number;
|
|
424
|
+
events: number;
|
|
425
|
+
blocked_count: number;
|
|
426
|
+
};
|
|
427
|
+
by_operation: {
|
|
428
|
+
credits: number;
|
|
429
|
+
cost_usd: number;
|
|
430
|
+
input_tokens: number;
|
|
431
|
+
output_tokens: number;
|
|
432
|
+
events: number;
|
|
433
|
+
blocked_count: number;
|
|
434
|
+
operation: string;
|
|
435
|
+
}[];
|
|
436
|
+
by_model: {
|
|
437
|
+
credits: number;
|
|
438
|
+
cost_usd: number;
|
|
439
|
+
input_tokens: number;
|
|
440
|
+
output_tokens: number;
|
|
441
|
+
events: number;
|
|
442
|
+
blocked_count: number;
|
|
443
|
+
model: string;
|
|
444
|
+
}[];
|
|
445
|
+
by_day: {
|
|
446
|
+
credits: number;
|
|
447
|
+
cost_usd: number;
|
|
448
|
+
input_tokens: number;
|
|
449
|
+
output_tokens: number;
|
|
450
|
+
events: number;
|
|
451
|
+
blocked_count: number;
|
|
452
|
+
day: string;
|
|
453
|
+
}[];
|
|
454
|
+
assistant: {
|
|
455
|
+
input_tokens: number;
|
|
456
|
+
output_tokens: number;
|
|
457
|
+
cost_usd: number;
|
|
458
|
+
};
|
|
459
|
+
};
|
|
460
|
+
type PartnerContactEraseByIdentityBody = {
|
|
461
|
+
phone?: string | undefined;
|
|
462
|
+
email?: string | undefined;
|
|
463
|
+
ref?: string | undefined;
|
|
464
|
+
};
|
|
465
|
+
type PartnerContactEraseByIdentityResult = {
|
|
466
|
+
erased: number;
|
|
467
|
+
contact_ids: string[];
|
|
468
|
+
skipped_linked_elsewhere: number;
|
|
469
|
+
};
|
|
388
470
|
type LeadCreate = {
|
|
389
471
|
status?: string | undefined;
|
|
390
472
|
assigned_to?: (string | undefined) | null;
|
|
@@ -1009,4 +1091,4 @@ interface ListEnvelope<T> {
|
|
|
1009
1091
|
pageSize: number;
|
|
1010
1092
|
}
|
|
1011
1093
|
|
|
1012
|
-
export type { ContactRefUpsertResult as A, LeadCapture as B, ContactQuery as C, LeadNote as D, LeadNoteCreate as E,
|
|
1094
|
+
export type { ContactRefUpsertResult as A, LeadCapture as B, ContactQuery as C, LeadNote as D, LeadNoteCreate as E, PartnerContactEraseByIdentityBody as F, PartnerContactEraseByIdentityResult as G, PartnerContactEraseResult as H, PartnerWorkspaceCreated as I, PartnerWorkspaceDetail as J, PartnerWorkspaceExisting as K, LeadQuery as L, MessageQuery as M, PartnerWorkspacePatchBody as N, PartnerWorkspaceSecret as O, ProductQuery as P, PartnerWorkspaceStatus as Q, PartnerWorkspaceUpsertBody as R, PartnerWorkspaceUsage as S, TaskQuery as T, PartnerWorkspaceUsageQuery as U, TagList as V, ContactList as a, Contact as b, ContactCreate as c, ContactUpdate as d, ListEnvelope as e, Lead as f, LeadCreate as g, LeadUpdate as h, Task as i, LegacyTaskUpdate as j, LegacyTask as k, Product as l, ProductCreate as m, ProductUpdate as n, ConversationQuery as o, Conversation as p, ConversationUpdate as q, Message as r, MessageCreate as s, TagQuery as t, TagWithUsage as u, TagCreate as v, Tag as w, ContactChanges as x, ContactChangesQuery as y, ContactRefUpsertBody as z };
|
|
@@ -126,6 +126,7 @@ type Contact = {
|
|
|
126
126
|
whatsapp_consent?: ("opted_in" | "opted_out" | "unknown") | undefined;
|
|
127
127
|
whatsapp_consent_source?: (string | undefined) | null;
|
|
128
128
|
whatsapp_consent_at?: (string | undefined) | null;
|
|
129
|
+
product_synced?: boolean | undefined;
|
|
129
130
|
metadata?: {
|
|
130
131
|
[x: string]: unknown;
|
|
131
132
|
} | undefined;
|
|
@@ -193,6 +194,7 @@ type ContactList = {
|
|
|
193
194
|
whatsapp_consent?: ("opted_in" | "opted_out" | "unknown") | undefined;
|
|
194
195
|
whatsapp_consent_source?: (string | undefined) | null;
|
|
195
196
|
whatsapp_consent_at?: (string | undefined) | null;
|
|
197
|
+
product_synced?: boolean | undefined;
|
|
196
198
|
metadata?: {
|
|
197
199
|
[x: string]: unknown;
|
|
198
200
|
} | undefined;
|
|
@@ -281,6 +283,7 @@ type ContactRefUpsertResult = {
|
|
|
281
283
|
whatsapp_consent?: ("opted_in" | "opted_out" | "unknown") | undefined;
|
|
282
284
|
whatsapp_consent_source?: (string | undefined) | null;
|
|
283
285
|
whatsapp_consent_at?: (string | undefined) | null;
|
|
286
|
+
product_synced?: boolean | undefined;
|
|
284
287
|
metadata?: {
|
|
285
288
|
[x: string]: unknown;
|
|
286
289
|
} | undefined;
|
|
@@ -343,16 +346,21 @@ type ContactChanges = {
|
|
|
343
346
|
};
|
|
344
347
|
type PartnerWorkspaceUpsertBody = {
|
|
345
348
|
name: string;
|
|
349
|
+
ai_monthly_cap_credits?: (number | null) | undefined;
|
|
350
|
+
currency?: string | undefined;
|
|
351
|
+
timezone?: string | undefined;
|
|
346
352
|
};
|
|
347
353
|
type PartnerWorkspacePatchBody = {
|
|
348
354
|
enabled?: boolean | undefined;
|
|
349
355
|
name?: string | undefined;
|
|
356
|
+
ai_monthly_cap_credits?: (number | null) | undefined;
|
|
350
357
|
};
|
|
351
358
|
type PartnerWorkspaceCreated = {
|
|
352
359
|
external_ref: string;
|
|
353
360
|
workspace_id: string | null;
|
|
354
361
|
embed_app_id: string | null;
|
|
355
362
|
enabled: boolean;
|
|
363
|
+
ai_monthly_cap_credits: number | null;
|
|
356
364
|
embed_app_secret: string;
|
|
357
365
|
created: true;
|
|
358
366
|
};
|
|
@@ -361,6 +369,7 @@ type PartnerWorkspaceExisting = {
|
|
|
361
369
|
workspace_id: string | null;
|
|
362
370
|
embed_app_id: string | null;
|
|
363
371
|
enabled: boolean;
|
|
372
|
+
ai_monthly_cap_credits: number | null;
|
|
364
373
|
created: false;
|
|
365
374
|
};
|
|
366
375
|
type PartnerWorkspaceStatus = {
|
|
@@ -368,13 +377,19 @@ type PartnerWorkspaceStatus = {
|
|
|
368
377
|
workspace_id: string | null;
|
|
369
378
|
embed_app_id: string | null;
|
|
370
379
|
enabled: boolean;
|
|
380
|
+
ai_monthly_cap_credits: number | null;
|
|
371
381
|
};
|
|
372
382
|
type PartnerWorkspaceDetail = {
|
|
373
383
|
external_ref: string;
|
|
374
384
|
workspace_id: string | null;
|
|
375
385
|
embed_app_id: string | null;
|
|
376
386
|
enabled: boolean;
|
|
387
|
+
ai_monthly_cap_credits: number | null;
|
|
377
388
|
state: "pending" | "owner_created" | "workspace_created" | "app_installed" | "sub_app_created" | "active";
|
|
389
|
+
ai: {
|
|
390
|
+
period: string;
|
|
391
|
+
used_credits: number;
|
|
392
|
+
} | null;
|
|
378
393
|
};
|
|
379
394
|
type PartnerWorkspaceSecret = {
|
|
380
395
|
embed_app_id: string;
|
|
@@ -385,6 +400,73 @@ type PartnerContactEraseResult = {
|
|
|
385
400
|
contact_id: string;
|
|
386
401
|
other_sources_removed: number;
|
|
387
402
|
};
|
|
403
|
+
type PartnerWorkspaceUsageQuery = {
|
|
404
|
+
from: string;
|
|
405
|
+
to: string;
|
|
406
|
+
};
|
|
407
|
+
type PartnerWorkspaceUsage = {
|
|
408
|
+
external_ref: string;
|
|
409
|
+
workspace_id: string;
|
|
410
|
+
from: string;
|
|
411
|
+
to: string;
|
|
412
|
+
timezone: "UTC";
|
|
413
|
+
cap: {
|
|
414
|
+
ai_monthly_cap_credits: number | null;
|
|
415
|
+
period: string;
|
|
416
|
+
used_credits: number;
|
|
417
|
+
remaining_credits: number | null;
|
|
418
|
+
};
|
|
419
|
+
totals: {
|
|
420
|
+
credits: number;
|
|
421
|
+
cost_usd: number;
|
|
422
|
+
input_tokens: number;
|
|
423
|
+
output_tokens: number;
|
|
424
|
+
events: number;
|
|
425
|
+
blocked_count: number;
|
|
426
|
+
};
|
|
427
|
+
by_operation: {
|
|
428
|
+
credits: number;
|
|
429
|
+
cost_usd: number;
|
|
430
|
+
input_tokens: number;
|
|
431
|
+
output_tokens: number;
|
|
432
|
+
events: number;
|
|
433
|
+
blocked_count: number;
|
|
434
|
+
operation: string;
|
|
435
|
+
}[];
|
|
436
|
+
by_model: {
|
|
437
|
+
credits: number;
|
|
438
|
+
cost_usd: number;
|
|
439
|
+
input_tokens: number;
|
|
440
|
+
output_tokens: number;
|
|
441
|
+
events: number;
|
|
442
|
+
blocked_count: number;
|
|
443
|
+
model: string;
|
|
444
|
+
}[];
|
|
445
|
+
by_day: {
|
|
446
|
+
credits: number;
|
|
447
|
+
cost_usd: number;
|
|
448
|
+
input_tokens: number;
|
|
449
|
+
output_tokens: number;
|
|
450
|
+
events: number;
|
|
451
|
+
blocked_count: number;
|
|
452
|
+
day: string;
|
|
453
|
+
}[];
|
|
454
|
+
assistant: {
|
|
455
|
+
input_tokens: number;
|
|
456
|
+
output_tokens: number;
|
|
457
|
+
cost_usd: number;
|
|
458
|
+
};
|
|
459
|
+
};
|
|
460
|
+
type PartnerContactEraseByIdentityBody = {
|
|
461
|
+
phone?: string | undefined;
|
|
462
|
+
email?: string | undefined;
|
|
463
|
+
ref?: string | undefined;
|
|
464
|
+
};
|
|
465
|
+
type PartnerContactEraseByIdentityResult = {
|
|
466
|
+
erased: number;
|
|
467
|
+
contact_ids: string[];
|
|
468
|
+
skipped_linked_elsewhere: number;
|
|
469
|
+
};
|
|
388
470
|
type LeadCreate = {
|
|
389
471
|
status?: string | undefined;
|
|
390
472
|
assigned_to?: (string | undefined) | null;
|
|
@@ -1009,4 +1091,4 @@ interface ListEnvelope<T> {
|
|
|
1009
1091
|
pageSize: number;
|
|
1010
1092
|
}
|
|
1011
1093
|
|
|
1012
|
-
export type { ContactRefUpsertResult as A, LeadCapture as B, ContactQuery as C, LeadNote as D, LeadNoteCreate as E,
|
|
1094
|
+
export type { ContactRefUpsertResult as A, LeadCapture as B, ContactQuery as C, LeadNote as D, LeadNoteCreate as E, PartnerContactEraseByIdentityBody as F, PartnerContactEraseByIdentityResult as G, PartnerContactEraseResult as H, PartnerWorkspaceCreated as I, PartnerWorkspaceDetail as J, PartnerWorkspaceExisting as K, LeadQuery as L, MessageQuery as M, PartnerWorkspacePatchBody as N, PartnerWorkspaceSecret as O, ProductQuery as P, PartnerWorkspaceStatus as Q, PartnerWorkspaceUpsertBody as R, PartnerWorkspaceUsage as S, TaskQuery as T, PartnerWorkspaceUsageQuery as U, TagList as V, ContactList as a, Contact as b, ContactCreate as c, ContactUpdate as d, ListEnvelope as e, Lead as f, LeadCreate as g, LeadUpdate as h, Task as i, LegacyTaskUpdate as j, LegacyTask as k, Product as l, ProductCreate as m, ProductUpdate as n, ConversationQuery as o, Conversation as p, ConversationUpdate as q, Message as r, MessageCreate as s, TagQuery as t, TagWithUsage as u, TagCreate as v, Tag as w, ContactChanges as x, ContactChangesQuery as y, ContactRefUpsertBody as z };
|
package/dist/embed-host.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var w=(e,n)=>{for(var r in n)m(e,r,{get:n[r],enumerable:!0})},R=(e,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of M(n))!v.call(e,t)&&t!==r&&m(e,t,{get:()=>n[t],enumerable:!(o=H(n,t))||o.enumerable});return e};var k=e=>R(m({},"__esModule",{value:!0}),e);var L={};w(L,{buildCrmEmbedUrl:()=>P,createCrmEmbedHost:()=>I,crmSession:()=>_,encodeHostBrand:()=>p,hostContextQuery:()=>B,normalizeHostBrand:()=>u,normalizeHostContext:()=>l});module.exports=k(L);var E=["light","dark","system"],A=/^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8}){0,3}$/,T=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,F=/^(\d{1,2}(?:\.\d{1,2})?)px$/,$=/^[A-Za-z0-9 ,'"_-]+$/;var O=["accent","accentForeground","background","surface","border","foreground","mutedForeground"];function h(e){if(typeof e!="string")return;let n=e.trim();if(!(!n||n.length>160||!$.test(n))&&!((n.match(/"/g)?.length??0)%2!==0||(n.match(/'/g)?.length??0)%2!==0))return n}function u(e){if(!e||typeof e!="object"||Array.isArray(e))return;let n={};for(let t of O){let a=e[t];if(typeof a=="string"&&T.test(a.trim())){let c=a.trim().toLowerCase();c.length===4&&(c=`#${c[1]}${c[1]}${c[2]}${c[2]}${c[3]}${c[3]}`),n[t]=c}}if(typeof e.radius=="string"){let t=F.exec(e.radius.trim());t&&Number(t[1])<=24&&(n.radius=`${Number(t[1])}px`)}let r=h(e.fontFamily);r&&(n.fontFamily=r);let o=h(e.displayFontFamily);return o&&(n.displayFontFamily=o),Object.keys(n).length>0?n:void 0}function p(e){let n=u(e);if(!n)return null;let r=new TextEncoder().encode(JSON.stringify(n)),o="";r.forEach(a=>{o+=String.fromCharCode(a)});let t=btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");return t.length<=1500?t:null}function l(e){let n={};if(e?.brand===null)n.brand=null;else{let r=u(e?.brand);r&&(n.brand=r)}return e?.theme&&E.includes(e.theme)&&(n.theme=e.theme),typeof e?.locale=="string"&&A.test(e.locale.trim())&&(n.locale=e.locale.trim()),n}function B(e){let n=l(e),r=[];n.theme&&r.push(`theme=${encodeURIComponent(n.theme)}`),n.locale&&r.push(`locale=${encodeURIComponent(n.locale)}`);let o=n.brand?p(n.brand):null;return o&&r.push(`brand=${o}`),r}function S(e){return!!e&&typeof e=="object"&&e.source==="crm-embed"&&e.type==="ready"}function _(e,n){return async()=>{let r=await fetch(e,{method:"POST",...n}),o=await r.json().catch(()=>({}));if(!r.ok){let a=o?.error;throw new Error(a?`CRM session failed: ${a}`:`CRM session failed (HTTP ${r.status})`)}let t=o;if(typeof t?.accessToken!="string"||typeof t?.workspaceId!="string")throw new Error("CRM session response is missing accessToken/workspaceId");return t}}function P(e,n){return`${e.replace(/\/$/,"")}/embed/${encodeURIComponent(n)}`}function I(e){let n=e.windowTarget??window,r=e.createChannel??(()=>new MessageChannel),o=e.devAllowAnyOrigin?"*":e.crmOrigin,t=null,a="",c=!1,d=l(e.hostContext);function g(s){if(s){t?.postMessage({type:"crm:host-context",...d,...s});return}if(!t||d.theme===void 0&&d.locale===void 0&&d.brand===void 0)return;let i={type:"crm:host-context",...d};t.postMessage(i)}async function f(){try{let s=await e.getBearer();return t?.postMessage({type:"auth-tokens",accessToken:s.accessToken,refreshToken:s.refreshToken??""}),g(),!0}catch(s){return e.onError?.(s),!1}}function y(s){let i=s.data;if(i)if(i.type==="channel-ack"){if(i.nonce!==a)return;f()}else i.type==="route-change"?e.onRouteChange?.(i.path):i.type==="resize"?e.onResize?.(i.height):i.type==="session-expired"&&f().then(b=>{b&&t?.postMessage({type:"session-refreshed"})})}function x(){t?.close();let s=r();t=s.port1,a=globalThis.crypto?.randomUUID?.()??`n-${String(Math.random()).slice(2)}`,t.onmessage=y,t.start?.(),e.iframe.contentWindow?.postMessage({type:"channel-init",nonce:a},o,[s.port2])}function C(s){c||s.source===e.iframe.contentWindow&&(!e.devAllowAnyOrigin&&s.origin!==e.crmOrigin||S(s.data)&&x())}return n.addEventListener("message",C),{navigate(s){t?.postMessage({type:"navigate",path:s})},setContext(s){let i=l(s);d={...d,...i},i.brand===null&&delete d.brand,g(i.brand===null?{brand:null}:void 0)},dispose(){c=!0,n.removeEventListener("message",C),t?.close(),t=null}}}0&&(module.exports={buildCrmEmbedUrl,createCrmEmbedHost,crmSession,encodeHostBrand,hostContextQuery,normalizeHostBrand,normalizeHostContext});
|
|
2
2
|
//# sourceMappingURL=embed-host.cjs.map
|