@lpextend/node-sdk 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -184,6 +184,37 @@ var DomainResolver = class {
184
184
  account: this.accountId,
185
185
  service: "promptlibrary",
186
186
  baseURI: `${this.geo}.promptlibrary.liveperson.net`
187
+ },
188
+ // Conversation Builder domains (aliases for consistency with CB service naming)
189
+ {
190
+ account: this.accountId,
191
+ service: "cbBotPlatform",
192
+ baseURI: `${this.region}.bc-platform.liveperson.net`
193
+ },
194
+ {
195
+ account: this.accountId,
196
+ service: "cbIbc",
197
+ baseURI: `${this.region}.bc-nlu.liveperson.net`
198
+ },
199
+ {
200
+ account: this.accountId,
201
+ service: "cbKb",
202
+ baseURI: `${this.region}.bc-kb.liveperson.net`
203
+ },
204
+ {
205
+ account: this.accountId,
206
+ service: "cbMonitoring",
207
+ baseURI: `${this.region}.bc-mgmt.liveperson.net`
208
+ },
209
+ {
210
+ account: this.accountId,
211
+ service: "cbExternalIntegrations",
212
+ baseURI: `${this.region}.bc-intg.liveperson.net`
213
+ },
214
+ {
215
+ account: this.accountId,
216
+ service: "cbAiSearch",
217
+ baseURI: `${this.region}.kai.liveperson.net`
187
218
  }
188
219
  ];
189
220
  }
@@ -1688,6 +1719,425 @@ var LPPromptsAPI = class {
1688
1719
  }
1689
1720
  };
1690
1721
 
1722
+ // src/api/conversation-builder.api.ts
1723
+ var ConversationBuilderAPI = class {
1724
+ constructor(accountId, debug = false, timeout = 3e4) {
1725
+ this.accountId = accountId;
1726
+ this.credentials = null;
1727
+ this.domainResolver = new DomainResolver(accountId);
1728
+ this.debug = debug;
1729
+ this.timeout = timeout;
1730
+ this.botGroups = new BotGroupsAPI(this);
1731
+ this.bots = new BotsAPI(this);
1732
+ this.dialogs = new DialogsAPI(this);
1733
+ this.interactions = new InteractionsAPI(this);
1734
+ this.nluDomains = new NLUDomainsAPI(this);
1735
+ this.knowledgeBases = new KnowledgeBasesAPI(this);
1736
+ this.botAgents = new BotAgentsAPI(this);
1737
+ this.integrations = new IntegrationsAPI(this);
1738
+ }
1739
+ /**
1740
+ * Set CB authentication credentials
1741
+ * Must be called before making any CB API calls
1742
+ */
1743
+ setCredentials(credentials) {
1744
+ this.credentials = credentials;
1745
+ this.log("CB credentials set", { organizationId: credentials.organizationId });
1746
+ }
1747
+ /**
1748
+ * Check if credentials are set
1749
+ */
1750
+ hasCredentials() {
1751
+ return this.credentials !== null;
1752
+ }
1753
+ /**
1754
+ * Get the current credentials
1755
+ * @throws If credentials not set
1756
+ */
1757
+ getCredentials() {
1758
+ if (!this.credentials) {
1759
+ throw new LPExtendSDKError(
1760
+ "CB credentials not set. Call setCredentials() first or use sentinel.authenticateCB().",
1761
+ ErrorCodes.UNAUTHORIZED
1762
+ );
1763
+ }
1764
+ return this.credentials;
1765
+ }
1766
+ /**
1767
+ * Get the account ID
1768
+ */
1769
+ getAccountId() {
1770
+ return this.accountId;
1771
+ }
1772
+ /**
1773
+ * Get domain for a CB service
1774
+ */
1775
+ async getDomain(service) {
1776
+ const domain = await this.domainResolver.getDomain(service);
1777
+ if (!domain) {
1778
+ throw new LPExtendSDKError(
1779
+ `Could not resolve domain for CB service: ${service}`,
1780
+ ErrorCodes.API_ERROR
1781
+ );
1782
+ }
1783
+ return domain;
1784
+ }
1785
+ /**
1786
+ * Make authenticated request to CB API
1787
+ */
1788
+ async request(service, path, options = {}) {
1789
+ const { cbToken, organizationId } = this.getCredentials();
1790
+ const domain = await this.getDomain(service);
1791
+ const method = options.method || "GET";
1792
+ let url = `https://${domain}${path}`;
1793
+ if (options.params) {
1794
+ const searchParams = new URLSearchParams();
1795
+ Object.entries(options.params).forEach(([key, value]) => {
1796
+ if (value !== void 0) {
1797
+ searchParams.set(key, String(value));
1798
+ }
1799
+ });
1800
+ const paramString = searchParams.toString();
1801
+ if (paramString) {
1802
+ url += (url.includes("?") ? "&" : "?") + paramString;
1803
+ }
1804
+ }
1805
+ const headers = {
1806
+ "Accept": "application/json",
1807
+ "Content-Type": "application/json; charset=utf-8",
1808
+ "authorization": cbToken,
1809
+ "organizationid": organizationId
1810
+ };
1811
+ this.log(`${method} ${url}`, { service });
1812
+ const controller = new AbortController();
1813
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
1814
+ try {
1815
+ const response = await fetch(url, {
1816
+ method,
1817
+ headers,
1818
+ body: options.body ? JSON.stringify(options.body) : void 0,
1819
+ signal: controller.signal
1820
+ });
1821
+ clearTimeout(timeoutId);
1822
+ if (!response.ok) {
1823
+ const errorBody = await response.json().catch(() => ({ message: "Unknown error" }));
1824
+ throw new LPExtendSDKError(
1825
+ `CB API Error: ${response.status} - ${errorBody.message || response.statusText}`,
1826
+ ErrorCodes.API_ERROR,
1827
+ response.status,
1828
+ errorBody
1829
+ );
1830
+ }
1831
+ const contentType = response.headers.get("content-type");
1832
+ if (!contentType?.includes("application/json") || response.status === 204) {
1833
+ return void 0;
1834
+ }
1835
+ return await response.json();
1836
+ } catch (error) {
1837
+ clearTimeout(timeoutId);
1838
+ if (error.name === "AbortError") {
1839
+ throw new LPExtendSDKError("CB API request timeout", ErrorCodes.TIMEOUT);
1840
+ }
1841
+ if (error instanceof LPExtendSDKError) {
1842
+ throw error;
1843
+ }
1844
+ throw new LPExtendSDKError(
1845
+ `CB API request failed: ${error.message}`,
1846
+ ErrorCodes.API_ERROR
1847
+ );
1848
+ }
1849
+ }
1850
+ /**
1851
+ * Debug logging
1852
+ */
1853
+ log(...args) {
1854
+ if (this.debug) {
1855
+ console.log("[LP-Extend-SDK:CB]", ...args);
1856
+ }
1857
+ }
1858
+ };
1859
+ var BotGroupsAPI = class {
1860
+ constructor(cb) {
1861
+ this.cb = cb;
1862
+ }
1863
+ /**
1864
+ * Get all bot groups
1865
+ */
1866
+ async getAll(params) {
1867
+ const queryParams = {};
1868
+ if (params?.expandAll) {
1869
+ queryParams["expand-all"] = true;
1870
+ } else {
1871
+ queryParams.page = params?.page ?? 1;
1872
+ queryParams.size = params?.size ?? 100;
1873
+ }
1874
+ return this.cb.request("cbBotPlatform", "/bot-groups", { params: queryParams });
1875
+ }
1876
+ /**
1877
+ * Get bots by group
1878
+ */
1879
+ async getBots(params) {
1880
+ const queryParams = {
1881
+ "sort-by": params?.sortBy ?? "botName:asc",
1882
+ page: params?.page ?? 1,
1883
+ size: params?.size ?? 10,
1884
+ "bot-group-id": params?.botGroupId ?? "un_assigned"
1885
+ };
1886
+ return this.cb.request("cbBotPlatform", "/bot-groups/bots", { params: queryParams });
1887
+ }
1888
+ };
1889
+ var BotsAPI = class {
1890
+ constructor(cb) {
1891
+ this.cb = cb;
1892
+ }
1893
+ /**
1894
+ * Get all bots (legacy chatbots endpoint)
1895
+ */
1896
+ async getAll() {
1897
+ return this.cb.request("botPlatform", "/bot-platform-manager-0.1/chatbots");
1898
+ }
1899
+ /**
1900
+ * Get chatbot by ID
1901
+ */
1902
+ async getById(chatBotId) {
1903
+ return this.cb.request("cbBotPlatform", "/chatbots", {
1904
+ params: { chatBotId }
1905
+ });
1906
+ }
1907
+ /**
1908
+ * Get global functions for a bot
1909
+ */
1910
+ async getGlobalFunctions(botId) {
1911
+ return this.cb.request("cbBotPlatform", `/bot/${botId}/globalFunctions`);
1912
+ }
1913
+ /**
1914
+ * Get LP app credentials for a bot
1915
+ */
1916
+ async getLPAppCredentials(chatBotId) {
1917
+ return this.cb.request("cbBotPlatform", "/auth/liveperson/app", {
1918
+ params: { chatBotId }
1919
+ });
1920
+ }
1921
+ /**
1922
+ * Get bot environment variables
1923
+ */
1924
+ async getEnvironment() {
1925
+ const data = await this.cb.request("cbBotPlatform", "/auth/botenvironment/");
1926
+ if (Array.isArray(data)) {
1927
+ return { success: true, successResult: data };
1928
+ }
1929
+ return data;
1930
+ }
1931
+ };
1932
+ var DialogsAPI = class {
1933
+ constructor(cb) {
1934
+ this.cb = cb;
1935
+ }
1936
+ /**
1937
+ * Get all dialogs for a bot
1938
+ */
1939
+ async getByBotId(botId) {
1940
+ return this.cb.request("cbBotPlatform", `/bots/${botId}/dialog/`);
1941
+ }
1942
+ /**
1943
+ * Get dialog template summaries
1944
+ */
1945
+ async getTemplateSummary() {
1946
+ return this.cb.request("cbBotPlatform", "/dialog/template/summary");
1947
+ }
1948
+ };
1949
+ var InteractionsAPI = class {
1950
+ constructor(cb) {
1951
+ this.cb = cb;
1952
+ }
1953
+ /**
1954
+ * Get all interactions for a bot
1955
+ */
1956
+ async getByBotId(botId) {
1957
+ return this.cb.request("cbBotPlatform", `/chat/${botId}/interaction/`);
1958
+ }
1959
+ };
1960
+ var NLUDomainsAPI = class {
1961
+ constructor(cb) {
1962
+ this.cb = cb;
1963
+ }
1964
+ /**
1965
+ * Get all NLU domains for the organization
1966
+ */
1967
+ async getAll() {
1968
+ return this.cb.request("cbIbc", "/api/cb/nlu/v1/domains/getByOrgId");
1969
+ }
1970
+ /**
1971
+ * Get intents for a domain
1972
+ */
1973
+ async getIntents(domainId) {
1974
+ const data = await this.cb.request("cbIbc", `/api/cb/nlu/v1/domains/${domainId}/intents`);
1975
+ if (Array.isArray(data)) {
1976
+ return { success: true, successResult: data };
1977
+ }
1978
+ return data;
1979
+ }
1980
+ };
1981
+ var KnowledgeBasesAPI = class {
1982
+ constructor(cb) {
1983
+ this.cb = cb;
1984
+ }
1985
+ /**
1986
+ * Get all knowledge bases
1987
+ */
1988
+ async getAll(includeMetrics = true) {
1989
+ return this.cb.request("cbKb", "/knowledgeDataSource", {
1990
+ params: { includeMetrics }
1991
+ });
1992
+ }
1993
+ /**
1994
+ * Get knowledge base by ID
1995
+ */
1996
+ async getById(kbId, includeMetrics = true) {
1997
+ return this.cb.request("cbKb", `/knowledgeDataSource/${kbId}`, {
1998
+ params: { includeMetrics }
1999
+ });
2000
+ }
2001
+ /**
2002
+ * Get content sources for a knowledge base
2003
+ */
2004
+ async getContentSources(kbId, includeKmsRecipeDetails = true) {
2005
+ return this.cb.request("cbKb", `/kb/${kbId}/content_sources`, {
2006
+ params: { includeKmsRecipeDetails }
2007
+ });
2008
+ }
2009
+ /**
2010
+ * Get articles for a knowledge base
2011
+ */
2012
+ async getArticles(kbId, params) {
2013
+ const body = {
2014
+ page: params?.page ?? 1,
2015
+ size: params?.size ?? 20,
2016
+ sortAscByLastModificationTime: params?.sortAscByLastModificationTime ?? false,
2017
+ articleIds: params?.articleIds ?? []
2018
+ };
2019
+ return this.cb.request("cbKb", `/kb/${kbId}/articles`, {
2020
+ method: "POST",
2021
+ body,
2022
+ params: { includeConflictingDetails: params?.includeConflictingDetails ?? true }
2023
+ });
2024
+ }
2025
+ /**
2026
+ * Search knowledge base using KAI
2027
+ */
2028
+ async search(kbId, searchRequest) {
2029
+ try {
2030
+ return await this.cb.request("cbAiSearch", `/v1/account/${this.cb.getAccountId()}/kb/${kbId}/search`, {
2031
+ method: "POST",
2032
+ body: searchRequest
2033
+ });
2034
+ } catch {
2035
+ return this.cb.request("cbKb", `/kb/${kbId}/search`, {
2036
+ method: "POST",
2037
+ body: searchRequest
2038
+ });
2039
+ }
2040
+ }
2041
+ /**
2042
+ * Get KAI On-Demand configurations
2043
+ */
2044
+ async getOnDemandConfigs() {
2045
+ return this.cb.request("cbKb", "/on-demand/configs");
2046
+ }
2047
+ /**
2048
+ * Get default prompt for KAI
2049
+ */
2050
+ async getDefaultPrompt() {
2051
+ return this.cb.request("cbKb", "/default-prompt");
2052
+ }
2053
+ };
2054
+ var BotAgentsAPI = class {
2055
+ constructor(cb) {
2056
+ this.cb = cb;
2057
+ }
2058
+ /**
2059
+ * Get bot instance status
2060
+ */
2061
+ async getInstanceStatus(botId) {
2062
+ return this.cb.request("cbMonitoring", `/sysadmin/nodejs/instance/status-v2/${botId}`);
2063
+ }
2064
+ /**
2065
+ * Start a bot agent
2066
+ */
2067
+ async start(botId, lpAccountId, lpAccountUser) {
2068
+ return this.cb.request("cbMonitoring", `/sysadmin/nodejs/instance/start/${botId}`, {
2069
+ method: "PUT",
2070
+ body: { lpAccountId, lpAccountUser }
2071
+ });
2072
+ }
2073
+ /**
2074
+ * Stop a bot agent
2075
+ */
2076
+ async stop(botId, lpAccountId, lpAccountUser) {
2077
+ return this.cb.request("cbMonitoring", `/sysadmin/nodejs/instance/stop/${botId}`, {
2078
+ method: "PUT",
2079
+ body: { lpAccountId, lpAccountUser }
2080
+ });
2081
+ }
2082
+ /**
2083
+ * Get all bot agents status
2084
+ */
2085
+ async getAllStatus(params) {
2086
+ return this.cb.request("cbMonitoring", "/sysadmin/nodejs/instance/status", {
2087
+ params: { environment: params?.environment ?? "PRODUCTION" }
2088
+ });
2089
+ }
2090
+ /**
2091
+ * Get PCS bots status
2092
+ */
2093
+ async getPCSStatus(params) {
2094
+ return this.cb.request("cbMonitoring", "/sysadmin/nodejs/instance/pcs/status", {
2095
+ params: { showBotsData: params?.showBotsData ?? true }
2096
+ });
2097
+ }
2098
+ /**
2099
+ * Get bot users
2100
+ */
2101
+ async getBotUsers() {
2102
+ return this.cb.request("cbExternalIntegrations", `/live-engage-service-0.1/le/accounts/${this.cb.getAccountId()}/bot_users`);
2103
+ }
2104
+ /**
2105
+ * Add a bot agent
2106
+ */
2107
+ async addAgent(lpUserId, chatBotId, request) {
2108
+ return this.cb.request("cbExternalIntegrations", `/live-engage-service-0.1/le/accounts/${this.cb.getAccountId()}/bot_users/${lpUserId}`, {
2109
+ method: "POST",
2110
+ body: request,
2111
+ params: { chatBotId }
2112
+ });
2113
+ }
2114
+ };
2115
+ var IntegrationsAPI = class {
2116
+ constructor(cb) {
2117
+ this.cb = cb;
2118
+ }
2119
+ /**
2120
+ * Get responders for a chatbot
2121
+ */
2122
+ async getResponders(chatBotId) {
2123
+ return this.cb.request("cbBotPlatform", "/responder", {
2124
+ params: { chatBotId }
2125
+ });
2126
+ }
2127
+ /**
2128
+ * Get LP skills
2129
+ */
2130
+ async getLPSkills() {
2131
+ return this.cb.request("cbExternalIntegrations", `/live-engage-service-0.1/le/accounts/${this.cb.getAccountId()}/skills`);
2132
+ }
2133
+ /**
2134
+ * Get credentials
2135
+ */
2136
+ async getCredentials() {
2137
+ return this.cb.request("cbExternalIntegrations", "/auth-service-0.1/credentials");
2138
+ }
2139
+ };
2140
+
1691
2141
  // src/sdk.ts
1692
2142
  var LPExtendSDK = class {
1693
2143
  /**
@@ -1720,6 +2170,7 @@ var LPExtendSDK = class {
1720
2170
  this.messaging = new MessagingAPI(this.http);
1721
2171
  this.sentinel = new SentinelAPI(this.http);
1722
2172
  this.prompts = new LPPromptsAPI(this.http);
2173
+ this.conversationBuilder = new ConversationBuilderAPI(config.accountId, this.debug, timeout);
1723
2174
  this.log("SDK initialized with scopes:", this.grantedScopes);
1724
2175
  }
1725
2176
  /**
@@ -1768,9 +2219,9 @@ async function createSDK(config) {
1768
2219
  if (!config.accountId) {
1769
2220
  throw new LPExtendSDKError("accountId is required", ErrorCodes.INVALID_CONFIG);
1770
2221
  }
1771
- if (!config.accessToken && !config.extendToken && !config.shellToken) {
2222
+ if (!config.accessToken && !config.extendToken && !config.shellToken && !config.apiKey) {
1772
2223
  throw new LPExtendSDKError(
1773
- "Either accessToken, extendToken, or shellToken is required",
2224
+ "Either accessToken, apiKey, extendToken, or shellToken is required",
1774
2225
  ErrorCodes.INVALID_CONFIG
1775
2226
  );
1776
2227
  }
@@ -1778,7 +2229,9 @@ async function createSDK(config) {
1778
2229
  const timeout = config.timeout ?? 3e4;
1779
2230
  let shellBaseUrl = config.shellBaseUrl;
1780
2231
  if (!shellBaseUrl) {
1781
- if (typeof window !== "undefined") {
2232
+ if (typeof process !== "undefined" && process.env?.LPEXTEND_SHELL_URL) {
2233
+ shellBaseUrl = process.env.LPEXTEND_SHELL_URL;
2234
+ } else if (typeof window !== "undefined") {
1782
2235
  try {
1783
2236
  if (window.self !== window.top && document.referrer) {
1784
2237
  const url = new URL(document.referrer);
@@ -1787,15 +2240,109 @@ async function createSDK(config) {
1787
2240
  } catch {
1788
2241
  }
1789
2242
  shellBaseUrl = shellBaseUrl || window.location.origin;
1790
- } else {
2243
+ } else if (config.apiKey || config.extendToken || config.shellToken) {
1791
2244
  throw new LPExtendSDKError(
1792
- "shellBaseUrl is required in non-browser environments",
2245
+ "shellBaseUrl is required when using apiKey, extendToken, or shellToken in non-browser environments. Set LPEXTEND_SHELL_URL environment variable or pass shellBaseUrl in config.",
1793
2246
  ErrorCodes.INVALID_CONFIG
1794
2247
  );
1795
2248
  }
1796
2249
  }
1797
2250
  let accessToken = config.accessToken;
1798
- if (!accessToken && config.extendToken) {
2251
+ if (!accessToken && config.apiKey && config.extendToken) {
2252
+ const verifyUrl = `${shellBaseUrl}/api/v1/apps/verify`;
2253
+ if (debug) {
2254
+ console.log("[LP-Extend-SDK] Verifying ExtendJWT with API key");
2255
+ console.log("[LP-Extend-SDK] Shell URL:", shellBaseUrl);
2256
+ console.log("[LP-Extend-SDK] Verify URL:", verifyUrl);
2257
+ console.log("[LP-Extend-SDK] API Key:", config.apiKey.substring(0, 20) + "...");
2258
+ console.log("[LP-Extend-SDK] ExtendToken length:", config.extendToken.length);
2259
+ }
2260
+ const authController = new AbortController();
2261
+ const authTimeoutId = setTimeout(() => authController.abort(), timeout);
2262
+ try {
2263
+ const authResponse = await fetch(verifyUrl, {
2264
+ method: "POST",
2265
+ headers: {
2266
+ "Content-Type": "application/json",
2267
+ "X-LPExtend-API-Key": config.apiKey
2268
+ },
2269
+ body: JSON.stringify({
2270
+ token: config.extendToken
2271
+ }),
2272
+ signal: authController.signal
2273
+ });
2274
+ clearTimeout(authTimeoutId);
2275
+ if (!authResponse.ok) {
2276
+ const errorData = await authResponse.json().catch(() => ({}));
2277
+ if (authResponse.status === 401) {
2278
+ throw new LPExtendSDKError(
2279
+ errorData.message || "Invalid API key or ExtendJWT",
2280
+ ErrorCodes.UNAUTHORIZED,
2281
+ authResponse.status,
2282
+ errorData
2283
+ );
2284
+ }
2285
+ if (authResponse.status === 403) {
2286
+ throw new LPExtendSDKError(
2287
+ errorData.message || "App not authorized for this account",
2288
+ ErrorCodes.APP_NOT_REGISTERED,
2289
+ authResponse.status,
2290
+ errorData
2291
+ );
2292
+ }
2293
+ throw new LPExtendSDKError(
2294
+ errorData.message || `Token verification failed: ${authResponse.status}`,
2295
+ ErrorCodes.API_ERROR,
2296
+ authResponse.status,
2297
+ errorData
2298
+ );
2299
+ }
2300
+ const authData = await authResponse.json();
2301
+ accessToken = authData.lpAccessToken;
2302
+ if (debug) {
2303
+ console.log("[LP-Extend-SDK] ExtendJWT verified with API key");
2304
+ console.log("[LP-Extend-SDK] User:", authData.user?.lpUserId, "Account:", authData.user?.lpAccountId);
2305
+ console.log("[LP-Extend-SDK] Allowed APIs:", authData.allowedApis);
2306
+ }
2307
+ const resolvedConfig = { ...config, accessToken };
2308
+ const initResult = {
2309
+ appId: config.appId,
2310
+ accountId: authData.user?.lpAccountId || config.accountId,
2311
+ grantedScopes: authData.allowedApis || [],
2312
+ appName: config.appId,
2313
+ version: "1.0.0"
2314
+ };
2315
+ return new LPExtendSDK(resolvedConfig, initResult);
2316
+ } catch (error) {
2317
+ clearTimeout(authTimeoutId);
2318
+ if (debug) {
2319
+ console.error("[LP-Extend-SDK] ExtendJWT verification error:", {
2320
+ name: error.name,
2321
+ message: error.message,
2322
+ cause: error.cause?.message || error.cause,
2323
+ verifyUrl
2324
+ });
2325
+ }
2326
+ if (error instanceof LPExtendSDKError) {
2327
+ throw error;
2328
+ }
2329
+ if (error.name === "AbortError") {
2330
+ throw new LPExtendSDKError("Token verification timeout", ErrorCodes.TIMEOUT);
2331
+ }
2332
+ const errorMessage = error.cause?.message || error.message;
2333
+ throw new LPExtendSDKError(
2334
+ `ExtendJWT verification failed: ${errorMessage}`,
2335
+ ErrorCodes.INIT_FAILED
2336
+ );
2337
+ }
2338
+ }
2339
+ if (!accessToken && config.apiKey && !config.extendToken) {
2340
+ throw new LPExtendSDKError(
2341
+ "API key authentication requires extendToken. The ExtendJWT is passed from the shell to your app when opened in an iframe.",
2342
+ ErrorCodes.INVALID_CONFIG
2343
+ );
2344
+ }
2345
+ if (!accessToken && config.extendToken && !config.apiKey) {
1799
2346
  if (debug) {
1800
2347
  console.log("[LP-Extend-SDK] Verifying ExtendJWT with shell");
1801
2348
  }
@@ -1838,6 +2385,20 @@ async function createSDK(config) {
1838
2385
  console.log("[LP-Extend-SDK] ExtendJWT verified, got LP access token");
1839
2386
  console.log("[LP-Extend-SDK] User:", authData.lpUserId, "Account:", authData.lpAccountId);
1840
2387
  }
2388
+ const grantedScopes = config.scopes || ["*"];
2389
+ if (debug) {
2390
+ console.log("[LP-Extend-SDK] ExtendJWT auth grants all scopes:", grantedScopes);
2391
+ console.log("[LP-Extend-SDK] SDK will call LP APIs directly");
2392
+ }
2393
+ const resolvedConfig = { ...config, accessToken };
2394
+ const initResult = {
2395
+ appId: config.appId,
2396
+ accountId: config.accountId,
2397
+ grantedScopes,
2398
+ appName: config.appId,
2399
+ version: "1.0.0"
2400
+ };
2401
+ return new LPExtendSDK(resolvedConfig, initResult);
1841
2402
  } catch (error) {
1842
2403
  clearTimeout(extendTimeoutId);
1843
2404
  if (error instanceof LPExtendSDKError) {
@@ -2002,6 +2563,51 @@ async function createSDK(config) {
2002
2563
  async function initializeSDK(config) {
2003
2564
  return createSDK(config);
2004
2565
  }
2566
+ async function createSDKFromEnv(extendToken) {
2567
+ const apiKey = process.env.LPEXTEND_API_KEY;
2568
+ const appId = process.env.APP_ID;
2569
+ const accountId = process.env.LP_ACCOUNT_ID;
2570
+ const shellBaseUrl = process.env.LPEXTEND_SHELL_URL;
2571
+ const debug = process.env.LPEXTEND_DEBUG === "true";
2572
+ if (!apiKey) {
2573
+ throw new LPExtendSDKError(
2574
+ "LPEXTEND_API_KEY environment variable is required",
2575
+ ErrorCodes.INVALID_CONFIG
2576
+ );
2577
+ }
2578
+ if (!appId) {
2579
+ throw new LPExtendSDKError(
2580
+ "APP_ID environment variable is required",
2581
+ ErrorCodes.INVALID_CONFIG
2582
+ );
2583
+ }
2584
+ if (!accountId) {
2585
+ throw new LPExtendSDKError(
2586
+ "LP_ACCOUNT_ID environment variable is required",
2587
+ ErrorCodes.INVALID_CONFIG
2588
+ );
2589
+ }
2590
+ if (!shellBaseUrl) {
2591
+ throw new LPExtendSDKError(
2592
+ "LPEXTEND_SHELL_URL environment variable is required",
2593
+ ErrorCodes.INVALID_CONFIG
2594
+ );
2595
+ }
2596
+ if (!extendToken) {
2597
+ throw new LPExtendSDKError(
2598
+ "extendToken is required. This is passed from the shell to your app when opened.",
2599
+ ErrorCodes.INVALID_CONFIG
2600
+ );
2601
+ }
2602
+ return createSDK({
2603
+ appId,
2604
+ accountId,
2605
+ apiKey,
2606
+ extendToken,
2607
+ shellBaseUrl,
2608
+ debug
2609
+ });
2610
+ }
2005
2611
  var VERSION = "1.0.0";
2006
2612
  var Scopes = {
2007
2613
  // Account Configuration
@@ -2123,15 +2729,23 @@ exports.AgentActivityAPI = AgentActivityAPI;
2123
2729
  exports.AgentGroupsAPI = AgentGroupsAPI;
2124
2730
  exports.AgentMetricsAPI = AgentMetricsAPI;
2125
2731
  exports.AutomaticMessagesAPI = AutomaticMessagesAPI;
2732
+ exports.BotAgentsAPI = BotAgentsAPI;
2733
+ exports.BotGroupsAPI = BotGroupsAPI;
2734
+ exports.BotsAPI = BotsAPI;
2126
2735
  exports.CampaignsAPI = CampaignsAPI;
2127
2736
  exports.CategoriesAPI = CategoriesAPI;
2128
2737
  exports.ConnectToMessagingAPI = ConnectToMessagingAPI;
2738
+ exports.ConversationBuilderAPI = ConversationBuilderAPI;
2129
2739
  exports.ConversationsAPI = ConversationsAPI;
2740
+ exports.DialogsAPI = DialogsAPI;
2130
2741
  exports.EngagementsAPI = EngagementsAPI;
2131
2742
  exports.ErrorCodes = ErrorCodes;
2132
2743
  exports.EvaluatorsAPI = EvaluatorsAPI;
2133
2744
  exports.FlowsAPI = FlowsAPI;
2134
2745
  exports.GeneratorsAPI = GeneratorsAPI;
2746
+ exports.IntegrationsAPI = IntegrationsAPI;
2747
+ exports.InteractionsAPI = InteractionsAPI;
2748
+ exports.KnowledgeBasesAPI = KnowledgeBasesAPI;
2135
2749
  exports.KnowledgebasesAPI = KnowledgebasesAPI;
2136
2750
  exports.LOBsAPI = LOBsAPI;
2137
2751
  exports.LPExtendSDK = LPExtendSDK;
@@ -2140,6 +2754,7 @@ exports.LPPromptsAPI = LPPromptsAPI;
2140
2754
  exports.MessagingAPI = MessagingAPI;
2141
2755
  exports.MessagingHistoryAPI = MessagingHistoryAPI;
2142
2756
  exports.MessagingOperationsAPI = MessagingOperationsAPI;
2757
+ exports.NLUDomainsAPI = NLUDomainsAPI;
2143
2758
  exports.OutboundReportingAPI = OutboundReportingAPI;
2144
2759
  exports.PredefinedContentAPI = PredefinedContentAPI;
2145
2760
  exports.ProfilesAPI = ProfilesAPI;
@@ -2156,6 +2771,7 @@ exports.UsersAPI = UsersAPI;
2156
2771
  exports.VERSION = VERSION;
2157
2772
  exports.WorkingHoursAPI = WorkingHoursAPI;
2158
2773
  exports.createSDK = createSDK;
2774
+ exports.createSDKFromEnv = createSDKFromEnv;
2159
2775
  exports.getShellToken = getShellToken;
2160
2776
  exports.initializeSDK = initializeSDK;
2161
2777
  //# sourceMappingURL=index.js.map