@lpextend/node-sdk 1.1.2 → 1.1.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/dist/index.d.mts +1130 -10
- package/dist/index.d.ts +1130 -10
- package/dist/index.js +721 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +712 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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,524 @@ 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
|
+
* Get consumer query metrics for a knowledge base
|
|
2055
|
+
*
|
|
2056
|
+
* Retrieves answered and/or unanswered query metrics within a date range.
|
|
2057
|
+
* Note: The API only supports 7-day ranges. For longer ranges, use getConsumerQueryMetricsExtended().
|
|
2058
|
+
*
|
|
2059
|
+
* @param params - Query parameters including kbId, startTime, endTime, and eventType
|
|
2060
|
+
* @returns Promise resolving to consumer query metrics
|
|
2061
|
+
*
|
|
2062
|
+
* @example
|
|
2063
|
+
* ```typescript
|
|
2064
|
+
* const metrics = await sdk.conversationBuilder.knowledgeBases.getConsumerQueryMetrics({
|
|
2065
|
+
* kbId: 'kb-123',
|
|
2066
|
+
* startTime: Date.now() - 7 * 24 * 60 * 60 * 1000, // 7 days ago
|
|
2067
|
+
* endTime: Date.now(),
|
|
2068
|
+
* eventType: ['EVENT_KB_UN_ANSWERED'],
|
|
2069
|
+
* });
|
|
2070
|
+
* ```
|
|
2071
|
+
*/
|
|
2072
|
+
async getConsumerQueryMetrics(params) {
|
|
2073
|
+
const body = {
|
|
2074
|
+
startTime: String(params.startTime),
|
|
2075
|
+
endTime: String(params.endTime),
|
|
2076
|
+
eventType: params.eventType,
|
|
2077
|
+
kbId: params.kbId
|
|
2078
|
+
};
|
|
2079
|
+
return this.cb.request("cbKb", "/kb/consumerQueryMetrics", {
|
|
2080
|
+
method: "POST",
|
|
2081
|
+
body
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
/**
|
|
2085
|
+
* Get consumer query metrics for extended date ranges (up to 3 months)
|
|
2086
|
+
*
|
|
2087
|
+
* Automatically iterates through 7-day chunks to retrieve all metrics within
|
|
2088
|
+
* the specified date range. Useful for historical analysis beyond the 7-day API limit.
|
|
2089
|
+
*
|
|
2090
|
+
* @param params - Extended query parameters including startDate, endDate, kbId, and eventType
|
|
2091
|
+
* @returns Promise resolving to aggregated consumer query metrics from all chunks
|
|
2092
|
+
*
|
|
2093
|
+
* @example
|
|
2094
|
+
* ```typescript
|
|
2095
|
+
* const metrics = await sdk.conversationBuilder.knowledgeBases.getConsumerQueryMetricsExtended({
|
|
2096
|
+
* kbId: 'kb-123',
|
|
2097
|
+
* startDate: new Date('2024-01-01'),
|
|
2098
|
+
* endDate: new Date('2024-03-01'),
|
|
2099
|
+
* eventType: ['EVENT_KB_ANSWERED', 'EVENT_KB_UN_ANSWERED'],
|
|
2100
|
+
* onProgress: (completed, total) => console.log(`${completed}/${total} chunks processed`),
|
|
2101
|
+
* });
|
|
2102
|
+
* ```
|
|
2103
|
+
*/
|
|
2104
|
+
async getConsumerQueryMetricsExtended(params) {
|
|
2105
|
+
const { startDate, endDate, eventType, kbId, onProgress } = params;
|
|
2106
|
+
const startMs = typeof startDate === "number" ? startDate : startDate.getTime();
|
|
2107
|
+
const endMs = typeof endDate === "number" ? endDate : endDate.getTime();
|
|
2108
|
+
const maxRangeMs = 90 * 24 * 60 * 60 * 1e3;
|
|
2109
|
+
if (endMs - startMs > maxRangeMs) {
|
|
2110
|
+
throw new LPExtendSDKError(
|
|
2111
|
+
"Date range exceeds maximum of 90 days. Please use a smaller range.",
|
|
2112
|
+
ErrorCodes.INVALID_CONFIG
|
|
2113
|
+
);
|
|
2114
|
+
}
|
|
2115
|
+
const chunkSizeMs = 7 * 24 * 60 * 60 * 1e3;
|
|
2116
|
+
const chunks = [];
|
|
2117
|
+
let chunkStart = startMs;
|
|
2118
|
+
while (chunkStart < endMs) {
|
|
2119
|
+
const chunkEnd = Math.min(chunkStart + chunkSizeMs, endMs);
|
|
2120
|
+
chunks.push({ start: chunkStart, end: chunkEnd });
|
|
2121
|
+
chunkStart = chunkEnd;
|
|
2122
|
+
}
|
|
2123
|
+
const allMetrics = [];
|
|
2124
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
2125
|
+
const chunk = chunks[i];
|
|
2126
|
+
try {
|
|
2127
|
+
const response = await this.getConsumerQueryMetrics({
|
|
2128
|
+
kbId,
|
|
2129
|
+
startTime: chunk.start,
|
|
2130
|
+
endTime: chunk.end,
|
|
2131
|
+
eventType
|
|
2132
|
+
});
|
|
2133
|
+
if (response.data && Array.isArray(response.data)) {
|
|
2134
|
+
allMetrics.push(...response.data);
|
|
2135
|
+
}
|
|
2136
|
+
} catch (error) {
|
|
2137
|
+
console.warn(`Failed to fetch metrics for chunk ${i + 1}/${chunks.length}:`, error);
|
|
2138
|
+
}
|
|
2139
|
+
if (onProgress) {
|
|
2140
|
+
onProgress(i + 1, chunks.length);
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2144
|
+
const uniqueMetrics = allMetrics.filter((metric) => {
|
|
2145
|
+
const key = metric.id || `${metric.consumerQuery}-${metric.timestamp}`;
|
|
2146
|
+
if (seen.has(key)) return false;
|
|
2147
|
+
seen.add(key);
|
|
2148
|
+
return true;
|
|
2149
|
+
});
|
|
2150
|
+
return uniqueMetrics;
|
|
2151
|
+
}
|
|
2152
|
+
};
|
|
2153
|
+
var BotAgentsAPI = class {
|
|
2154
|
+
constructor(cb) {
|
|
2155
|
+
this.cb = cb;
|
|
2156
|
+
}
|
|
2157
|
+
/**
|
|
2158
|
+
* Get bot instance status
|
|
2159
|
+
*/
|
|
2160
|
+
async getInstanceStatus(botId) {
|
|
2161
|
+
return this.cb.request("cbMonitoring", `/sysadmin/nodejs/instance/status-v2/${botId}`);
|
|
2162
|
+
}
|
|
2163
|
+
/**
|
|
2164
|
+
* Start a bot agent
|
|
2165
|
+
*/
|
|
2166
|
+
async start(botId, lpAccountId, lpAccountUser) {
|
|
2167
|
+
return this.cb.request("cbMonitoring", `/sysadmin/nodejs/instance/start/${botId}`, {
|
|
2168
|
+
method: "PUT",
|
|
2169
|
+
body: { lpAccountId, lpAccountUser }
|
|
2170
|
+
});
|
|
2171
|
+
}
|
|
2172
|
+
/**
|
|
2173
|
+
* Stop a bot agent
|
|
2174
|
+
*/
|
|
2175
|
+
async stop(botId, lpAccountId, lpAccountUser) {
|
|
2176
|
+
return this.cb.request("cbMonitoring", `/sysadmin/nodejs/instance/stop/${botId}`, {
|
|
2177
|
+
method: "PUT",
|
|
2178
|
+
body: { lpAccountId, lpAccountUser }
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
/**
|
|
2182
|
+
* Get all bot agents status
|
|
2183
|
+
*/
|
|
2184
|
+
async getAllStatus(params) {
|
|
2185
|
+
return this.cb.request("cbMonitoring", "/sysadmin/nodejs/instance/status", {
|
|
2186
|
+
params: { environment: params?.environment ?? "PRODUCTION" }
|
|
2187
|
+
});
|
|
2188
|
+
}
|
|
2189
|
+
/**
|
|
2190
|
+
* Get PCS bots status
|
|
2191
|
+
*/
|
|
2192
|
+
async getPCSStatus(params) {
|
|
2193
|
+
return this.cb.request("cbMonitoring", "/sysadmin/nodejs/instance/pcs/status", {
|
|
2194
|
+
params: { showBotsData: params?.showBotsData ?? true }
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
/**
|
|
2198
|
+
* Get bot users
|
|
2199
|
+
*/
|
|
2200
|
+
async getBotUsers() {
|
|
2201
|
+
return this.cb.request("cbExternalIntegrations", `/live-engage-service-0.1/le/accounts/${this.cb.getAccountId()}/bot_users`);
|
|
2202
|
+
}
|
|
2203
|
+
/**
|
|
2204
|
+
* Add a bot agent
|
|
2205
|
+
*/
|
|
2206
|
+
async addAgent(lpUserId, chatBotId, request) {
|
|
2207
|
+
return this.cb.request("cbExternalIntegrations", `/live-engage-service-0.1/le/accounts/${this.cb.getAccountId()}/bot_users/${lpUserId}`, {
|
|
2208
|
+
method: "POST",
|
|
2209
|
+
body: request,
|
|
2210
|
+
params: { chatBotId }
|
|
2211
|
+
});
|
|
2212
|
+
}
|
|
2213
|
+
};
|
|
2214
|
+
var IntegrationsAPI = class {
|
|
2215
|
+
constructor(cb) {
|
|
2216
|
+
this.cb = cb;
|
|
2217
|
+
}
|
|
2218
|
+
/**
|
|
2219
|
+
* Get responders for a chatbot
|
|
2220
|
+
*/
|
|
2221
|
+
async getResponders(chatBotId) {
|
|
2222
|
+
return this.cb.request("cbBotPlatform", "/responder", {
|
|
2223
|
+
params: { chatBotId }
|
|
2224
|
+
});
|
|
2225
|
+
}
|
|
2226
|
+
/**
|
|
2227
|
+
* Get LP skills
|
|
2228
|
+
*/
|
|
2229
|
+
async getLPSkills() {
|
|
2230
|
+
return this.cb.request("cbExternalIntegrations", `/live-engage-service-0.1/le/accounts/${this.cb.getAccountId()}/skills`);
|
|
2231
|
+
}
|
|
2232
|
+
/**
|
|
2233
|
+
* Get credentials
|
|
2234
|
+
*/
|
|
2235
|
+
async getCredentials() {
|
|
2236
|
+
return this.cb.request("cbExternalIntegrations", "/auth-service-0.1/credentials");
|
|
2237
|
+
}
|
|
2238
|
+
};
|
|
2239
|
+
|
|
1691
2240
|
// src/sdk.ts
|
|
1692
2241
|
var LPExtendSDK = class {
|
|
1693
2242
|
/**
|
|
@@ -1720,6 +2269,7 @@ var LPExtendSDK = class {
|
|
|
1720
2269
|
this.messaging = new MessagingAPI(this.http);
|
|
1721
2270
|
this.sentinel = new SentinelAPI(this.http);
|
|
1722
2271
|
this.prompts = new LPPromptsAPI(this.http);
|
|
2272
|
+
this.conversationBuilder = new ConversationBuilderAPI(config.accountId, this.debug, timeout);
|
|
1723
2273
|
this.log("SDK initialized with scopes:", this.grantedScopes);
|
|
1724
2274
|
}
|
|
1725
2275
|
/**
|
|
@@ -1768,9 +2318,9 @@ async function createSDK(config) {
|
|
|
1768
2318
|
if (!config.accountId) {
|
|
1769
2319
|
throw new LPExtendSDKError("accountId is required", ErrorCodes.INVALID_CONFIG);
|
|
1770
2320
|
}
|
|
1771
|
-
if (!config.accessToken && !config.extendToken && !config.shellToken) {
|
|
2321
|
+
if (!config.accessToken && !config.extendToken && !config.shellToken && !config.apiKey) {
|
|
1772
2322
|
throw new LPExtendSDKError(
|
|
1773
|
-
"Either accessToken, extendToken, or shellToken is required",
|
|
2323
|
+
"Either accessToken, apiKey, extendToken, or shellToken is required",
|
|
1774
2324
|
ErrorCodes.INVALID_CONFIG
|
|
1775
2325
|
);
|
|
1776
2326
|
}
|
|
@@ -1778,7 +2328,9 @@ async function createSDK(config) {
|
|
|
1778
2328
|
const timeout = config.timeout ?? 3e4;
|
|
1779
2329
|
let shellBaseUrl = config.shellBaseUrl;
|
|
1780
2330
|
if (!shellBaseUrl) {
|
|
1781
|
-
if (typeof
|
|
2331
|
+
if (typeof process !== "undefined" && process.env?.LPEXTEND_SHELL_URL) {
|
|
2332
|
+
shellBaseUrl = process.env.LPEXTEND_SHELL_URL;
|
|
2333
|
+
} else if (typeof window !== "undefined") {
|
|
1782
2334
|
try {
|
|
1783
2335
|
if (window.self !== window.top && document.referrer) {
|
|
1784
2336
|
const url = new URL(document.referrer);
|
|
@@ -1787,15 +2339,109 @@ async function createSDK(config) {
|
|
|
1787
2339
|
} catch {
|
|
1788
2340
|
}
|
|
1789
2341
|
shellBaseUrl = shellBaseUrl || window.location.origin;
|
|
1790
|
-
} else {
|
|
2342
|
+
} else if (config.apiKey || config.extendToken || config.shellToken) {
|
|
1791
2343
|
throw new LPExtendSDKError(
|
|
1792
|
-
"shellBaseUrl is required in non-browser environments",
|
|
2344
|
+
"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
2345
|
ErrorCodes.INVALID_CONFIG
|
|
1794
2346
|
);
|
|
1795
2347
|
}
|
|
1796
2348
|
}
|
|
1797
2349
|
let accessToken = config.accessToken;
|
|
1798
|
-
if (!accessToken && config.extendToken) {
|
|
2350
|
+
if (!accessToken && config.apiKey && config.extendToken) {
|
|
2351
|
+
const verifyUrl = `${shellBaseUrl}/api/v1/apps/verify`;
|
|
2352
|
+
if (debug) {
|
|
2353
|
+
console.log("[LP-Extend-SDK] Verifying ExtendJWT with API key");
|
|
2354
|
+
console.log("[LP-Extend-SDK] Shell URL:", shellBaseUrl);
|
|
2355
|
+
console.log("[LP-Extend-SDK] Verify URL:", verifyUrl);
|
|
2356
|
+
console.log("[LP-Extend-SDK] API Key:", config.apiKey.substring(0, 20) + "...");
|
|
2357
|
+
console.log("[LP-Extend-SDK] ExtendToken length:", config.extendToken.length);
|
|
2358
|
+
}
|
|
2359
|
+
const authController = new AbortController();
|
|
2360
|
+
const authTimeoutId = setTimeout(() => authController.abort(), timeout);
|
|
2361
|
+
try {
|
|
2362
|
+
const authResponse = await fetch(verifyUrl, {
|
|
2363
|
+
method: "POST",
|
|
2364
|
+
headers: {
|
|
2365
|
+
"Content-Type": "application/json",
|
|
2366
|
+
"X-LPExtend-API-Key": config.apiKey
|
|
2367
|
+
},
|
|
2368
|
+
body: JSON.stringify({
|
|
2369
|
+
token: config.extendToken
|
|
2370
|
+
}),
|
|
2371
|
+
signal: authController.signal
|
|
2372
|
+
});
|
|
2373
|
+
clearTimeout(authTimeoutId);
|
|
2374
|
+
if (!authResponse.ok) {
|
|
2375
|
+
const errorData = await authResponse.json().catch(() => ({}));
|
|
2376
|
+
if (authResponse.status === 401) {
|
|
2377
|
+
throw new LPExtendSDKError(
|
|
2378
|
+
errorData.message || "Invalid API key or ExtendJWT",
|
|
2379
|
+
ErrorCodes.UNAUTHORIZED,
|
|
2380
|
+
authResponse.status,
|
|
2381
|
+
errorData
|
|
2382
|
+
);
|
|
2383
|
+
}
|
|
2384
|
+
if (authResponse.status === 403) {
|
|
2385
|
+
throw new LPExtendSDKError(
|
|
2386
|
+
errorData.message || "App not authorized for this account",
|
|
2387
|
+
ErrorCodes.APP_NOT_REGISTERED,
|
|
2388
|
+
authResponse.status,
|
|
2389
|
+
errorData
|
|
2390
|
+
);
|
|
2391
|
+
}
|
|
2392
|
+
throw new LPExtendSDKError(
|
|
2393
|
+
errorData.message || `Token verification failed: ${authResponse.status}`,
|
|
2394
|
+
ErrorCodes.API_ERROR,
|
|
2395
|
+
authResponse.status,
|
|
2396
|
+
errorData
|
|
2397
|
+
);
|
|
2398
|
+
}
|
|
2399
|
+
const authData = await authResponse.json();
|
|
2400
|
+
accessToken = authData.lpAccessToken;
|
|
2401
|
+
if (debug) {
|
|
2402
|
+
console.log("[LP-Extend-SDK] ExtendJWT verified with API key");
|
|
2403
|
+
console.log("[LP-Extend-SDK] User:", authData.user?.lpUserId, "Account:", authData.user?.lpAccountId);
|
|
2404
|
+
console.log("[LP-Extend-SDK] Allowed APIs:", authData.allowedApis);
|
|
2405
|
+
}
|
|
2406
|
+
const resolvedConfig = { ...config, accessToken };
|
|
2407
|
+
const initResult = {
|
|
2408
|
+
appId: config.appId,
|
|
2409
|
+
accountId: authData.user?.lpAccountId || config.accountId,
|
|
2410
|
+
grantedScopes: authData.allowedApis || [],
|
|
2411
|
+
appName: config.appId,
|
|
2412
|
+
version: "1.0.0"
|
|
2413
|
+
};
|
|
2414
|
+
return new LPExtendSDK(resolvedConfig, initResult);
|
|
2415
|
+
} catch (error) {
|
|
2416
|
+
clearTimeout(authTimeoutId);
|
|
2417
|
+
if (debug) {
|
|
2418
|
+
console.error("[LP-Extend-SDK] ExtendJWT verification error:", {
|
|
2419
|
+
name: error.name,
|
|
2420
|
+
message: error.message,
|
|
2421
|
+
cause: error.cause?.message || error.cause,
|
|
2422
|
+
verifyUrl
|
|
2423
|
+
});
|
|
2424
|
+
}
|
|
2425
|
+
if (error instanceof LPExtendSDKError) {
|
|
2426
|
+
throw error;
|
|
2427
|
+
}
|
|
2428
|
+
if (error.name === "AbortError") {
|
|
2429
|
+
throw new LPExtendSDKError("Token verification timeout", ErrorCodes.TIMEOUT);
|
|
2430
|
+
}
|
|
2431
|
+
const errorMessage = error.cause?.message || error.message;
|
|
2432
|
+
throw new LPExtendSDKError(
|
|
2433
|
+
`ExtendJWT verification failed: ${errorMessage}`,
|
|
2434
|
+
ErrorCodes.INIT_FAILED
|
|
2435
|
+
);
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
if (!accessToken && config.apiKey && !config.extendToken) {
|
|
2439
|
+
throw new LPExtendSDKError(
|
|
2440
|
+
"API key authentication requires extendToken. The ExtendJWT is passed from the shell to your app when opened in an iframe.",
|
|
2441
|
+
ErrorCodes.INVALID_CONFIG
|
|
2442
|
+
);
|
|
2443
|
+
}
|
|
2444
|
+
if (!accessToken && config.extendToken && !config.apiKey) {
|
|
1799
2445
|
if (debug) {
|
|
1800
2446
|
console.log("[LP-Extend-SDK] Verifying ExtendJWT with shell");
|
|
1801
2447
|
}
|
|
@@ -1838,6 +2484,20 @@ async function createSDK(config) {
|
|
|
1838
2484
|
console.log("[LP-Extend-SDK] ExtendJWT verified, got LP access token");
|
|
1839
2485
|
console.log("[LP-Extend-SDK] User:", authData.lpUserId, "Account:", authData.lpAccountId);
|
|
1840
2486
|
}
|
|
2487
|
+
const grantedScopes = config.scopes || ["*"];
|
|
2488
|
+
if (debug) {
|
|
2489
|
+
console.log("[LP-Extend-SDK] ExtendJWT auth grants all scopes:", grantedScopes);
|
|
2490
|
+
console.log("[LP-Extend-SDK] SDK will call LP APIs directly");
|
|
2491
|
+
}
|
|
2492
|
+
const resolvedConfig = { ...config, accessToken };
|
|
2493
|
+
const initResult = {
|
|
2494
|
+
appId: config.appId,
|
|
2495
|
+
accountId: config.accountId,
|
|
2496
|
+
grantedScopes,
|
|
2497
|
+
appName: config.appId,
|
|
2498
|
+
version: "1.0.0"
|
|
2499
|
+
};
|
|
2500
|
+
return new LPExtendSDK(resolvedConfig, initResult);
|
|
1841
2501
|
} catch (error) {
|
|
1842
2502
|
clearTimeout(extendTimeoutId);
|
|
1843
2503
|
if (error instanceof LPExtendSDKError) {
|
|
@@ -2002,6 +2662,51 @@ async function createSDK(config) {
|
|
|
2002
2662
|
async function initializeSDK(config) {
|
|
2003
2663
|
return createSDK(config);
|
|
2004
2664
|
}
|
|
2665
|
+
async function createSDKFromEnv(extendToken) {
|
|
2666
|
+
const apiKey = process.env.LPEXTEND_API_KEY;
|
|
2667
|
+
const appId = process.env.APP_ID;
|
|
2668
|
+
const accountId = process.env.LP_ACCOUNT_ID;
|
|
2669
|
+
const shellBaseUrl = process.env.LPEXTEND_SHELL_URL;
|
|
2670
|
+
const debug = process.env.LPEXTEND_DEBUG === "true";
|
|
2671
|
+
if (!apiKey) {
|
|
2672
|
+
throw new LPExtendSDKError(
|
|
2673
|
+
"LPEXTEND_API_KEY environment variable is required",
|
|
2674
|
+
ErrorCodes.INVALID_CONFIG
|
|
2675
|
+
);
|
|
2676
|
+
}
|
|
2677
|
+
if (!appId) {
|
|
2678
|
+
throw new LPExtendSDKError(
|
|
2679
|
+
"APP_ID environment variable is required",
|
|
2680
|
+
ErrorCodes.INVALID_CONFIG
|
|
2681
|
+
);
|
|
2682
|
+
}
|
|
2683
|
+
if (!accountId) {
|
|
2684
|
+
throw new LPExtendSDKError(
|
|
2685
|
+
"LP_ACCOUNT_ID environment variable is required",
|
|
2686
|
+
ErrorCodes.INVALID_CONFIG
|
|
2687
|
+
);
|
|
2688
|
+
}
|
|
2689
|
+
if (!shellBaseUrl) {
|
|
2690
|
+
throw new LPExtendSDKError(
|
|
2691
|
+
"LPEXTEND_SHELL_URL environment variable is required",
|
|
2692
|
+
ErrorCodes.INVALID_CONFIG
|
|
2693
|
+
);
|
|
2694
|
+
}
|
|
2695
|
+
if (!extendToken) {
|
|
2696
|
+
throw new LPExtendSDKError(
|
|
2697
|
+
"extendToken is required. This is passed from the shell to your app when opened.",
|
|
2698
|
+
ErrorCodes.INVALID_CONFIG
|
|
2699
|
+
);
|
|
2700
|
+
}
|
|
2701
|
+
return createSDK({
|
|
2702
|
+
appId,
|
|
2703
|
+
accountId,
|
|
2704
|
+
apiKey,
|
|
2705
|
+
extendToken,
|
|
2706
|
+
shellBaseUrl,
|
|
2707
|
+
debug
|
|
2708
|
+
});
|
|
2709
|
+
}
|
|
2005
2710
|
var VERSION = "1.0.0";
|
|
2006
2711
|
var Scopes = {
|
|
2007
2712
|
// Account Configuration
|
|
@@ -2123,15 +2828,23 @@ exports.AgentActivityAPI = AgentActivityAPI;
|
|
|
2123
2828
|
exports.AgentGroupsAPI = AgentGroupsAPI;
|
|
2124
2829
|
exports.AgentMetricsAPI = AgentMetricsAPI;
|
|
2125
2830
|
exports.AutomaticMessagesAPI = AutomaticMessagesAPI;
|
|
2831
|
+
exports.BotAgentsAPI = BotAgentsAPI;
|
|
2832
|
+
exports.BotGroupsAPI = BotGroupsAPI;
|
|
2833
|
+
exports.BotsAPI = BotsAPI;
|
|
2126
2834
|
exports.CampaignsAPI = CampaignsAPI;
|
|
2127
2835
|
exports.CategoriesAPI = CategoriesAPI;
|
|
2128
2836
|
exports.ConnectToMessagingAPI = ConnectToMessagingAPI;
|
|
2837
|
+
exports.ConversationBuilderAPI = ConversationBuilderAPI;
|
|
2129
2838
|
exports.ConversationsAPI = ConversationsAPI;
|
|
2839
|
+
exports.DialogsAPI = DialogsAPI;
|
|
2130
2840
|
exports.EngagementsAPI = EngagementsAPI;
|
|
2131
2841
|
exports.ErrorCodes = ErrorCodes;
|
|
2132
2842
|
exports.EvaluatorsAPI = EvaluatorsAPI;
|
|
2133
2843
|
exports.FlowsAPI = FlowsAPI;
|
|
2134
2844
|
exports.GeneratorsAPI = GeneratorsAPI;
|
|
2845
|
+
exports.IntegrationsAPI = IntegrationsAPI;
|
|
2846
|
+
exports.InteractionsAPI = InteractionsAPI;
|
|
2847
|
+
exports.KnowledgeBasesAPI = KnowledgeBasesAPI;
|
|
2135
2848
|
exports.KnowledgebasesAPI = KnowledgebasesAPI;
|
|
2136
2849
|
exports.LOBsAPI = LOBsAPI;
|
|
2137
2850
|
exports.LPExtendSDK = LPExtendSDK;
|
|
@@ -2140,6 +2853,7 @@ exports.LPPromptsAPI = LPPromptsAPI;
|
|
|
2140
2853
|
exports.MessagingAPI = MessagingAPI;
|
|
2141
2854
|
exports.MessagingHistoryAPI = MessagingHistoryAPI;
|
|
2142
2855
|
exports.MessagingOperationsAPI = MessagingOperationsAPI;
|
|
2856
|
+
exports.NLUDomainsAPI = NLUDomainsAPI;
|
|
2143
2857
|
exports.OutboundReportingAPI = OutboundReportingAPI;
|
|
2144
2858
|
exports.PredefinedContentAPI = PredefinedContentAPI;
|
|
2145
2859
|
exports.ProfilesAPI = ProfilesAPI;
|
|
@@ -2156,6 +2870,7 @@ exports.UsersAPI = UsersAPI;
|
|
|
2156
2870
|
exports.VERSION = VERSION;
|
|
2157
2871
|
exports.WorkingHoursAPI = WorkingHoursAPI;
|
|
2158
2872
|
exports.createSDK = createSDK;
|
|
2873
|
+
exports.createSDKFromEnv = createSDKFromEnv;
|
|
2159
2874
|
exports.getShellToken = getShellToken;
|
|
2160
2875
|
exports.initializeSDK = initializeSDK;
|
|
2161
2876
|
//# sourceMappingURL=index.js.map
|