@cstar.help/js 0.17.2 → 0.17.4

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 CHANGED
@@ -49,16 +49,16 @@ Manage tickets, customers, articles, team members, settings, game system, and ev
49
49
  ```typescript
50
50
  import { CStarClient } from '@cstar.help/js';
51
51
 
52
- const cstar = new CStarClient({
53
- apiKey: process.env.CSTAR_SECRET_KEY, // sk_live_... or sk_test_...
54
- teamId: process.env.CSTAR_TEAM_ID
55
- });
52
+ const apiKey = process.env.CSTAR_SECRET_KEY; // sk_live_... or sk_test_...
53
+ const teamId = process.env.CSTAR_TEAM_ID;
54
+ if (!apiKey || !teamId) throw new Error('Set CSTAR_SECRET_KEY and CSTAR_TEAM_ID.');
55
+ const cstar = new CStarClient({ apiKey, teamId });
56
56
 
57
57
  // List open tickets
58
58
  const { data: tickets } = await cstar.tickets.list({ status: 'open' });
59
59
 
60
60
  // Create a ticket
61
- const { data: ticket } = await cstar.tickets.create({
61
+ const ticket = await cstar.tickets.create({
62
62
  title: 'Help with billing',
63
63
  customerId: 'cus_abc123'
64
64
  });
@@ -69,6 +69,8 @@ for await (const ticket of cstar.tickets.listAutoPaginating({ status: 'open' }))
69
69
  }
70
70
  ```
71
71
 
72
+ Created, retrieved and updated resources are returned directly. List methods return `{ data, pagination, hasMore }`. Search returns `{ results, total, query }`. Read `cstar.lastMeta.requestId` immediately after a call when you need its request ID.
73
+
72
74
  ### Full Resource Reference
73
75
 
74
76
  **Core Resources** — Tickets, customers, and knowledge base.
@@ -116,13 +118,17 @@ for await (const ticket of cstar.tickets.listAutoPaginating({ status: 'open' }))
116
118
  | `cstar.game.boss` | `.current()` `.isActive()` `.spawn(params?)` `.damage(params)` `.defeats(params?)` `.getDefeat(id)` |
117
119
  | `cstar.game.achievements` | `.list(params?)` `.unlocked(params)` `.get(id, params?)` |
118
120
  | `cstar.game.quests` | `.today(params?)` `.history(params?)` |
119
- | `cstar.game.puzzles` | `.today(params?)` `.complete(params)` `.streak(params)` `.leaderboard(params?)` |
121
+ | `cstar.game.puzzles` | `.today(params?)` `.complete(params)` `.streak(params)` `.leaderboard(params)` |
120
122
  | `cstar.game.oneUps` | `.list(params?)` `.send(params)` `.remaining(params)` |
121
123
  | `cstar.game.highFives` | `.list(params?)` `.send(params)` `.canSend(teamId, params)` |
122
- | `cstar.game.cosmetics` | `.list(params?)` `.getPreferences(params)` `.updatePreferences(params)` |
123
- | `cstar.game.seasons` | `.list()` `.current()` `.stats(seasonId, params)` |
124
+ | `cstar.game.cosmetics` | `.list(params)` `.getPreferences(params)` `.updatePreferences(params)` |
125
+ | `cstar.game.seasons` | `.list(params?)` `.current()` `.stats(seasonId, params)` |
124
126
  | `cstar.game.skills` | `.get(params)` `.allocate(params)` `.reset(params)` |
125
127
 
128
+ Game writes belong on your server with a secret API key. Use user and team UUIDs from cStar. One-ups and high fives default their sender to the key creator. Puzzle scoreboards require a `puzzleId`; streak boards use `{ type: 'streaks' }`. Cosmetic lists require a `userId`.
129
+
130
+ Cosmetic and season lists return `{ data, pagination, hasMore }`. One-up and high-five lists return `{ object: 'list', data }`. Today's quests return `{ quests, completedToday, totalQuests, allComplete, completionBonus, resetsAt }`. Single resources return bare objects.
131
+
126
132
  **Advanced** — AI, automations, views, billing, webhooks.
127
133
 
128
134
  | Resource | Methods |
@@ -140,20 +146,21 @@ for await (const ticket of cstar.tickets.listAutoPaginating({ status: 'open' }))
140
146
 
141
147
  ```typescript
142
148
  // Team analytics
143
- const { data: overview } = await cstar.analytics.overview({ period: 'week' });
144
- console.log(`${overview.tickets.open} open tickets this week`);
149
+ const overview = await cstar.analytics.overview({ period: 'week' });
150
+ console.log(`${overview.tickets?.open ?? 0} open tickets this week`);
145
151
 
146
152
  // SLA rules
147
153
  const { data: rules } = await cstar.sla.list();
148
154
 
149
- // Boss battle
150
- const { data: boss } = await cstar.game.boss.current();
151
- if (boss.active) {
152
- console.log(`${boss.name} — ${boss.health}/${boss.maxHealth} HP`);
153
- }
155
+ // Cheer on another team. The sender defaults to your API key's creator.
156
+ const highFive = await cstar.game.highFives.send({
157
+ recipientTeamId: '550e8400-e29b-41d4-a716-446655440003',
158
+ message: 'Amazing work!'
159
+ });
160
+ console.log(`A high five from ${highFive.senderTeam.name}`);
154
161
 
155
162
  // AI-powered reply suggestion
156
- const { data: suggestion } = await cstar.ai.suggestReply('tkt_abc123');
163
+ const suggestion = await cstar.ai.suggestReply('tkt_abc123');
157
164
 
158
165
  // Bulk close resolved tickets
159
166
  await cstar.bulk.update({
@@ -162,14 +169,19 @@ await cstar.bulk.update({
162
169
  data: { status: 'closed' }
163
170
  });
164
171
 
165
- // Export data
166
- const { data: exportResult } = await cstar.export.create({
167
- resources: [{ type: 'tickets', filters: { status: 'closed' } }],
168
- format: 'csv'
172
+ // Export closed tickets as JSON with raw rows and per-resource counts
173
+ const exported = await cstar.export.create({
174
+ resources: ['tickets'],
175
+ filters: { status: 'closed' },
176
+ format: 'json'
169
177
  });
178
+ console.log(exported.summary.tickets);
179
+
180
+ // CSV is text and supports one resource at a time
181
+ const csv = await cstar.export.create({ resources: ['tickets'], format: 'csv' });
170
182
 
171
183
  // Saved views
172
- const { data: view } = await cstar.views.create({
184
+ const view = await cstar.views.create({
173
185
  name: 'Urgent Unresolved',
174
186
  entityType: 'tickets',
175
187
  filters: { priority: 'urgent', status: 'open' }
@@ -177,7 +189,7 @@ const { data: view } = await cstar.views.create({
177
189
  const { data: results } = await cstar.views.execute(view.id);
178
190
 
179
191
  // Search across everything
180
- const { data: searchResults } = await cstar.search.query({
192
+ const { results: searchResults } = await cstar.search.query({
181
193
  query: 'billing issue',
182
194
  types: ['tickets', 'customers']
183
195
  });
@@ -443,7 +455,7 @@ try {
443
455
  Safely retry create/update operations:
444
456
 
445
457
  ```typescript
446
- const { data: ticket } = await cstar.tickets.create(
458
+ const ticket = await cstar.tickets.create(
447
459
  { title: 'Billing issue', customerId: 'cus_abc' },
448
460
  { idempotencyKey: 'create-billing-issue-usr123' }
449
461
  );
package/dist/index.cjs CHANGED
@@ -278,7 +278,7 @@ function parseError(statusCode, body, retryAfter) {
278
278
  }
279
279
 
280
280
  // src/client.ts
281
- var SDK_VERSION = "0.17.2";
281
+ var SDK_VERSION = "0.17.4";
282
282
  var DEFAULT_BASE_URL = "https://www.cstar.help";
283
283
  var DEFAULT_API_VERSION = "2026-03-01";
284
284
  var DEFAULT_MAX_RETRIES = 3;
@@ -384,8 +384,13 @@ var HttpClient = class {
384
384
  }
385
385
  if (response.ok) {
386
386
  if (response.status === 204) return void 0;
387
- const json = await response.json();
388
387
  const headerRequestId = response.headers.get("x-request-id") ?? response.headers.get("x-cstar-request-id");
388
+ if (options?.responseType === "text") {
389
+ const text = await response.text();
390
+ this.captureMeta(null, headerRequestId);
391
+ return text;
392
+ }
393
+ const json = await response.json();
389
394
  this.captureMeta(json, headerRequestId);
390
395
  return this.unwrapEnvelope(json);
391
396
  }
@@ -1495,11 +1500,9 @@ var QuickRepliesResource = class {
1495
1500
  }
1496
1501
  /** Reorder quick replies. */
1497
1502
  async reorder(orderedIds) {
1498
- return this.client.request(
1499
- "PUT",
1500
- "/settings/quick-replies/reorder",
1501
- { body: { orderedIds } }
1502
- );
1503
+ return this.client.request("PUT", "/settings/quick-replies/reorder", {
1504
+ body: { orderedIds }
1505
+ });
1503
1506
  }
1504
1507
  };
1505
1508
  var SettingsResource = class {
@@ -1673,9 +1676,13 @@ var CustomFieldsResource = class {
1673
1676
  }
1674
1677
  /** Reorder custom fields within a content type. */
1675
1678
  async reorder(contentType, orderedIds) {
1676
- return this.client.request("PUT", "/custom-fields/reorder", {
1677
- body: { contentType, orderedIds }
1678
- });
1679
+ return this.client.request(
1680
+ "PUT",
1681
+ "/custom-fields/reorder",
1682
+ {
1683
+ body: { contentType, orderedIds }
1684
+ }
1685
+ );
1679
1686
  }
1680
1687
  };
1681
1688
 
@@ -1810,11 +1817,11 @@ var ExportResource = class {
1810
1817
  constructor(client) {
1811
1818
  this.client = client;
1812
1819
  }
1813
- /** Create an export. Returns exported data synchronously. */
1814
1820
  async create(params, options) {
1815
1821
  return this.client.request("POST", "/export", {
1816
1822
  body: params,
1817
- idempotencyKey: options?.idempotencyKey
1823
+ idempotencyKey: options?.idempotencyKey,
1824
+ responseType: params.format === "csv" ? "text" : "json"
1818
1825
  });
1819
1826
  }
1820
1827
  };
@@ -1979,7 +1986,7 @@ var BossResource = class {
1979
1986
  /** List boss defeat history. */
1980
1987
  async defeats(params) {
1981
1988
  return this.client.request("GET", "/game/boss/defeats", {
1982
- query: params
1989
+ query: params ? { ...params } : void 0
1983
1990
  });
1984
1991
  }
1985
1992
  /** Get a single defeat record. */
@@ -1994,25 +2001,25 @@ var AchievementsResource = class {
1994
2001
  /** List all achievements with progress. `params.userId` is required. */
1995
2002
  async list(params) {
1996
2003
  return this.client.request("GET", "/game/achievements", {
1997
- query: params
2004
+ query: params ? { ...params } : void 0
1998
2005
  });
1999
2006
  }
2000
2007
  /** List unlocked achievements only. */
2001
2008
  async unlocked(params) {
2002
2009
  return this.client.request("GET", "/game/achievements/unlocked", {
2003
- query: params
2010
+ query: params ? { ...params } : void 0
2004
2011
  });
2005
2012
  }
2006
2013
  /** Get a single achievement. */
2007
2014
  async get(achievementId, params) {
2008
2015
  return this.client.request("GET", `/game/achievements/${achievementId}`, {
2009
- query: params
2016
+ query: params ? { ...params } : void 0
2010
2017
  });
2011
2018
  }
2012
2019
  /** Get recently unlocked achievements across the team. */
2013
2020
  async recent(params) {
2014
2021
  return this.client.request("GET", "/game/achievements/recent", {
2015
- query: params
2022
+ query: params ? { ...params } : void 0
2016
2023
  });
2017
2024
  }
2018
2025
  };
@@ -2023,13 +2030,13 @@ var GameActivityResource = class {
2023
2030
  /** Get the team activity feed. */
2024
2031
  async list(params) {
2025
2032
  return this.client.request("GET", "/game/activity", {
2026
- query: params
2033
+ query: params ? { ...params } : void 0
2027
2034
  });
2028
2035
  }
2029
2036
  /** Get activity for a specific member. */
2030
2037
  async forMember(memberId, params) {
2031
2038
  return this.client.request("GET", `/game/activity/member/${memberId}`, {
2032
- query: params
2039
+ query: params ? { ...params } : void 0
2033
2040
  });
2034
2041
  }
2035
2042
  };
@@ -2040,13 +2047,13 @@ var QuestsResource = class {
2040
2047
  /** Get today's quests. */
2041
2048
  async today(params) {
2042
2049
  return this.client.request("GET", "/game/quests/today", {
2043
- query: params
2050
+ query: params ? { ...params } : void 0
2044
2051
  });
2045
2052
  }
2046
2053
  /** Get quest history. */
2047
2054
  async history(params) {
2048
2055
  return this.client.request("GET", "/game/quests/history", {
2049
- query: params
2056
+ query: params ? { ...params } : void 0
2050
2057
  });
2051
2058
  }
2052
2059
  };
@@ -2057,10 +2064,10 @@ var PuzzlesResource = class {
2057
2064
  /** Get today's puzzle. */
2058
2065
  async today(params) {
2059
2066
  return this.client.request("GET", "/game/puzzles/today", {
2060
- query: params
2067
+ query: params ? { ...params } : void 0
2061
2068
  });
2062
2069
  }
2063
- /** Submit a puzzle answer. */
2070
+ /** Record a completed puzzle, its timing and result. */
2064
2071
  async complete(params, options) {
2065
2072
  return this.client.request("POST", "/game/puzzles/complete", {
2066
2073
  body: params,
@@ -2070,13 +2077,13 @@ var PuzzlesResource = class {
2070
2077
  /** Get puzzle streak for a user. */
2071
2078
  async streak(params) {
2072
2079
  return this.client.request("GET", "/game/puzzles/streak", {
2073
- query: params
2080
+ query: params ? { ...params } : void 0
2074
2081
  });
2075
2082
  }
2076
2083
  /** Get puzzle leaderboard. */
2077
2084
  async leaderboard(params) {
2078
2085
  return this.client.request("GET", "/game/puzzles/leaderboard", {
2079
- query: params
2086
+ query: params ? { ...params } : void 0
2080
2087
  });
2081
2088
  }
2082
2089
  };
@@ -2087,7 +2094,7 @@ var OneUpsResource = class {
2087
2094
  /** List one-ups. */
2088
2095
  async list(params) {
2089
2096
  return this.client.request("GET", "/game/one-ups", {
2090
- query: params
2097
+ query: params ? { ...params } : void 0
2091
2098
  });
2092
2099
  }
2093
2100
  /** Send a one-up. */
@@ -2100,7 +2107,7 @@ var OneUpsResource = class {
2100
2107
  /** Check remaining free one-ups today. */
2101
2108
  async remaining(params) {
2102
2109
  return this.client.request("GET", "/game/one-ups/remaining", {
2103
- query: params
2110
+ query: params ? { ...params } : void 0
2104
2111
  });
2105
2112
  }
2106
2113
  };
@@ -2111,7 +2118,7 @@ var HighFivesResource = class {
2111
2118
  /** List high fives. */
2112
2119
  async list(params) {
2113
2120
  return this.client.request("GET", "/game/high-fives", {
2114
- query: params
2121
+ query: params ? { ...params } : void 0
2115
2122
  });
2116
2123
  }
2117
2124
  /** Send a high five. */
@@ -2124,7 +2131,7 @@ var HighFivesResource = class {
2124
2131
  /** Check if you can send a high five to a team. */
2125
2132
  async canSend(recipientTeamId, params) {
2126
2133
  return this.client.request("GET", `/game/high-fives/can-send/${recipientTeamId}`, {
2127
- query: params
2134
+ query: params ? { ...params } : void 0
2128
2135
  });
2129
2136
  }
2130
2137
  };
@@ -2135,13 +2142,13 @@ var CosmeticsResource = class {
2135
2142
  /** List unlocked cosmetics. */
2136
2143
  async list(params) {
2137
2144
  return this.client.request("GET", "/game/cosmetics", {
2138
- query: params
2145
+ query: params ? { ...params } : void 0
2139
2146
  });
2140
2147
  }
2141
2148
  /** Get cosmetic preferences. */
2142
2149
  async getPreferences(params) {
2143
2150
  return this.client.request("GET", "/game/cosmetics/preferences", {
2144
- query: params
2151
+ query: params ? { ...params } : void 0
2145
2152
  });
2146
2153
  }
2147
2154
  /** Update cosmetic preferences. */
@@ -2154,8 +2161,10 @@ var SeasonsResource = class {
2154
2161
  this.client = client;
2155
2162
  }
2156
2163
  /** List all seasons. */
2157
- async list() {
2158
- return this.client.request("GET", "/game/seasons");
2164
+ async list(params) {
2165
+ return this.client.request("GET", "/game/seasons", {
2166
+ query: params ? { ...params } : void 0
2167
+ });
2159
2168
  }
2160
2169
  /** Get the current active season. */
2161
2170
  async current() {
@@ -2164,7 +2173,7 @@ var SeasonsResource = class {
2164
2173
  /** Get user stats for a season. */
2165
2174
  async stats(seasonId, params) {
2166
2175
  return this.client.request("GET", `/game/seasons/${seasonId}/stats`, {
2167
- query: params
2176
+ query: params ? { ...params } : void 0
2168
2177
  });
2169
2178
  }
2170
2179
  };
@@ -2175,7 +2184,7 @@ var SkillsResource = class {
2175
2184
  /** Get the skill tree with current allocations. */
2176
2185
  async get(params) {
2177
2186
  return this.client.request("GET", "/game/skills", {
2178
- query: params
2187
+ query: params ? { ...params } : void 0
2179
2188
  });
2180
2189
  }
2181
2190
  /** Allocate a skill point. */
@@ -2210,7 +2219,7 @@ var GameResource = class {
2210
2219
  /** Get current player stats. */
2211
2220
  async player(params) {
2212
2221
  return this.client.request("GET", "/game/player", {
2213
- query: params
2222
+ query: params ? { ...params } : void 0
2214
2223
  });
2215
2224
  }
2216
2225
  /** Get a specific player's stats by membership ID. */
@@ -2225,13 +2234,13 @@ var GameResource = class {
2225
2234
  */
2226
2235
  async leaderboard(params) {
2227
2236
  return this.client.request("GET", "/game/leaderboard", {
2228
- query: params
2237
+ query: params ? { ...params } : void 0
2229
2238
  });
2230
2239
  }
2231
2240
  /** Get the current user's leaderboard position. */
2232
2241
  async myRank(params) {
2233
2242
  return this.client.request("GET", "/game/leaderboard/me", {
2234
- query: params
2243
+ query: params ? { ...params } : void 0
2235
2244
  });
2236
2245
  }
2237
2246
  /** Get game balance configuration (read-only constants). */