@dugjason/front-node 0.1.0 → 0.2.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 (47) hide show
  1. package/{LICENSE.md → LICENSE} +2 -2
  2. package/README.md +40 -297
  3. package/dist/index.cjs +2 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +11907 -0
  6. package/dist/index.d.cts.map +1 -0
  7. package/dist/index.d.mts +11907 -0
  8. package/dist/index.d.mts.map +1 -0
  9. package/dist/index.mjs +2 -0
  10. package/dist/index.mjs.map +1 -0
  11. package/package.json +67 -32
  12. package/dist/src/client.d.ts +0 -48
  13. package/dist/src/client.d.ts.map +0 -1
  14. package/dist/src/client.js +0 -218
  15. package/dist/src/client.js.map +0 -1
  16. package/dist/src/front.d.ts +0 -29
  17. package/dist/src/front.d.ts.map +0 -1
  18. package/dist/src/front.js +0 -44
  19. package/dist/src/front.js.map +0 -1
  20. package/dist/src/index.d.ts +0 -8
  21. package/dist/src/index.d.ts.map +0 -1
  22. package/dist/src/index.js +0 -10
  23. package/dist/src/index.js.map +0 -1
  24. package/dist/src/oauth.d.ts +0 -28
  25. package/dist/src/oauth.d.ts.map +0 -1
  26. package/dist/src/oauth.js +0 -82
  27. package/dist/src/oauth.js.map +0 -1
  28. package/dist/src/resources/accounts.d.ts +0 -39
  29. package/dist/src/resources/accounts.d.ts.map +0 -1
  30. package/dist/src/resources/accounts.js +0 -57
  31. package/dist/src/resources/accounts.js.map +0 -1
  32. package/dist/src/resources/conversations.d.ts +0 -41
  33. package/dist/src/resources/conversations.d.ts.map +0 -1
  34. package/dist/src/resources/conversations.js +0 -55
  35. package/dist/src/resources/conversations.js.map +0 -1
  36. package/dist/src/resources/teammates.d.ts +0 -29
  37. package/dist/src/resources/teammates.d.ts.map +0 -1
  38. package/dist/src/resources/teammates.js +0 -37
  39. package/dist/src/resources/teammates.js.map +0 -1
  40. package/dist/src/types.d.ts +0 -147
  41. package/dist/src/types.d.ts.map +0 -1
  42. package/dist/src/types.js +0 -2
  43. package/dist/src/types.js.map +0 -1
  44. package/dist/tests/client.test.d.ts +0 -2
  45. package/dist/tests/client.test.d.ts.map +0 -1
  46. package/dist/tests/client.test.js +0 -226
  47. package/dist/tests/client.test.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 J.Dugdale
3
+ Copyright (c) 2026 Jason Dugdale
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,323 +1,66 @@
1
- # Front Node.js SDK
1
+ # front-node
2
2
 
3
- A modern TypeScript SDK for the [Front.com API](https://dev.frontapp.com/reference/introduction). This SDK provides a clean, intuitive interface for interacting with Front's customer operations platform.
3
+ A modern TypeScript SDK for the [Front](https://front.com) API.
4
4
 
5
- ## Installation
5
+ ## Install
6
6
 
7
7
  ```bash
8
- npm install front-node
9
- # or
10
- pnpm install front-node
11
- # or
12
- yarn add front-node
8
+ npm install @dugjason/front-node
13
9
  ```
14
10
 
15
- ## Quick Start
11
+ ## Usage
16
12
 
17
- ```typescript
18
- import { Front } from 'front-node';
13
+ ```ts
14
+ import { Front } from "@dugjason/front-node";
19
15
 
20
- // Initialize with API key (required)
21
- const front = new Front({
22
- apiKey: process.env.FRONT_API_KEY || 'your-api-key'
23
- });
24
-
25
- // Fetch a conversation
26
- const conversation = await front.conversations.fetch('cnv_55c8c149');
16
+ const front = new Front({ apiKey: process.env.FRONT_API_TOKEN });
27
17
 
28
- // List teammates
29
18
  const teammates = await front.teammates.list();
30
19
 
31
- // Update a teammate
32
- await front.teammates.update(teammates._results[0].id, {
33
- is_available: true
34
- });
35
- ```
36
-
37
- ## Authentication
38
-
39
- The SDK supports two authentication methods:
40
-
41
- ### 1. OAuth (Recommended for Production)
42
-
43
- OAuth provides automatic token refresh and is required for public integrations:
44
-
45
- ```typescript
46
- const front = new Front({
47
- oauth: {
48
- clientId: 'your-oauth-client-id',
49
- clientSecret: 'your-oauth-client-secret',
50
- accessToken: 'your-current-access-token',
51
- refreshToken: 'your-refresh-token',
52
-
53
- // Optional: Called when tokens are refreshed
54
- onTokenRefresh: async (tokens) => {
55
- // Save new tokens to your database
56
- await saveTokensToDatabase(tokens);
57
- }
58
- }
59
- });
60
- ```
61
-
62
- The SDK automatically refreshes tokens when they expire (every hour) and calls your `onTokenRefresh` callback with the new tokens.
63
-
64
- ### 2. API Key (Simple Setup)
65
-
66
- For testing or single-instance usage:
67
-
68
- ```typescript
69
- // Using environment variable (recommended)
70
- const front = new Front({
71
- apiKey: process.env.FRONT_API_KEY || 'your-api-key'
20
+ // ID-scoped operations do not require fetching the resource first.
21
+ await front.channels.createMessage("cha_123", {
22
+ body: "Hello from Front",
23
+ options: { archive: true },
24
+ to: ["customer@example.com"],
72
25
  });
73
-
74
- // Or provide directly
75
- const front = new Front({ apiKey: 'your-api-key' });
26
+ await front.conversations.addTag("cnv_123", { tag_ids: ["tag_123"] });
27
+ await front.messages.markSeen("msg_123");
76
28
  ```
77
29
 
78
- ## API Reference
79
-
80
- ### Conversations
81
-
82
- ```typescript
83
- // List conversations
84
- const conversations = await front.conversations.list({
85
- limit: 50,
86
- q: 'status:unassigned'
87
- });
88
-
89
- // Fetch a specific conversation
90
- const conversation = await front.conversations.fetch('cnv_123');
91
-
92
- // Update a conversation
93
- await front.conversations.update('cnv_123', {
94
- status: 'archived'
95
- });
96
-
97
- // Get conversation messages
98
- const messages = await front.conversations.getMessages('cnv_123');
99
-
100
- // Get conversation events
101
- const events = await front.conversations.getEvents('cnv_123');
102
- ```
103
-
104
- ### Teammates
105
-
106
- ```typescript
107
- // List all teammates
108
- const teammates = await front.teammates.list();
109
-
110
- // Fetch a specific teammate
111
- const teammate = await front.teammates.fetch('tea_123');
112
-
113
- // Update a teammate
114
- await front.teammates.update('tea_123', {
115
- first_name: 'John',
116
- last_name: 'Doe',
117
- is_available: true
118
- });
119
-
120
- // Get teammate's inboxes
121
- const inboxes = await front.teammates.getInboxes('tea_123');
122
-
123
- // Get teammate's conversations
124
- const conversations = await front.teammates.getConversations('tea_123', {
125
- limit: 10
126
- });
127
- ```
128
-
129
- ## OAuth Token Management
130
-
131
- When using OAuth, the SDK provides several utilities for token management:
132
-
133
- ```typescript
134
- // Check if using OAuth
135
- const isOAuth = front.isUsingOAuth();
136
-
137
- // Get OAuth manager for advanced operations
138
- const oauthManager = front.getOAuthManager();
139
- if (oauthManager) {
140
- // Force token refresh
141
- const newToken = oauthManager.getAccessToken();
142
- }
30
+ ## Development
143
31
 
144
- // Update OAuth configuration (e.g., after manual token refresh)
145
- front.updateOAuthConfig({
146
- accessToken: 'new-access-token',
147
- refreshToken: 'new-refresh-token',
148
- });
149
- ```
150
-
151
- ### Token Refresh Callback
152
-
153
- The `onTokenRefresh` callback is crucial for OAuth implementations - it allows the SDK to notify your application when tokens are automatically refreshed, so you can save the updated tokens to your database or storage system.
154
-
155
- **Example with database storage:**
156
- ```typescript
157
- // Function to save tokens to your database
158
- async function saveTokensToDatabase(userId: string, tokens: OAuthTokens) {
159
- await db.users.update(userId, {
160
- frontAccessToken: tokens.access_token,
161
- frontRefreshToken: tokens.refresh_token,
162
- updatedAt: new Date()
163
- });
164
- }
165
-
166
- const front = new Front({
167
- oauth: {
168
- clientId: 'your-client-id',
169
- clientSecret: 'your-client-secret',
170
- accessToken: 'current-access-token',
171
- refreshToken: 'current-refresh-token',
172
-
173
- // SDK calls this whenever tokens are refreshed
174
- onTokenRefresh: async (tokens) => {
175
- console.log('Front SDK refreshed tokens, saving to database...');
176
- await saveTokensToDatabase(currentUserId, tokens);
177
- console.log('Tokens saved successfully');
178
- }
179
- }
180
- });
181
-
182
- // When any API call triggers a token refresh, your callback will be called
183
- const conversations = await front.conversations.list(); // May trigger refresh + callback
184
- ```
185
-
186
- ### Concurrent Token Refresh Protection
187
-
188
- The SDK uses an internal `refreshPromise` mechanism to prevent multiple simultaneous token refresh attempts. This ensures that if multiple API calls happen simultaneously when a token is expired, only one refresh request is made to the OAuth server, and your `onTokenRefresh` callback is only called once.
189
-
190
- **How it works:**
191
- - When the first API call detects an expired token, it starts the refresh process
192
- - Any subsequent API calls that also detect the expired token will wait for the same refresh promise to complete
193
- - Once the refresh is complete, `onTokenRefresh` is called once with the new tokens
194
- - All waiting calls then proceed with the refreshed token
195
-
196
- **Practical Example:**
197
- ```typescript
198
- let refreshCount = 0;
199
-
200
- const front = new Front({
201
- oauth: {
202
- clientId: 'your-client-id',
203
- clientSecret: 'your-client-secret',
204
- accessToken: 'expired-token',
205
- refreshToken: 'your-refresh-token',
206
- onTokenRefresh: async (tokens) => {
207
- refreshCount++;
208
- console.log(`Token refresh #${refreshCount}:`, tokens);
209
- await saveTokensToDatabase(currentUserId, tokens);
210
- }
211
- }
212
- });
213
-
214
- // These calls happen simultaneously when token is expired
215
- // Only ONE refresh request will be made, callback called once
216
- const [conversations, teammates, accounts] = await Promise.all([
217
- front.conversations.list(), // Triggers token refresh
218
- front.teammates.list(), // Waits for existing refresh
219
- front.accounts.list() // Waits for existing refresh
220
- ]);
221
-
222
- console.log(`Refresh count: ${refreshCount}`); // Will be 1, not 3
223
- ```
224
-
225
- This prevents rate limiting issues with the OAuth provider and ensures your database isn't hit with duplicate token updates.
226
-
227
- ## Configuration
228
-
229
- ```typescript
230
- const front = new Front({
231
- apiKey: 'your-api-key', // For API key auth
232
- baseUrl: 'https://api2.frontapp.com', // optional, defaults to Front's API
233
- oauth: { // For OAuth auth
234
- clientId: 'your-client-id',
235
- clientSecret: 'your-client-secret',
236
- accessToken: 'current-access-token',
237
- refreshToken: 'current-refresh-token',
238
- onTokenRefresh: async (tokens) => { /* save tokens */ }
239
- }
240
- });
32
+ ```bash
33
+ bun install
34
+ bun test
35
+ bun run check
241
36
  ```
242
37
 
243
- ## Error Handling
38
+ ## Release
244
39
 
245
- The SDK throws structured errors with helpful information:
40
+ Releases are managed by Changesets. Add a changeset for user-facing changes:
246
41
 
247
- ```typescript
248
- try {
249
- const conversation = await front.conversations.fetch('invalid-id');
250
- } catch (error) {
251
- console.error('Status:', error.status);
252
- console.error('Message:', error.message);
253
- console.error('Code:', error.code);
254
- }
42
+ ```bash
43
+ bun run changeset
255
44
  ```
256
45
 
257
- ## TypeScript Support
46
+ Merging to `main` opens or updates a version PR. Merging that version PR publishes
47
+ to npm as `@dugjason/front-node` through npm trusted publishing.
258
48
 
259
- The SDK is built with TypeScript and provides full type definitions:
49
+ ## Custom `fetch`
260
50
 
261
- ```typescript
262
- import { Front, Conversation, Teammate } from 'front-node';
51
+ You can use the library with a custom fetch library, compatible with `node:fetch`.
52
+ An illustrative example could be a fetch implementation with built-in tracing or custom telemetry;
263
53
 
264
- const front = new Front({ apiKey: 'your-api-key' });
54
+ ```ts
55
+ import { Front } from "@dugjason/front-node";
265
56
 
266
- // Full type safety
267
- const conversation: Conversation = await front.conversations.fetch('cnv_123');
268
- const teammates: Teammate[] = (await front.teammates.list())._results;
57
+ const loggingFetch: typeof fetch = async (input, init) => {
58
+ const t0 = performance.now();
59
+ const response = await globalThis.fetch(input, init);
60
+ console.log(
61
+ `${init?.method ?? "GET"} ${input} ${response.status} ${Math.round(performance.now() - t0)}ms`,
62
+ );
63
+ return response;
64
+ };
65
+ const front = new Front({ fetch: loggingFetch });
269
66
  ```
270
-
271
- ## Releases
272
-
273
- This package uses automated publishing with manual version management. When changes are merged to the main branch, the current version in `package.json` is automatically published to npm.
274
-
275
- ### Release Process
276
-
277
- 1. **Version Management**: Version bumps are handled manually using semantic versioning:
278
- - **Patch** (`1.0.0` → `1.0.1`): Bug fixes, documentation updates, refactoring
279
- - **Minor** (`1.0.0` → `1.1.0`): New features, enhancements
280
- - **Major** (`1.0.0` → `2.0.0`): Breaking changes
281
-
282
- 2. **How to Release**:
283
- ```bash
284
- # Bump version using pnpm (recommended)
285
- pnpm version patch # for bug fixes
286
- pnpm version minor # for new features
287
- pnpm version major # for breaking changes
288
-
289
- # Or manually edit package.json and create a git tag
290
- git tag v1.2.3
291
-
292
- # Push changes and tags
293
- git push origin main --tags
294
- ```
295
-
296
- 3. **What Happens on Push to Main**:
297
- - Tests run on Node.js 20 and 22
298
- - Code is linted with Biome
299
- - TypeScript compilation is verified
300
- - Package is published to npm using the current `package.json` version
301
- - GitHub release is created with the current version tag
302
-
303
- ### Development Workflow
304
-
305
- 1. Create feature branch from `main`
306
- 2. Make changes and commit
307
- 3. Open Pull Request
308
- 4. After review and merge to `main`:
309
- - If you want to publish: bump version first, then merge
310
- - If not ready to publish: merge without version bump
311
-
312
- ## Requirements
313
-
314
- - Node.js 18.0.0 or higher (for native fetch support)
315
- - TypeScript 5.0+ (if using TypeScript)
316
-
317
- ## License
318
-
319
- ISC
320
-
321
- ## Contributing
322
-
323
- Contributions are welcome! Please feel free to submit a Pull Request.
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`@dugjason/front-node`,t=`0.2.0`,n=class extends Error{status;headers;response;body;constructor(e,t){super(`Front API error: ${e.status} ${e.statusText}`),this.name=`FrontApiError`,this.status=e.status,this.headers=e.headers,this.response=e,this.body=t}};const r=e=>{if(!e)return null;try{let t=new URL(e).searchParams.get(`page_token`);if(t!==null&&t!==``)return t}catch{return null}return null},i=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return e;let t=e,n={};for(let[e,i]of Object.entries(t)){if(e===`_pagination`){if(typeof i==`object`&&i&&!Array.isArray(i)){let e=i,t=e.next,a=typeof t==`string`?r(t):t;n.pagination={...e,next:a}}continue}n[e]=i}return n},a=`${e}@${t}`,o=/\/$/u,s=(e,t)=>`${e.replace(o,``)}${t.startsWith(`/`)?t:`/${t}`}`,c=(e,t)=>{if(!t)return e;let n=new URLSearchParams;for(let[e,r]of Object.entries(t))r!==void 0&&n.set(e,r);let r=n.toString();return r.length>0?`${e}?${r}`:e};var l=class{apiKey;baseUrl;fetchImpl;userAgent;constructor(e){this.apiKey=e.apiKey,this.baseUrl=e.baseUrl??`https://api2.frontapp.com`,this.fetchImpl=e.fetch??globalThis.fetch.bind(globalThis),this.userAgent=e.userAgent??a}buildUrl(e,t){return c(s(this.baseUrl,e),t)}static expandPath(e,t){let n=e;for(let[e,r]of Object.entries(t))n=n.replace(`{${e}}`,encodeURIComponent(r));if(n.includes(`{`))throw Error(`Unresolved path template: ${e} → ${n}`);return n}async requestJson(e,t,r){let a=this.buildUrl(t,r?.query),o=new Headers({Accept:`application/json`,Authorization:`Bearer ${this.apiKey}`,"User-Agent":this.userAgent});r?.body!==void 0&&o.set(`Content-Type`,`application/json`);let s=await this.fetchImpl(a,{body:r?.body===void 0?void 0:JSON.stringify(r.body),headers:o,method:e});if(!s.ok){let e,t=await s.text();try{e=JSON.parse(t)}catch{e=t}throw new n(s,e)}if(s.status===204)return;let c=await s.text();if(c.length===0)return;let l=JSON.parse(c);return i(l)}async requestWithoutParsingBody(e,t,r){let i=this.buildUrl(t,r?.query),a=new Headers({Accept:`*/*`,Authorization:`Bearer ${this.apiKey}`,"User-Agent":this.userAgent});if(r?.headers!==void 0)for(let[e,t]of Object.entries(r.headers))t!==void 0&&a.set(e,t);let o=await this.fetchImpl(i,{headers:a,method:e});if(!o.ok){let e,t=await o.text();try{e=JSON.parse(t)}catch{e=t}throw new n(o,e)}return o}},u=class{state;base;stateLoaded;resourceId;constructor(e,t,n){this.base=e,this.stateLoaded=t!==void 0,t!==void 0&&(this.state=structuredClone(t)),this.resourceId=n}get id(){let e=(this.stateLoaded?this.state.id:void 0)??this.resourceId;if(e===void 0)throw Error(`This resource operation requires an ID.`);return e}get links(){return this.requireState()._links}set links(e){this.assign(`_links`,e)}get data(){return this.requireState()}pick(e){return this.requireState()[e]}assign(e,t){this.state={...this.requireState(),[e]:t}}replaceState(e){this.state=structuredClone(e),this.stateLoaded=!0}hasState(){return this.stateLoaded}requireState(){if(!this.stateLoaded)throw Error(`This resource operation requires fetched resource data.`);return this.state}onAfterRefresh(){}async refresh(){let e=await this.base.requestJson(`GET`,this.selfPath());return this.replaceState(e),this.onAfterRefresh(),this}async delete(){await this.base.requestJson(`DELETE`,this.selfPath())}async patchNoContent(e,t){await this.base.requestJson(`PATCH`,this.selfPath(),{body:e}),this.stateLoaded&&(this.state=t(this.state,e))}async patchReplaceFromResponse(e){let t=await this.base.requestJson(`PATCH`,this.selfPath(),{body:e});this.replaceState(t)}async save(){await this.update(this.toUpdateBody())}};const d=e=>{if(!e)return;let t={};return e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},ee=e=>{if(!e)return;let t={};return e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},te=e=>({custom_fields:e.custom_fields,description:e.description??void 0,domains:e.domains,name:e.name});var f=class e extends u{selfPath(){return l.expandPath(`/accounts/{account_id}`,{account_id:this.id})}get name(){return this.pick(`name`)}set name(e){this.assign(`name`,e)}get description(){return this.pick(`description`)}set description(e){this.assign(`description`,e)}get domains(){return this.pick(`domains`)}set domains(e){this.assign(`domains`,e)}get customFields(){return this.pick(`custom_fields`)}set customFields(e){this.assign(`custom_fields`,e)}get logoUrl(){return this.pick(`logo_url`)}get externalId(){return this.pick(`external_id`)}get createdAt(){return this.pick(`created_at`)}get updatedAt(){return this.pick(`updated_at`)}toUpdateBody(){return te(this.state)}async update(e,t){if(typeof e==`string`){await this.target(e).update(t??{});return}await this.patchReplaceFromResponse(e)}async delete(e){if(e===void 0){await super.delete();return}await this.target(e).delete()}async listContacts(e,t){if(typeof e==`string`)return await this.target(e).listContacts(t);let n=l.expandPath(`/accounts/{account_id}/contacts`,{account_id:this.id});return await this.base.requestJson(`GET`,n,{query:ee(e)})}async addContacts(e,t){if(typeof e==`string`){await this.target(e).addContacts(t??{contact_ids:[]});return}let n=l.expandPath(`/accounts/{account_id}/contacts`,{account_id:this.id});await this.base.requestJson(`POST`,n,{body:e})}async removeContacts(e,t){if(typeof e==`string`){await this.target(e).removeContacts(t??{contact_ids:[]});return}let n=l.expandPath(`/accounts/{account_id}/contacts`,{account_id:this.id});await this.base.requestJson(`DELETE`,n,{body:e})}async list(e){return await this.base.requestJson(`GET`,`/accounts`,{query:d(e)})}async create(t){let n=await this.base.requestJson(`POST`,`/accounts`,{body:t});return new e(this.base,n)}async get(e){return await this.target(e).refresh()}target(t){return new e(this.base,void 0,t)}async listCustomFields(){return await this.base.requestJson(`GET`,`/accounts/custom_fields`)}},p=class{state;base;constructor(e,t){this.base=e,this.state=structuredClone(t)}get id(){return this.state.id}get links(){return this.state._links}get data(){return this.state}selfPath(){return l.expandPath(`/analytics/exports/{export_id}`,{export_id:this.id})}async refresh(){let e=await this.base.requestJson(`GET`,this.selfPath());return this.state=structuredClone(e),this}},m=class{state;base;constructor(e,t){this.base=e,this.state=structuredClone(t)}get uid(){return this.state.uid}get links(){return this.state._links}get data(){return this.state}selfPath(){return l.expandPath(`/analytics/reports/{report_uid}`,{report_uid:this.uid})}async refresh(){let e=await this.base.requestJson(`GET`,this.selfPath());return this.state=structuredClone(e),this}},h=class{base;constructor(e){this.base=e}async createExport(e){let t=await this.base.requestJson(`POST`,`/analytics/exports`,{body:e});return new p(this.base,t)}async getExport(e){let t=l.expandPath(`/analytics/exports/{export_id}`,{export_id:e}),n=await this.base.requestJson(`GET`,t);return new p(this.base,n)}async createReport(e){let t=await this.base.requestJson(`POST`,`/analytics/reports`,{body:e});return new m(this.base,t)}async getReport(e){let t=l.expandPath(`/analytics/reports/{report_uid}`,{report_uid:e}),n=await this.base.requestJson(`GET`,t);return new m(this.base,n)}},g=class{base;constructor(e){this.base=e}async triggerEvent(e,t){let n=l.expandPath(`/applications/{application_uid}/events`,{application_uid:e});await this.base.requestJson(`POST`,n,{body:t})}};const ne=(e,t)=>{let n=Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0)),r={...e};return n.name!==void 0&&(r={...r,name:n.name}),n.settings!==void 0&&(r={...r,settings:{...e.settings,...n.settings}}),r},re=e=>({name:e.name,settings:e.settings});var _=class e extends u{selfPath(){return l.expandPath(`/channels/{channel_id}`,{channel_id:this.id})}get name(){return this.pick(`name`)}set name(e){this.assign(`name`,e)}get settings(){return this.pick(`settings`)}set settings(e){this.assign(`settings`,e)}get type(){return this.pick(`type`)}get address(){return this.pick(`address`)}get sendAs(){return this.pick(`send_as`)}get isPrivate(){return this.pick(`is_private`)}get isValid(){return this.pick(`is_valid`)}delete(){return Promise.reject(Error(`Deleting channel ${this.id} is not supported by the Front REST API for this path.`))}toUpdateBody(){return re(this.state)}async update(e,t){let{body:n,id:r}=this.resolveIdAndBody(e,t),i=l.expandPath(`/channels/{channel_id}`,{channel_id:r});await this.base.requestJson(`PATCH`,i,{body:n}),this.hasState()&&r===this.id&&this.replaceState(ne(this.state,n))}async createDraft(e,t){let{body:n,id:r}=this.resolveIdAndBody(e,t),i=l.expandPath(`/channels/{channel_id}/drafts`,{channel_id:r});return await this.base.requestJson(`POST`,i,{body:n})}async receiveCustomMessage(e,t){let{body:n,id:r}=this.resolveIdAndBody(e,t),i=l.expandPath(`/channels/{channel_id}/incoming_messages`,{channel_id:r});return await this.base.requestJson(`POST`,i,{body:n})}async createMessage(e,t){let{body:n,id:r}=this.resolveIdAndBody(e,t),i=l.expandPath(`/channels/{channel_id}/messages`,{channel_id:r});return await this.base.requestJson(`POST`,i,{body:n})}async validate(e){let t=e??this.id,n=l.expandPath(`/channels/{channel_id}/validate`,{channel_id:t});return await this.base.requestJson(`POST`,n)}async list(){return await this.base.requestJson(`GET`,`/channels`)}async get(t){let n=l.expandPath(`/channels/{channel_id}`,{channel_id:t}),r=await this.base.requestJson(`GET`,n);return new e(this.base,r)}async create(e,t){let n=l.expandPath(`/inboxes/{inbox_id}/channels`,{inbox_id:e});await this.base.requestJson(`POST`,n,{body:t})}resolveIdAndBody(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`A request body is required.`);return{body:t,id:e}}return{body:e,id:this.id}}};const ie=e=>({body:e.body,is_pinned:e.is_pinned});var v=class e extends u{selfPath(){return l.expandPath(`/comments/{comment_id}`,{comment_id:this.id})}patchPath(){return l.expandPath(`/comments/{comment_id}/`,{comment_id:this.id})}get author(){return this.pick(`author`)}get body(){return this.pick(`body`)}set body(e){this.assign(`body`,e)}get isPinned(){return this.pick(`is_pinned`)}set isPinned(e){this.assign(`is_pinned`,e)}get postedAt(){return this.pick(`posted_at`)}get attachments(){return this.pick(`attachments`)}delete(e){return e===void 0?Promise.reject(Error(`Deleting comment ${this.id} is not supported by the Front REST API for this path.`)):this.target(e).delete()}toUpdateBody(){return ie(this.state)}async update(e,t){if(typeof e==`string`){await this.target(e).update(t??{});return}let n=await this.base.requestJson(`PATCH`,this.patchPath(),{body:e});this.replaceState(n)}async listMentions(e){if(e!==void 0)return await this.target(e).listMentions();let t=l.expandPath(`/comments/{comment_id}/mentions`,{comment_id:this.id});return await this.base.requestJson(`GET`,t)}async addReply(t,n){if(typeof t==`string`)return await this.target(t).addReply(n??{body:``});let r=l.expandPath(`/comments/{comment_id}/replies`,{comment_id:this.id}),i=await this.base.requestJson(`POST`,r,{body:t});return new e(this.base,i)}async downloadAttachment(e,t){if(t!==void 0)return await this.target(e).downloadAttachment(t);let n=l.expandPath(`/comments/{comment_id}/download/{attachment_link_id}`,{attachment_link_id:e,comment_id:this.id});return await this.base.requestWithoutParsingBody(`GET`,n)}async get(e){return await this.target(e).refresh()}target(t){return new e(this.base,void 0,t)}};const y=e=>{if(!e)return;let t={};return e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},b=e=>{if(!e)return;let t={};return e.q!==void 0&&(t.q=String(e.q)),e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),t},x=(e,t)=>{let{parent_tag_id:n,...r}=t,i=Object.fromEntries(Object.entries(r).filter(([,e])=>e!==void 0));return{...e,...i}},S=(e,t)=>{let n={description:e.description??void 0,highlight:e.highlight??void 0,is_visible_in_conversation_lists:e.is_visible_in_conversation_lists,name:e.name};return t!==void 0&&(n.parent_tag_id=t),n};var C=class e extends u{parentTagIdForUpdate;constructor(e,t,n){super(e,t,n),this.parentTagIdForUpdate=void 0}selfPath(){return l.expandPath(`/tags/{tag_id}`,{tag_id:this.id})}onAfterRefresh(){this.parentTagIdForUpdate=void 0}get name(){return this.pick(`name`)}set name(e){this.assign(`name`,e)}get description(){return this.pick(`description`)}set description(e){this.assign(`description`,e)}get highlight(){return this.pick(`highlight`)}set highlight(e){this.assign(`highlight`,e)}get isPrivate(){return this.pick(`is_private`)}get isVisibleInConversationLists(){return this.pick(`is_visible_in_conversation_lists`)}set isVisibleInConversationLists(e){this.assign(`is_visible_in_conversation_lists`,e)}get createdAt(){return this.pick(`created_at`)}get updatedAt(){return this.pick(`updated_at`)}get parentTagId(){return this.parentTagIdForUpdate}set parentTagId(e){this.parentTagIdForUpdate=e}toUpdateBody(){return S(this.state,this.parentTagIdForUpdate)}async update(e,t){if(typeof e==`string`){await this.target(e).update(t??{});return}await this.patchNoContent(e,x),`parent_tag_id`in e&&(this.parentTagIdForUpdate=e.parent_tag_id===null||e.parent_tag_id===void 0?void 0:e.parent_tag_id)}async delete(e){if(e===void 0){await super.delete();return}await this.target(e).delete()}async listChildren(t){if(t!==void 0)return await this.target(t).listChildren();let n=l.expandPath(`/tags/{tag_id}/children`,{tag_id:this.id});return((await this.base.requestJson(`GET`,n))._results??[]).map(t=>new e(this.base,t))}async createChild(t,n){if(typeof t==`string`){if(n===void 0)throw Error(`Creating a child tag requires a request body.`);return await this.target(t).createChild(n)}let r=l.expandPath(`/tags/{tag_id}/children`,{tag_id:this.id}),i=await this.base.requestJson(`POST`,r,{body:t});return new e(this.base,i)}async listTaggedConversations(e,t){if(typeof e==`string`)return await this.target(e).listTaggedConversations(t);let n=l.expandPath(`/tags/{tag_id}/conversations`,{tag_id:this.id});return await this.base.requestJson(`GET`,n,{query:b(e)})}async list(e){return await this.base.requestJson(`GET`,`/tags`,{query:y(e)})}async create(t){let n=await this.base.requestJson(`POST`,`/tags`,{body:t});return new e(this.base,n)}async get(e){return await this.target(e).refresh()}target(t){return new e(this.base,void 0,t)}};const ae=e=>{if(!e)return;let t={};return e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t};var w=class{base;constructor(e){this.base=e}async listRules(){return await this.base.requestJson(`GET`,`/company/rules`)}async listTicketStatuses(){return await this.base.requestJson(`GET`,`/company/statuses`)}async getTicketStatus(e){let t=l.expandPath(`/company/statuses/{status_id}`,{status_id:e});return await this.base.requestJson(`GET`,t)}async listTags(e){return await this.base.requestJson(`GET`,`/company/tags`,{query:ae(e)})}async createTag(e){let t=await this.base.requestJson(`POST`,`/company/tags`,{body:e});return new C(this.base,t)}};const oe=e=>{if(!e)return;let t={};return e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),t};var T=class{base;constructor(e){this.base=e}async list(){return await this.base.requestJson(`GET`,`/contact_lists`)}async create(e){await this.base.requestJson(`POST`,`/contact_lists`,{body:e})}async delete(e){let t=l.expandPath(`/contact_lists/{contact_list_id}`,{contact_list_id:e});await this.base.requestJson(`DELETE`,t)}async listContacts(e,t){let n=l.expandPath(`/contact_lists/{contact_list_id}/contacts`,{contact_list_id:e});return await this.base.requestJson(`GET`,n,{query:oe(t)})}async addContacts(e,t){let n=l.expandPath(`/contact_lists/{contact_list_id}/contacts`,{contact_list_id:e});await this.base.requestJson(`POST`,n,{body:t})}async removeContacts(e,t){let n=l.expandPath(`/contact_lists/{contact_list_id}/contacts`,{contact_list_id:e});await this.base.requestJson(`DELETE`,n,{body:t})}};const E=e=>{if(e.id===void 0||e.id===``)throw Error("Contact response missing `id`.");return{...e,_links:e._links!==void 0&&e._links!==null?{...e._links}:{},id:e.id}},se=e=>{if(!e)return;let t={};return e.q!==void 0&&(t.q=String(e.q)),e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},ce=e=>{if(!e)return;let t={};return e.q!==void 0&&(t.q=String(e.q)),e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),t},le=(e,t)=>{let n={...e};return t.name!==void 0&&(n={...n,name:t.name}),t.description!==void 0&&(n={...n,description:t.description}),t.links!==void 0&&(n={...n,links:t.links}),t.custom_fields!==void 0&&(n={...n,custom_fields:t.custom_fields}),n},ue=e=>({custom_fields:e.custom_fields,description:e.description,links:e.links,name:e.name});var D=class e extends u{constructor(e,t,n){super(e,t===void 0?void 0:E(t),n)}selfPath(){return l.expandPath(`/contacts/{contact_id}`,{contact_id:this.id})}get name(){return this.pick(`name`)}set name(e){this.assign(`name`,e)}get description(){return this.pick(`description`)}set description(e){this.assign(`description`,e)}get avatarUrl(){return this.pick(`avatar_url`)}get contactLinks(){return this.pick(`links`)}set contactLinks(e){this.assign(`links`,e)}get handles(){return this.pick(`handles`)}get customFields(){return this.pick(`custom_fields`)}set customFields(e){this.assign(`custom_fields`,e)}get lists(){return this.pick(`lists`)}get groups(){return this.pick(`groups`)}get isPrivate(){return this.pick(`is_private`)}toUpdateBody(){return ue(this.state)}async update(e,t){if(typeof e==`string`){await this.target(e).update(t??{});return}await this.patchNoContent(e,le)}async delete(e){if(e===void 0){await super.delete();return}await this.target(e).delete()}async refresh(){let e=await this.base.requestJson(`GET`,this.selfPath());return this.replaceState(E(e)),this.onAfterRefresh(),this}async listConversations(e,t){if(typeof e==`string`)return await this.target(e).listConversations(t);let n=l.expandPath(`/contacts/{contact_id}/conversations`,{contact_id:this.id});return await this.base.requestJson(`GET`,n,{query:ce(e)})}async addHandle(e,t){if(typeof e==`string`){await this.target(e).addHandle(t??{handle:``,source:`custom`});return}let n=l.expandPath(`/contacts/{contact_id}/handles`,{contact_id:this.id});await this.base.requestJson(`POST`,n,{body:e});let r=this.pick(`handles`)??[];this.assign(`handles`,[...r,e])}async deleteHandle(e,t){if(typeof e==`string`){await this.target(e).deleteHandle(t??{force:!1,handle:``,source:`custom`});return}let n=l.expandPath(`/contacts/{contact_id}/handles`,{contact_id:this.id});await this.base.requestJson(`DELETE`,n,{body:e});let r=this.pick(`handles`)??[];this.assign(`handles`,r.filter(t=>t.handle!==e.handle||t.source!==e.source))}async listNotes(e){if(e!==void 0)return await this.target(e).listNotes();let t=l.expandPath(`/contacts/{contact_id}/notes`,{contact_id:this.id});return await this.base.requestJson(`GET`,t)}async addNote(e,t){if(typeof e==`string`)return await this.target(e).addNote(t??{author_id:``,body:``});let n=l.expandPath(`/contacts/{contact_id}/notes`,{contact_id:this.id});return await this.base.requestJson(`POST`,n,{body:e})}async list(e){return await this.base.requestJson(`GET`,`/contacts`,{query:se(e)})}async create(t){let n=await this.base.requestJson(`POST`,`/contacts`,{body:t});return new e(this.base,n)}async listCustomFields(){return await this.base.requestJson(`GET`,`/contacts/custom_fields`)}async merge(t){let n=await this.base.requestJson(`POST`,`/contacts/merge`,{body:t});return new e(this.base,n)}async get(e){return await this.target(e).refresh()}target(t){return new e(this.base,void 0,t)}};const de=e=>{if(!e)return;let t={};return e.q!==void 0&&(t.q=String(e.q)),e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},fe=e=>{if(!e)return;let t={};return e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),t},pe=e=>{if(!e)return;let t={};return e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),t},me=e=>{if(!e)return;let t={};return e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},he=(e,t,n)=>{let r=l.expandPath(`/conversations/{conversation_id}/messages`,{conversation_id:t});return e.requestJson(`GET`,r,{query:me(n)})},ge=e=>{if(!e)return;let t={};return e.ignore_errors!==void 0&&(t.ignore_errors=e.ignore_errors?`true`:`false`),t},_e=e=>{switch(e){case`archived`:return`archived`;case`deleted`:return`deleted`;case`open`:return`unassigned`;case`spam`:return`deleted`;default:return e}},ve=e=>{if(e===`archived`)return`archived`;if(e===`deleted`)return`deleted`;if(e===`unassigned`)return`open`},ye=(e,t)=>{let n=Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0)),r={...e};if(n.status!==void 0&&(r={...r,status:_e(n.status)}),n.status_id!==void 0&&(r={...r,status_id:n.status_id}),n.custom_fields!==void 0&&(r={...r,custom_fields:n.custom_fields}),n.tag_ids!==void 0){let e=new Set(n.tag_ids);r={...r,tags:r.tags.filter(t=>e.has(t.id))}}let i=n.assignee_id;return i!==void 0&&(r={...r,assignee:{...r.assignee,id:i===null?``:i}}),r},O=e=>{let t=ve(e.status);return{assignee_id:e.assignee.id===``?void 0:e.assignee.id,custom_fields:e.custom_fields,tag_ids:e.tags.map(e=>e.id),...t===void 0?{}:{status:t},...e.status_id===void 0?{}:{status_id:e.status_id}}};var k=class e extends u{selfPath(){return l.expandPath(`/conversations/{conversation_id}`,{conversation_id:this.id})}get subject(){return this.pick(`subject`)}get status(){return this.pick(`status`)}get statusId(){return this.pick(`status_id`)}get statusCategory(){return this.pick(`status_category`)}get ticketIds(){return this.pick(`ticket_ids`)}get assignee(){return this.pick(`assignee`)}get recipient(){return this.pick(`recipient`)}get tags(){return this.pick(`tags`)}get conversationLinks(){return this.pick(`links`)}get customFields(){return this.pick(`custom_fields`)}get createdAt(){return this.pick(`created_at`)}get updatedAt(){return this.pick(`updated_at`)}get waitingSince(){return this.pick(`waiting_since`)}get isPrivate(){return this.pick(`is_private`)}get scheduledReminders(){return this.pick(`scheduled_reminders`)}get metadata(){return this.pick(`metadata`)}toUpdateBody(){return O(this.state)}async update(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Updating a conversation by ID requires a request body.`);await this.target(e).update(t);return}await this.patchNoContent(e,ye)}async delete(e){if(e!==void 0){await this.target(e).delete();return}await super.delete()}async updateAssignee(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Updating a conversation assignee by ID requires a request body.`);await this.target(e).updateAssignee(t);return}let n=l.expandPath(`/conversations/{conversation_id}/assignee`,{conversation_id:this.id});await this.base.requestJson(`PUT`,n,{body:e})}async listComments(e){if(e!==void 0)return await this.target(e).listComments();let t=l.expandPath(`/conversations/{conversation_id}/comments`,{conversation_id:this.id});return await this.base.requestJson(`GET`,t)}async addComment(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Adding a conversation comment by ID requires a request body.`);return await this.target(e).addComment(t)}let n=l.expandPath(`/conversations/{conversation_id}/comments`,{conversation_id:this.id}),r=await this.base.requestJson(`POST`,n,{body:e});return new v(this.base,r)}async listDrafts(e){if(e!==void 0)return await this.target(e).listDrafts();let t=l.expandPath(`/conversations/{conversation_id}/drafts`,{conversation_id:this.id});return await this.base.requestJson(`GET`,t)}async createDraftReply(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Creating a conversation draft by ID requires a request body.`);return await this.target(e).createDraftReply(t)}let n=l.expandPath(`/conversations/{conversation_id}/drafts`,{conversation_id:this.id});return await this.base.requestJson(`POST`,n,{body:e})}async listEvents(e,t){if(typeof e==`string`)return await this.target(e).listEvents(t);let n=l.expandPath(`/conversations/{conversation_id}/events`,{conversation_id:this.id});return await this.base.requestJson(`GET`,n,{query:pe(e)})}async listFollowers(e){if(e!==void 0)return await this.target(e).listFollowers();let t=l.expandPath(`/conversations/{conversation_id}/followers`,{conversation_id:this.id});return await this.base.requestJson(`GET`,t)}async addFollowers(e,t,n){if(typeof e==`string`){if(t===void 0)throw Error(`Adding conversation followers by ID requires a request body.`);await this.target(e).addFollowers(t,n);return}let r=l.expandPath(`/conversations/{conversation_id}/followers`,{conversation_id:this.id});await this.base.requestJson(`POST`,r,{body:e,query:ge(t)})}async deleteFollowers(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Removing conversation followers by ID requires a request body.`);await this.target(e).deleteFollowers(t);return}let n=l.expandPath(`/conversations/{conversation_id}/followers`,{conversation_id:this.id});await this.base.requestJson(`DELETE`,n,{body:e})}async listInboxes(e){if(e!==void 0)return await this.target(e).listInboxes();let t=l.expandPath(`/conversations/{conversation_id}/inboxes`,{conversation_id:this.id});return await this.base.requestJson(`GET`,t)}async addLink(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Adding a conversation link by ID requires a request body.`);await this.target(e).addLink(t);return}let n=l.expandPath(`/conversations/{conversation_id}/links`,{conversation_id:this.id});await this.base.requestJson(`POST`,n,{body:e})}async removeLinks(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Removing conversation links by ID requires a request body.`);await this.target(e).removeLinks(t);return}let n=l.expandPath(`/conversations/{conversation_id}/links`,{conversation_id:this.id});await this.base.requestJson(`DELETE`,n,{body:e})}async listMessages(e,t){return typeof e==`string`?await this.target(e).listMessages(t):await he(this.base,this.id,e)}async createMessageReply(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Replying to a conversation by ID requires a request body.`);return await this.target(e).createMessageReply(t)}let n=l.expandPath(`/conversations/{conversation_id}/messages`,{conversation_id:this.id});return await this.base.requestJson(`POST`,n,{body:e})}async updateReminders(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Updating conversation reminders by ID requires a request body.`);await this.target(e).updateReminders(t);return}let n=l.expandPath(`/conversations/{conversation_id}/reminders`,{conversation_id:this.id});await this.base.requestJson(`PATCH`,n,{body:e})}async addTag(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Adding a conversation tag by ID requires a request body.`);await this.target(e).addTag(t);return}let n=l.expandPath(`/conversations/{conversation_id}/tags`,{conversation_id:this.id});await this.base.requestJson(`POST`,n,{body:e})}async removeTag(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Removing a conversation tag by ID requires a request body.`);await this.target(e).removeTag(t);return}let n=l.expandPath(`/conversations/{conversation_id}/tags`,{conversation_id:this.id});await this.base.requestJson(`DELETE`,n,{body:e})}async list(e){return await this.base.requestJson(`GET`,`/conversations`,{query:de(e)})}async create(t){let n=await this.base.requestJson(`POST`,`/conversations`,{body:t});return new e(this.base,n)}async listCustomFields(){return await this.base.requestJson(`GET`,`/conversations/custom_fields`)}async search(e,t){let n=l.expandPath(`/conversations/search/{query}`,{query:e});return await this.base.requestJson(`GET`,n,{query:fe(t)})}async get(e){let t=this.target(e);return await t.refresh(),t}target(t){return new e(this.base,void 0,t)}},A=class{base;constructor(e){this.base=e}async list(){return await this.base.requestJson(`GET`,`/custom_fields`)}},j=class{base;constructor(e){this.base=e}async download(e){let t=l.expandPath(`/download/{attachment_link_id}`,{attachment_link_id:e});return await this.base.requestWithoutParsingBody(`GET`,t)}},M=class{base;constructor(e){this.base=e}async delete(e,t){let n=l.expandPath(`/drafts/{draft_id}`,{draft_id:e});await this.base.requestJson(`DELETE`,n,{body:t})}async edit(e,t){let n=l.expandPath(`/drafts/{message_id}/`,{message_id:e});return await this.base.requestJson(`PATCH`,n,{body:t})}};const N=e=>{if(!e)return;let t={};return e.q!==void 0&&(t.q=String(e.q)),e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t};var P=class{base;constructor(e){this.base=e}async list(e){return await this.base.requestJson(`GET`,`/events`,{query:N(e)})}async get(e){let t=l.expandPath(`/events/{event_id}`,{event_id:e});return await this.base.requestJson(`GET`,t)}};const be=e=>{if(!e)return;let t={};return e.q!==void 0&&(t.q=String(e.q)),e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),t},F=e=>{let{id:t}=e;if(t===void 0||t===``)throw Error(`Inbox response missing id`);return t};var I=class e{state;base;inboxId;constructor(e,t,n){if(this.base=e,t===void 0){this.inboxId=n;return}let r=F(t);this.inboxId=r,this.state=structuredClone({...t,id:r})}get id(){let e=this.state?.id??this.inboxId;if(e===void 0)throw Error(`This inbox operation requires an ID.`);return e}get links(){return this.requireState()._links}get data(){return this.requireState()}requireState(){if(this.state===void 0)throw Error(`This inbox operation requires fetched resource data.`);return this.state}selfPath(){return l.expandPath(`/inboxes/{inbox_id}`,{inbox_id:this.id})}async refresh(){let e=await this.base.requestJson(`GET`,this.selfPath()),t=F(e);return this.state=structuredClone({...e,id:t}),this}async listChannels(e){if(e!==void 0)return await this.target(e).listChannels();let t=l.expandPath(`/inboxes/{inbox_id}/channels`,{inbox_id:this.id});return await this.base.requestJson(`GET`,t)}async listConversations(e,t){if(typeof e==`string`)return await this.target(e).listConversations(t);let n=l.expandPath(`/inboxes/{inbox_id}/conversations`,{inbox_id:this.id});return await this.base.requestJson(`GET`,n,{query:be(e)})}async importMessage(e,t){if(typeof e==`string`)return await this.target(e).importMessage(t??{});let n=l.expandPath(`/inboxes/{inbox_id}/imported_messages`,{inbox_id:this.id});return await this.base.requestJson(`POST`,n,{body:e})}async listTeammateAccess(e){if(e!==void 0)return await this.target(e).listTeammateAccess();let t=l.expandPath(`/inboxes/{inbox_id}/teammates`,{inbox_id:this.id});return await this.base.requestJson(`GET`,t)}async addTeammateAccess(e,t){if(typeof e==`string`){await this.target(e).addTeammateAccess(t??{teammate_ids:[]});return}let n=l.expandPath(`/inboxes/{inbox_id}/teammates`,{inbox_id:this.id});await this.base.requestJson(`POST`,n,{body:e})}async removeTeammateAccess(e,t){if(typeof e==`string`){await this.target(e).removeTeammateAccess(t??{teammate_ids:[]});return}let n=l.expandPath(`/inboxes/{inbox_id}/teammates`,{inbox_id:this.id});await this.base.requestJson(`DELETE`,n,{body:e})}async list(){return await this.base.requestJson(`GET`,`/inboxes`)}async create(t){let n=await this.base.requestJson(`POST`,`/inboxes`,{body:t});return new e(this.base,n)}async listCustomFields(){return await this.base.requestJson(`GET`,`/inboxes/custom_fields`)}async get(e){return await this.target(e).refresh()}target(t){return new e(this.base,void 0,t)}};const L=e=>{if(!e)return;let t={};return e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),Object.keys(t).length>0?t:void 0};var R=class e{base;knowledgeBaseId;snapshot;constructor(e,t,n){this.base=e,this.knowledgeBaseId=t??``,this.snapshot=n}get id(){if(this.knowledgeBaseId.length===0)throw Error(`This knowledge base operation requires an ID.`);return this.knowledgeBaseId}get data(){return this.snapshot}async refresh(){let e=l.expandPath(`/knowledge_bases/{knowledge_base_id}`,{knowledge_base_id:this.knowledgeBaseId});return this.snapshot=await this.base.requestJson(`GET`,e),this}async getContentDefault(){let e=l.expandPath(`/knowledge_bases/{knowledge_base_id}/content`,{knowledge_base_id:this.knowledgeBaseId});return await this.base.requestJson(`GET`,e)}async updateContentDefault(e){let t=l.expandPath(`/knowledge_bases/{knowledge_base_id}/content`,{knowledge_base_id:this.knowledgeBaseId});return await this.base.requestJson(`PATCH`,t,{body:e})}async getContentLocale(e){let t=l.expandPath(`/knowledge_bases/{knowledge_base_id}/locales/{locale}/content`,{knowledge_base_id:this.knowledgeBaseId,locale:e});return await this.base.requestJson(`GET`,t)}async updateContentLocale(e,t){let n=l.expandPath(`/knowledge_bases/{knowledge_base_id}/locales/{locale}/content`,{knowledge_base_id:this.knowledgeBaseId,locale:e});return await this.base.requestJson(`PATCH`,n,{body:t})}async listArticles(e){let t=l.expandPath(`/knowledge_bases/{knowledge_base_id}/articles`,{knowledge_base_id:this.knowledgeBaseId});return await this.base.requestJson(`GET`,t,{query:L(e)})}async createArticleDefault(e){let t=l.expandPath(`/knowledge_bases/{knowledge_base_id}/articles`,{knowledge_base_id:this.knowledgeBaseId}),n=await this.base.requestJson(`POST`,t,{body:e});return new z(this.base,n.id,n)}async createArticleLocale(e,t){let n=l.expandPath(`/knowledge_bases/{knowledge_base_id}/locales/{locale}/articles`,{knowledge_base_id:this.knowledgeBaseId,locale:e}),r=await this.base.requestJson(`POST`,n,{body:t});return new z(this.base,r.id,r)}async listCategories(e){let t=l.expandPath(`/knowledge_bases/{knowledge_base_id}/categories`,{knowledge_base_id:this.knowledgeBaseId});return await this.base.requestJson(`GET`,t,{query:L(e)})}async createCategoryDefault(e){let t=l.expandPath(`/knowledge_bases/{knowledge_base_id}/categories`,{knowledge_base_id:this.knowledgeBaseId}),n=await this.base.requestJson(`POST`,t,{body:e});return new B(this.base,n.id,n)}async createCategoryLocale(e,t){let n=l.expandPath(`/knowledge_bases/{knowledge_base_id}/locales/{locale}/categories`,{knowledge_base_id:this.knowledgeBaseId,locale:e}),r=await this.base.requestJson(`POST`,n,{body:t});return new B(this.base,r.id,r)}async list(){return await this.base.requestJson(`GET`,`/knowledge_bases`)}async create(t){let n=await this.base.requestJson(`POST`,`/knowledge_bases`,{body:t});return new e(this.base,n.id,n)}async get(e){let t=this.target(e);return await t.refresh(),t}target(t){return new e(this.base,t)}article(e){return new z(this.base,e)}category(e){return new B(this.base,e)}},z=class{base;articleId;snapshot;constructor(e,t,n){this.base=e,this.articleId=t,this.snapshot=n}get id(){return this.articleId}get data(){return this.snapshot}async refresh(){let e=l.expandPath(`/knowledge_base_articles/{article_id}`,{article_id:this.articleId});return this.snapshot=await this.base.requestJson(`GET`,e),this}async delete(){let e=l.expandPath(`/knowledge_base_articles/{article_id}`,{article_id:this.articleId});return await this.base.requestJson(`DELETE`,e)}async getContentDefault(){let e=l.expandPath(`/knowledge_base_articles/{article_id}/content`,{article_id:this.articleId});return await this.base.requestJson(`GET`,e)}async updateContentDefault(e){let t=l.expandPath(`/knowledge_base_articles/{article_id}/content`,{article_id:this.articleId});return await this.base.requestJson(`PATCH`,t,{body:e})}async getContentLocale(e){let t=l.expandPath(`/knowledge_base_articles/{article_id}/locales/{locale}/content`,{article_id:this.articleId,locale:e});return await this.base.requestJson(`GET`,t)}async updateContentLocale(e,t){let n=l.expandPath(`/knowledge_base_articles/{article_id}/locales/{locale}/content`,{article_id:this.articleId,locale:e});return await this.base.requestJson(`PATCH`,n,{body:t})}async downloadAttachment(e){let t=l.expandPath(`/knowledge_base_articles/{article_id}/download/{attachment_id}`,{article_id:this.articleId,attachment_id:e});return await this.base.requestWithoutParsingBody(`GET`,t)}},B=class{base;categoryId;snapshot;constructor(e,t,n){this.base=e,this.categoryId=t,this.snapshot=n}get id(){return this.categoryId}get data(){return this.snapshot}async refresh(){let e=l.expandPath(`/knowledge_base_categories/{category_id}`,{category_id:this.categoryId});return this.snapshot=await this.base.requestJson(`GET`,e),this}async delete(){let e=l.expandPath(`/knowledge_base_categories/{category_id}`,{category_id:this.categoryId});await this.base.requestJson(`DELETE`,e)}async listArticles(e){let t=l.expandPath(`/knowledge_base_categories/{category_id}/articles`,{category_id:this.categoryId});return await this.base.requestJson(`GET`,t,{query:L(e)})}async getContentDefault(){let e=l.expandPath(`/knowledge_base_categories/{category_id}/content`,{category_id:this.categoryId});return await this.base.requestJson(`GET`,e)}async updateContentDefault(e){let t=l.expandPath(`/knowledge_base_categories/{category_id}/content`,{category_id:this.categoryId});return await this.base.requestJson(`PATCH`,t,{body:e})}async getContentLocale(e){let t=l.expandPath(`/knowledge_base_categories/{category_id}/locales/{locale}/content`,{category_id:this.categoryId,locale:e});return await this.base.requestJson(`GET`,t)}async updateContentLocale(e,t){let n=l.expandPath(`/knowledge_base_categories/{category_id}/locales/{locale}/content`,{category_id:this.categoryId,locale:e});return await this.base.requestJson(`PATCH`,n,{body:t})}};const xe=e=>{if(!e)return;let t={};return e.q!==void 0&&(t.q=String(e.q)),e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},Se=e=>{if(!e)return;let t={};return e.q!==void 0&&(t.q=String(e.q)),e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},Ce=(e,t)=>{let n=Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0));return{...e,...n}},we=e=>({name:e.name});var V=class e extends u{selfPath(){return l.expandPath(`/links/{link_id}`,{link_id:this.id})}get name(){return this.pick(`name`)}set name(e){this.assign(`name`,e)}get type(){return this.pick(`type`)}get externalUrl(){return this.pick(`external_url`)}get customFields(){return this.pick(`custom_fields`)}delete(e){return e===void 0?Promise.reject(Error(`Deleting link ${this.id} is not supported by the Front REST API for this path.`)):this.target(e).delete()}toUpdateBody(){return we(this.state)}async update(e,t){if(typeof e==`string`){await this.target(e).update(t??{});return}await this.patchNoContent(e,Ce)}async listConversations(e,t){if(typeof e==`string`)return await this.target(e).listConversations(t);let n=l.expandPath(`/links/{link_id}/conversations`,{link_id:this.id});return await this.base.requestJson(`GET`,n,{query:Se(e)})}async list(e){return await this.base.requestJson(`GET`,`/links`,{query:xe(e)})}async create(t){let n=await this.base.requestJson(`POST`,`/links`,{body:t});return new e(this.base,n)}async listCustomFields(){return await this.base.requestJson(`GET`,`/links/custom_fields`)}async get(e){return await this.target(e).refresh()}target(t){return new e(this.base,void 0,t)}},H=class{base;constructor(e){this.base=e}async details(){return await this.base.requestJson(`GET`,`/me`)}};const Te=e=>{if(!e)return;let t={};return e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},Ee=e=>{let t={body:e.body,name:e.name,subject:e.subject===null?void 0:e.subject};return e.inbox_ids!==null&&(t.inbox_ids=e.inbox_ids),t};var U=class e extends u{folderIdForUpdate;constructor(e,t,n){super(e,t,n),this.folderIdForUpdate=void 0}onAfterRefresh(){this.folderIdForUpdate=void 0}selfPath(){return l.expandPath(`/message_templates/{message_template_id}`,{message_template_id:this.id})}get name(){return this.pick(`name`)}set name(e){this.assign(`name`,e)}get subject(){return this.pick(`subject`)}set subject(e){this.assign(`subject`,e)}get body(){return this.pick(`body`)}set body(e){this.assign(`body`,e)}get isAvailableForAllInboxes(){return this.pick(`is_available_for_all_inboxes`)}get inboxIds(){return this.pick(`inbox_ids`)}set inboxIds(e){this.assign(`inbox_ids`,e)}get folderId(){return this.folderIdForUpdate}set folderId(e){this.folderIdForUpdate=e}toUpdateBody(){let e=Ee(this.state);return this.folderIdForUpdate!==void 0&&(e.folder_id=this.folderIdForUpdate??void 0),e}async update(e,t){if(typeof e==`string`){await this.target(e).update(t??{});return}await this.patchReplaceFromResponse(e),`folder_id`in e&&(this.folderIdForUpdate=e.folder_id===null||e.folder_id===void 0?void 0:e.folder_id)}async delete(e){if(e===void 0){await super.delete();return}await this.target(e).delete()}async downloadAttachment(e,t){if(t!==void 0)return await this.target(e).downloadAttachment(t);let n=l.expandPath(`/message_templates/{message_template_id}/download/{attachment_link_id}`,{attachment_link_id:e,message_template_id:this.id});return await this.base.requestWithoutParsingBody(`GET`,n)}async list(e){return await this.base.requestJson(`GET`,`/message_templates`,{query:Te(e)})}async create(t){let n=await this.base.requestJson(`POST`,`/message_templates`,{body:t});return new e(this.base,n)}async get(e){return await this.target(e).refresh()}target(t){return new e(this.base,void 0,t)}};const De=e=>{if(!e)return;let t={};return e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},Oe=(e,t)=>{let n={name:e.name};return t!==void 0&&(n.parent_folder_id=t??void 0),n};var W=class e extends u{parentFolderIdForUpdate;constructor(e,t,n){super(e,t,n),this.parentFolderIdForUpdate=void 0}onAfterRefresh(){this.parentFolderIdForUpdate=void 0}selfPath(){return l.expandPath(`/message_template_folders/{message_template_folder_id}`,{message_template_folder_id:this.id})}get name(){return this.pick(`name`)}set name(e){this.assign(`name`,e)}get parentFolderId(){return this.parentFolderIdForUpdate}set parentFolderId(e){this.parentFolderIdForUpdate=e}toUpdateBody(){return Oe(this.state,this.parentFolderIdForUpdate)}async update(e,t){if(typeof e==`string`){await this.target(e).update(t??{});return}await this.patchReplaceFromResponse(e),`parent_folder_id`in e&&(this.parentFolderIdForUpdate=e.parent_folder_id===null||e.parent_folder_id===void 0?void 0:e.parent_folder_id)}async delete(e){if(e!==void 0){await this.target(e).delete();return}await this.base.requestJson(`DELETE`,this.selfPath())}async listChildFolders(e){if(e!==void 0)return await this.target(e).listChildFolders();let t=l.expandPath(`/message_template_folders/{message_template_folder_id}/message_template_folders`,{message_template_folder_id:this.id});return await this.base.requestJson(`GET`,t)}async createChildFolder(t,n){if(typeof t==`string`){if(n===void 0)throw Error(`Creating a child folder requires a request body.`);return await this.target(t).createChildFolder(n)}let r=l.expandPath(`/message_template_folders/{message_template_folder_id}/message_template_folders`,{message_template_folder_id:this.id}),i=await this.base.requestJson(`POST`,r,{body:t});return new e(this.base,i)}async listChildTemplates(e){if(e!==void 0)return await this.target(e).listChildTemplates();let t=l.expandPath(`/message_template_folders/{message_template_folder_id}/message_templates`,{message_template_folder_id:this.id});return await this.base.requestJson(`GET`,t)}async createChildTemplate(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Creating a child template requires a request body.`);return await this.target(e).createChildTemplate(t)}let n=l.expandPath(`/message_template_folders/{message_template_folder_id}/message_templates`,{message_template_folder_id:this.id}),r=await this.base.requestJson(`POST`,n,{body:e});return new U(this.base,r)}async list(e){return await this.base.requestJson(`GET`,`/message_template_folders`,{query:De(e)})}async create(t){let n=await this.base.requestJson(`POST`,`/message_template_folders`,{body:t});return new e(this.base,n)}async get(e){return await this.target(e).refresh()}target(t){return new e(this.base,void 0,t)}};const ke={};var G=class e{base;boundMessageId;snapshot;constructor(e,t,n){this.base=e,this.boundMessageId=t,this.snapshot=n}get messageIdParam(){return this.messageId}get data(){return this.snapshot}async refresh(){let e=l.expandPath(`/messages/{message_id}`,{message_id:this.messageId});return this.snapshot=await this.base.requestJson(`GET`,e),this}async fetchRaw(e,t){let n=typeof e==`string`?e:this.messageId,r=typeof e==`string`?t:e,i=l.expandPath(`/messages/{message_id}`,{message_id:n}),a={...r?.headers};return a.Accept===void 0&&(a.Accept=`application/json`),await this.base.requestWithoutParsingBody(`GET`,i,{headers:a})}async downloadAttachment(e,t){let n=t===void 0?this.messageId:e,r=t??e,i=l.expandPath(`/messages/{message_id}/download/{attachment_link_id}`,{attachment_link_id:r,message_id:n});return await this.base.requestWithoutParsingBody(`GET`,i)}async getSeen(e=this.messageId){let t=l.expandPath(`/messages/{message_id}/seen`,{message_id:e});return await this.base.requestJson(`GET`,t)}async markSeen(e=this.messageId){let t=l.expandPath(`/messages/{message_id}/seen`,{message_id:e});await this.base.requestJson(`POST`,t,{body:ke})}get messageId(){if(this.boundMessageId===void 0)throw Error(`This message operation requires an ID.`);return this.boundMessageId}async get(t){let n=l.expandPath(`/messages/{message_id}`,{message_id:t}),r=await this.base.requestJson(`GET`,n);return new e(this.base,t,r)}},K=class{base;constructor(e){this.base=e}async list(){return await this.base.requestJson(`GET`,`/rules`)}async get(e){let t=l.expandPath(`/rules/{rule_id}`,{rule_id:e});return await this.base.requestJson(`GET`,t)}};const Ae=e=>{if(!e)return;let t={};return e.q!==void 0&&(t.q=String(e.q)),e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),t},je=(e,t)=>{let n=Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0));return{...e,...n}},Me=e=>({custom_fields:e.custom_fields,first_name:e.first_name,is_available:e.is_available,last_name:e.last_name,username:e.username});var q=class e extends u{selfPath(){return l.expandPath(`/teammates/{teammate_id}`,{teammate_id:this.id})}get email(){return this.pick(`email`)}get username(){return this.pick(`username`)}set username(e){this.assign(`username`,e)}get firstName(){return this.pick(`first_name`)}set firstName(e){this.assign(`first_name`,e)}get lastName(){return this.pick(`last_name`)}set lastName(e){this.assign(`last_name`,e)}get isAdmin(){return this.pick(`is_admin`)}get isAvailable(){return this.pick(`is_available`)}set isAvailable(e){this.assign(`is_available`,e)}get isBlocked(){return this.pick(`is_blocked`)}get type(){return this.pick(`type`)}get customFields(){return this.pick(`custom_fields`)}set customFields(e){this.assign(`custom_fields`,e)}toUpdateBody(){return Me(this.state)}async update(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Updating a teammate by ID requires a request body.`);await this.target(e).update(t);return}await this.patchNoContent(e,je)}async listAssignedConversations(e,t){if(typeof e==`string`)return await this.target(e).listAssignedConversations(t);let n=l.expandPath(`/teammates/{teammate_id}/conversations`,{teammate_id:this.id});return await this.base.requestJson(`GET`,n,{query:Ae(e)})}async list(){return await this.base.requestJson(`GET`,`/teammates`)}async get(e){let t=this.target(e);return await t.refresh(),t}target(t){return new e(this.base,void 0,t)}};const Ne=(e,t)=>{let{times:n,...r}=t,i=Object.fromEntries(Object.entries(r).filter(([,e])=>e!==void 0)),a={...e,...i};return n!==void 0&&(a={...a,times:{...e.times,...n}}),a},Pe=e=>({color:e.color,name:e.name,times:e.times,timezone:e.timezone});var J=class e extends u{selfPath(){return l.expandPath(`/shifts/{shift_id}`,{shift_id:this.id})}get name(){return this.pick(`name`)}set name(e){this.assign(`name`,e)}get color(){return this.pick(`color`)}set color(e){this.assign(`color`,e)}get timezone(){return this.pick(`timezone`)}set timezone(e){this.assign(`timezone`,e)}get times(){return this.pick(`times`)}set times(e){this.assign(`times`,e)}get createdAt(){return this.pick(`created_at`)}get updatedAt(){return this.pick(`updated_at`)}toUpdateBody(){return Pe(this.state)}async update(e,t){if(typeof e==`string`){await this.target(e).update(t??{});return}await this.patchNoContent(e,Ne)}async delete(e){if(e===void 0){await super.delete();return}await this.target(e).delete()}async listTeammates(e){if(e!==void 0)return await this.target(e).listTeammates();let t=l.expandPath(`/shifts/{shift_id}/teammates`,{shift_id:this.id});return((await this.base.requestJson(`GET`,t))._results??[]).map(e=>new q(this.base,e))}async addTeammates(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Adding teammates requires a request body.`);await this.target(e).addTeammates(t);return}let n=l.expandPath(`/shifts/{shift_id}/teammates`,{shift_id:this.id});await this.base.requestJson(`POST`,n,{body:e})}async removeTeammates(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Removing teammates requires a request body.`);await this.target(e).removeTeammates(t);return}let n=l.expandPath(`/shifts/{shift_id}/teammates`,{shift_id:this.id});await this.base.requestJson(`DELETE`,n,{body:e})}async list(){return await this.base.requestJson(`GET`,`/shifts`)}async create(t){let n=await this.base.requestJson(`POST`,`/shifts`,{body:t});return new e(this.base,n)}async get(e){return await this.target(e).refresh()}target(t){return new e(this.base,void 0,t)}};const Fe=e=>({body:e.body,channel_ids:e.channel_ids===null?void 0:e.channel_ids,is_default:e.is_default,is_visible_for_all_teammate_channels:e.is_visible_for_all_teammate_channels,name:e.name??void 0,sender_info:e.sender_info??void 0});var Y=class e extends u{selfPath(){return l.expandPath(`/signatures/{signature_id}`,{signature_id:this.id})}get name(){return this.pick(`name`)}set name(e){this.assign(`name`,e)}get body(){return this.pick(`body`)}set body(e){this.assign(`body`,e)}get senderInfo(){return this.pick(`sender_info`)}set senderInfo(e){this.assign(`sender_info`,e)}get isVisibleForAllTeammateChannels(){return this.pick(`is_visible_for_all_teammate_channels`)}set isVisibleForAllTeammateChannels(e){this.assign(`is_visible_for_all_teammate_channels`,e)}get isDefault(){return this.pick(`is_default`)}set isDefault(e){this.assign(`is_default`,e)}get isPrivate(){return this.pick(`is_private`)}get channelIds(){return this.pick(`channel_ids`)}set channelIds(e){this.assign(`channel_ids`,e)}toUpdateBody(){return Fe(this.state)}async update(e,t){if(typeof e==`string`){await this.target(e).update(t??{});return}await this.patchReplaceFromResponse(e)}async delete(e){if(e===void 0){await super.delete();return}await this.target(e).delete()}async get(e){return await this.target(e).refresh()}target(t){return new e(this.base,void 0,t)}async listTeammate(e){let t=l.expandPath(`/teammates/{teammate_id}/signatures`,{teammate_id:e});return await this.base.requestJson(`GET`,t)}async createTeammate(t,n){let r=l.expandPath(`/teammates/{teammate_id}/signatures`,{teammate_id:t}),i=await this.base.requestJson(`POST`,r,{body:n});return new e(this.base,i)}async listTeam(e){let t=l.expandPath(`/teams/{team_id}/signatures`,{team_id:e});return await this.base.requestJson(`GET`,t)}async createTeam(t,n){let r=l.expandPath(`/teams/{team_id}/signatures`,{team_id:t}),i=await this.base.requestJson(`POST`,r,{body:n});return new e(this.base,i)}};const Ie=(e,t)=>{let{permissions:n,...r}=t,i=Object.fromEntries(Object.entries(r).filter(([,e])=>e!==void 0)),a={...e,...i};if(n!==void 0){let t=n.contacts,r=e.permissions.contacts;a={...a,permissions:{...e.permissions,...n,contacts:t===void 0?r:{...r,...t}}}}return a},Le=e=>{let t=e.contacts;if(t===void 0)return;let{access:n}=t;if(n===void 0)return;let r={access:n};return t.contact_list_ids!==void 0&&(r.contact_list_ids=t.contact_list_ids),{contacts:r}},X=e=>{let t={name:e.name};e.description!==null&&(t.description=e.description);let n=Le(e.permissions);return n!==void 0&&(t.permissions=n),t};var Z=class e extends u{selfPath(){return l.expandPath(`/teammate_groups/{teammate_group_id}`,{teammate_group_id:this.id})}get name(){return this.pick(`name`)}set name(e){this.assign(`name`,e)}get description(){return this.pick(`description`)}set description(e){this.assign(`description`,e)}get isManagedByScim(){return this.pick(`is_managed_by_scim`)}get permissions(){return this.pick(`permissions`)}set permissions(e){this.assign(`permissions`,e)}toUpdateBody(){return X(this.state)}async update(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Updating a teammate group by ID requires a request body.`);await this.target(e).update(t);return}await this.patchNoContent(e,Ie)}async listInboxes(){let e=l.expandPath(`/teammate_groups/{teammate_group_id}/inboxes`,{teammate_group_id:this.id});return await this.base.requestJson(`GET`,e)}async addInboxes(e){let t=l.expandPath(`/teammate_groups/{teammate_group_id}/inboxes`,{teammate_group_id:this.id});await this.base.requestJson(`POST`,t,{body:e})}async removeInboxes(e){let t=l.expandPath(`/teammate_groups/{teammate_group_id}/inboxes`,{teammate_group_id:this.id});await this.base.requestJson(`DELETE`,t,{body:e})}async listTeammates(){let e=l.expandPath(`/teammate_groups/{teammate_group_id}/teammates`,{teammate_group_id:this.id});return((await this.base.requestJson(`GET`,e))._results??[]).map(e=>new q(this.base,e))}async addTeammates(e){let t=l.expandPath(`/teammate_groups/{teammate_group_id}/teammates`,{teammate_group_id:this.id});await this.base.requestJson(`POST`,t,{body:e})}async removeTeammates(e){let t=l.expandPath(`/teammate_groups/{teammate_group_id}/teammates`,{teammate_group_id:this.id});await this.base.requestJson(`DELETE`,t,{body:e})}async listTeams(){let e=l.expandPath(`/teammate_groups/{teammate_group_id}/teams`,{teammate_group_id:this.id});return await this.base.requestJson(`GET`,e)}async addTeams(e){let t=l.expandPath(`/teammate_groups/{teammate_group_id}/teams`,{teammate_group_id:this.id});await this.base.requestJson(`POST`,t,{body:e})}async removeTeams(e){let t=l.expandPath(`/teammate_groups/{teammate_group_id}/teams`,{teammate_group_id:this.id});await this.base.requestJson(`DELETE`,t,{body:e})}async list(){return await this.base.requestJson(`GET`,`/teammate_groups`)}async create(t){let n=await this.base.requestJson(`POST`,`/teammate_groups`,{body:t});return new e(this.base,n)}async get(e){let t=this.target(e);return await t.refresh(),t}target(t){return new e(this.base,void 0,t)}};const Re=e=>{if(!e)return;let t={};return e.q!==void 0&&(t.q=String(e.q)),e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},ze=e=>{if(!e)return;let t={};return e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},Be=e=>{if(!e)return;let t={};return e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},Ve=e=>{if(!e)return;let t={};return e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),e.sort_by!==void 0&&(t.sort_by=String(e.sort_by)),e.sort_order!==void 0&&(t.sort_order=String(e.sort_order)),t},He=e=>{if(!e)return;let t={};return e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),t};var Q=class e{state;base;teamId;constructor(e,t,n){this.base=e,this.state=t===void 0?void 0:structuredClone(t),this.teamId=n}get id(){let e=this.state?.id??this.teamId;if(e===void 0)throw Error(`This team operation requires an ID.`);return e}get links(){return this.requireState()._links}get data(){return this.state}requireState(){if(this.state===void 0)throw Error(`This team operation requires fetched resource data.`);return this.state}selfPath(){return l.expandPath(`/teams/{team_id}`,{team_id:this.id})}async refresh(){let e=await this.base.requestJson(`GET`,this.selfPath());return this.state=structuredClone(e),this}async listChannels(){let e=l.expandPath(`/teams/{team_id}/channels`,{team_id:this.id});return await this.base.requestJson(`GET`,e)}async listContactGroups(){let e=l.expandPath(`/teams/{team_id}/contact_groups`,{team_id:this.id});return await this.base.requestJson(`GET`,e)}async createContactGroup(e){let t=l.expandPath(`/teams/{team_id}/contact_groups`,{team_id:this.id});await this.base.requestJson(`POST`,t,{body:e})}async listContactLists(){let e=l.expandPath(`/teams/{team_id}/contact_lists`,{team_id:this.id});return await this.base.requestJson(`GET`,e)}async createContactList(e){let t=l.expandPath(`/teams/{team_id}/contact_lists`,{team_id:this.id});await this.base.requestJson(`POST`,t,{body:e})}async listContacts(e){let t=l.expandPath(`/teams/{team_id}/contacts`,{team_id:this.id});return await this.base.requestJson(`GET`,t,{query:Re(e)})}async createContact(e){let t=l.expandPath(`/teams/{team_id}/contacts`,{team_id:this.id});return await this.base.requestJson(`POST`,t,{body:e})}async listInboxes(){let e=l.expandPath(`/teams/{team_id}/inboxes`,{team_id:this.id});return await this.base.requestJson(`GET`,e)}async createInbox(e){let t=l.expandPath(`/teams/{team_id}/inboxes`,{team_id:this.id}),n=await this.base.requestJson(`POST`,t,{body:e});return new I(this.base,n)}async listMessageTemplateFolders(e){let t=l.expandPath(`/teams/{team_id}/message_template_folders`,{team_id:this.id});return await this.base.requestJson(`GET`,t,{query:ze(e)})}async createMessageTemplateFolder(e){let t=l.expandPath(`/teams/{team_id}/message_template_folders`,{team_id:this.id});return await this.base.requestJson(`POST`,t,{body:e})}async listMessageTemplates(e){let t=l.expandPath(`/teams/{team_id}/message_templates`,{team_id:this.id});return await this.base.requestJson(`GET`,t,{query:Be(e)})}async createMessageTemplate(e){let t=l.expandPath(`/teams/{team_id}/message_templates`,{team_id:this.id});return await this.base.requestJson(`POST`,t,{body:e})}async listRules(){let e=l.expandPath(`/teams/{team_id}/rules`,{team_id:this.id});return await this.base.requestJson(`GET`,e)}async listShifts(){let e=l.expandPath(`/teams/{team_id}/shifts`,{team_id:this.id});return await this.base.requestJson(`GET`,e)}async createShift(e){let t=l.expandPath(`/teams/{team_id}/shifts`,{team_id:this.id});return await this.base.requestJson(`POST`,t,{body:e})}async listSignatures(){let e=l.expandPath(`/teams/{team_id}/signatures`,{team_id:this.id});return await this.base.requestJson(`GET`,e)}async createSignature(e){let t=l.expandPath(`/teams/{team_id}/signatures`,{team_id:this.id}),n=await this.base.requestJson(`POST`,t,{body:e});return new Y(this.base,n)}async listTags(e){let t=l.expandPath(`/teams/{team_id}/tags`,{team_id:this.id});return await this.base.requestJson(`GET`,t,{query:Ve(e)})}async createTag(e){let t=l.expandPath(`/teams/{team_id}/tags`,{team_id:this.id}),n=await this.base.requestJson(`POST`,t,{body:e});return new C(this.base,n)}async addTeammates(e){let t=l.expandPath(`/teams/{team_id}/teammates`,{team_id:this.id});await this.base.requestJson(`POST`,t,{body:e})}async removeTeammates(e){let t=l.expandPath(`/teams/{team_id}/teammates`,{team_id:this.id});await this.base.requestJson(`DELETE`,t,{body:e})}async listViews(e){let t=l.expandPath(`/teams/{team_id}/views`,{team_id:this.id});return await this.base.requestJson(`GET`,t,{query:He(e)})}async createView(e){let t=l.expandPath(`/teams/{team_id}/views`,{team_id:this.id});return await this.base.requestJson(`POST`,t,{body:e})}async listTeams(){return await this.base.requestJson(`GET`,`/teams`)}async getTeam(e){let t=this.target(e);return await t.refresh(),t}target(t){return new e(this.base,void 0,t)}};const Ue=e=>{if(!e)return;let t={};return e.limit!==void 0&&(t.limit=String(e.limit)),e.page_token!==void 0&&(t.page_token=String(e.page_token)),t},We=(e,t)=>{let n=Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0)),r={...e,...n};return Object.hasOwn(t,`highlight`)&&(r={...r,highlight:t.highlight??null}),r},Ge=e=>({assignee_ids:e.assignee_ids,highlight:e.highlight??void 0,inbox_ids:e.inbox_ids,name:e.name,no_tags:e.no_tags,not_assignee_ids:e.not_assignee_ids,not_tag_ids:e.not_tag_ids,tag_ids:e.tag_ids});var $=class e extends u{selfPath(){return l.expandPath(`/views/{view_id}`,{view_id:this.id})}get name(){return this.pick(`name`)}set name(e){this.assign(`name`,e)}get highlight(){return this.pick(`highlight`)}set highlight(e){this.assign(`highlight`,e)}get inboxIds(){return this.pick(`inbox_ids`)}set inboxIds(e){this.assign(`inbox_ids`,e)}get tagIds(){return this.pick(`tag_ids`)}set tagIds(e){this.assign(`tag_ids`,e)}get notTagIds(){return this.pick(`not_tag_ids`)}set notTagIds(e){this.assign(`not_tag_ids`,e)}get noTags(){return this.pick(`no_tags`)}set noTags(e){this.assign(`no_tags`,e)}get assigneeIds(){return this.pick(`assignee_ids`)}set assigneeIds(e){this.assign(`assignee_ids`,e)}get notAssigneeIds(){return this.pick(`not_assignee_ids`)}set notAssigneeIds(e){this.assign(`not_assignee_ids`,e)}toUpdateBody(){return Ge(this.state)}async update(e,t){if(typeof e==`string`){if(t===void 0)throw Error(`Updating a view by ID requires a request body.`);await this.target(e).update(t);return}await this.patchNoContent(e,We)}async addTeammates(e){let t=l.expandPath(`/views/{view_id}/teammates`,{view_id:this.id});await this.base.requestJson(`POST`,t,{body:e})}async list(e){return await this.base.requestJson(`GET`,`/views`,{query:Ue(e)})}async get(e){let t=this.target(e);return await t.refresh(),t}target(t){return new e(this.base,void 0,t)}};const Ke=()=>{let e=process.env.FRONT_API_TOKEN;if(!e)return;let t=e.trim();return t.length>0?t:void 0};var qe=class extends l{accounts;analytics;applications;channels;comments;company;contactLists;contacts;conversations;customFieldsGlobal;downloads;drafts;events;inboxes;knowledgeBases;links;me;messageTemplateFolders;messageTemplates;messages;rules;shifts;tags;signatures;teammateGroups;teammates;teams;views;constructor(e){let{apiKey:t,baseUrl:n,fetch:r,userAgent:i}=e??{},a=t??Ke();if(!a)throw Error(`Front API token is required. Set FRONT_API_TOKEN in the environment or pass { apiKey: "..." } to the Front constructor.`);super({apiKey:a,baseUrl:n??`https://api2.frontapp.com`,...r===void 0?{}:{fetch:r},...i===void 0?{}:{userAgent:i}}),this.accounts=new f(this),this.analytics=new h(this),this.applications=new g(this),this.channels=new _(this),this.comments=new v(this),this.company=new w(this),this.contactLists=new T(this),this.contacts=new D(this),this.conversations=new k(this),this.customFieldsGlobal=new A(this),this.downloads=new j(this),this.drafts=new M(this),this.events=new P(this),this.inboxes=new I(this),this.knowledgeBases=new R(this),this.links=new V(this),this.me=new H(this),this.messageTemplateFolders=new W(this),this.messageTemplates=new U(this),this.messages=new G(this),this.rules=new K(this),this.shifts=new J(this),this.tags=new C(this),this.signatures=new Y(this),this.teammateGroups=new Z(this),this.teammates=new q(this),this.teams=new Q(this),this.views=new $(this)}};exports.Front=qe,exports.FrontAccounts=f,exports.FrontAnalytics=h,exports.FrontAnalyticsExport=p,exports.FrontAnalyticsReport=m,exports.FrontApiError=n,exports.FrontApplications=g,exports.FrontBase=l,exports.FrontChannels=_,exports.FrontComments=v,exports.FrontCompany=w,exports.FrontContactLists=T,exports.FrontContacts=D,exports.FrontConversations=k,exports.FrontCustomFieldsGlobal=A,exports.FrontDownloads=j,exports.FrontDrafts=M,exports.FrontEvents=P,exports.FrontInboxes=I,exports.FrontKnowledgeBaseArticle=z,exports.FrontKnowledgeBaseCategory=B,exports.FrontKnowledgeBases=R,exports.FrontLinks=V,exports.FrontMe=H,exports.FrontMessageTemplateFolders=W,exports.FrontMessageTemplates=U,exports.FrontMessages=G,exports.FrontResource=u,exports.FrontRules=K,exports.FrontShifts=J,exports.FrontSignatures=Y,exports.FrontTags=C,exports.FrontTeammateGroups=Z,exports.FrontTeammates=q,exports.FrontTeams=Q,exports.FrontViews=$,exports.normalizeFrontResponse=i,exports.pageTokenFromPaginationNextUrl=r;
2
+ //# sourceMappingURL=index.cjs.map