@botpress/client 0.0.7 → 0.0.9

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.ts CHANGED
@@ -1,8 +1,9 @@
1
- export * as axios from 'axios';
2
- import { ClientProps } from './config';
3
- export type { Message, Conversation, User, State, Event, ModelFile as File, Bot, Integration } from './gen';
4
- export * from './gen/errors';
5
- import { ApiClient as AutoGeneratedClient } from './gen/client';
6
- export declare class Client extends AutoGeneratedClient {
7
- constructor(clientProps?: ClientProps);
8
- }
1
+ export * as axios from 'axios';
2
+ import { ClientProps, ClientConfig } from './config';
3
+ export type { Message, Conversation, User, State, Event, ModelFile as File, Bot, Integration } from './gen';
4
+ export * from './gen/errors';
5
+ import { ApiClient as AutoGeneratedClient } from './gen/client';
6
+ export declare class Client extends AutoGeneratedClient {
7
+ readonly config: ClientConfig;
8
+ constructor(clientProps?: ClientProps);
9
+ }
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import Be from"axios";import*as Ps from"axios";import{isBrowser as b,isNode as X}from"browser-or-node";var I="https://api.botpress.cloud",ee="https://oauth.botpress.cloud/oauth2/token",te="BP_API_URL",se="BP_OAUTH_URL",re="BP_BOT_ID",ne="BP_INTEGRATION_ID",ae="BP_WORKSPACE_ID",oe="BP_ENV",ie="BP_TOKEN",le="BP_CLIENT_KEY",ce="BP_CLIENT_SECRET";function $(n){let t=pe(n),e={};return t.dev&&(e["x-bp-env"]="dev"),t.workspaceId&&(e["x-workspace-id"]=t.workspaceId),t.botId&&(e["x-bot-id"]=t.botId),t.integrationId&&(e["x-integration-id"]=t.integrationId),t.token?{authStrategy:"token",host:t.host??I,withCredentials:b,headers:e,token:t.token}:t.clientKey&&t.clientSecret&&t.oauthUrl?{authStrategy:"oauth",host:t.host??I,withCredentials:b,headers:e,clientKey:t.clientKey,clientSecret:t.clientSecret,oauthUrl:t.oauthUrl}:{host:t.host??I,withCredentials:b,headers:e,authStrategy:"none"}}function pe(n){return b?ue(n):X?ge(n):n}function ge(n){let t={...n,host:n.host??process.env[te]??I,oauthUrl:n.oauthUrl??process.env[se]??ee,botId:n.botId??process.env[re],integrationId:n.integrationId??process.env[ne],workspaceId:n.workspaceId??process.env[ae],dev:n.dev??process.env[oe]==="dev"},e=t.token??process.env[ie],s=t.clientKey??process.env[le],a=t.clientSecret??process.env[ce];return e?t.token=e:s&&a&&(t.clientKey=s,t.clientSecret=a),t}function ue(n){return{...n,dev:n.dev??!0}}var m=class extends Error{constructor(e,s,a,r,o){super(r);this.code=e;this.description=s;this.type=a;this.message=r;this.error=o}isApiError=!0;toJSON(){return{code:this.code,type:this.type,message:this.message}}},de=n=>typeof n=="object"&&!Array.isArray(n)&&n!==null,ye=n=>n instanceof m||de(n)&&n.isApiError===!0,B=class extends m{constructor(t,e){super(500,"An unknown error occurred","Unknown",t,e)}},D=class extends m{constructor(t,e){super(500,"An internal error occurred","Internal",t,e)}},T=class extends m{constructor(t,e){super(401,"The request requires to be authenticated.","Unauthorized",t,e)}},E=class extends m{constructor(t,e){super(403,"The requested action can't be peform by this resource.","Forbidden",t,e)}},S=class extends m{constructor(t,e){super(413,"The request payload is too large.","PayloadTooLarge",t,e)}},w=class extends m{constructor(t,e){super(400,"The request payload isn't invalid.","InvalidPayload",t,e)}},M=class extends m{constructor(t,e){super(405,"The requested method does not exist.","MethodNotFound",t,e)}},G=class extends m{constructor(t,e){super(404,"The requested resource does not exist.","ResourceNotFound",t,e)}},L=class extends m{constructor(t,e){super(400,"The provided JSON schema is invalid.","InvalidJsonSchema",t,e)}},F=class extends m{constructor(t,e){super(400,"The provided data doesn't respect the provided JSON schema.","InvalidDataFormat",t,e)}},k=class extends m{constructor(t,e){super(400,"The provided identifier is not valid. An identifier must start with a lowercase letter, be between 2 and 100 characters long and use only alphanumeric characters.","InvalidIdentifier",t,e)}},_=class extends m{constructor(t,e){super(409,"The resource is not related with another resource. This is usually caused when providing two resources that aren't linked together.","RelationConflict",t,e)}},N=class extends m{constructor(t,e){super(400,"The provided resource reference is missing. This is usually caused when providing an invalid id inside the payload of a request.","ReferenceNotFound",t,e)}},j=class extends m{constructor(t,e){super(400,"The provided query is invalid. This is usually caused when providing an invalid parameter for querying a resource.","InvalidQuery",t,e)}},Q=class extends m{constructor(t,e){super(400,"An error happened during the execution of a runtime (bot or integration).","Runtime",t,e)}},he={Unknown:B,Internal:D,Unauthorized:T,Forbidden:E,PayloadTooLarge:S,InvalidPayload:w,MethodNotFound:M,ResourceNotFound:G,InvalidJsonSchema:L,InvalidDataFormat:F,InvalidIdentifier:k,RelationConflict:_,ReferenceNotFound:N,InvalidQuery:j,Runtime:Q},H=n=>ye(n)?n:n instanceof Error?new B(n.message,n):n===null?new B("An unknown error occurred"):typeof n=="string"?new B(n):typeof n!="object"?new B("An unknown error occurred"):Ae(n);function Ae(n){if("code"in n&&"type"in n&&"message"in n){if(typeof n.message!="string")return new B("An unknown error occurred");if(typeof n.type!="string")return new B(n.message);let t=he[n.type];return t?new t(n.message):new B(n.message)}return new B("An unknown error occurred")}import Re from"axios";import A from"axios";import Ce from"axios";var g="https://api.botpress.cloud".replace(/\/+$/,"");var q=class{constructor(t,e=g,s=Ce){this.basePath=e;this.axios=s;t&&(this.configuration=t,this.basePath=t.basePath||this.basePath)}configuration},v=class extends Error{constructor(e,s){super(s);this.field=e}name="RequiredError"};import"axios";var u="https://example.com",R=function(n,t,e){if(e==null)throw new v(t,`Required parameter ${t} was null or undefined when calling ${n}.`)};function W(n,t,e=""){typeof t=="object"?Array.isArray(t)?t.forEach(s=>W(n,s,e)):Object.keys(t).forEach(s=>W(n,t[s],`${e}${e!==""?".":""}${s}`)):n.has(e)?n.append(e,t):n.set(e,t)}var d=function(n,...t){let e=new URLSearchParams(n.search);W(e,t),n.search=e.toString()},f=function(n,t,e){let s=typeof n!="string";return(s&&e&&e.isJsonMime?e.isJsonMime(t.headers["Content-Type"]):s)?JSON.stringify(n!==void 0?n:{}):n||""},y=function(n){return n.pathname+n.search+n.hash},h=function(n,t,e,s){return(a=t,r=e)=>{let o={...n.options,url:(s?.basePath||r)+n.url};return a.request(o)}};var xe=function(n){return{callAction:async(t,e={})=>{let s="/v1/chat/actions",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},l={};i["Content-Type"]="application/json",d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},configureIntegration:async(t,e={})=>{let s="/v1/chat/integrations/configure",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},l={};i["Content-Type"]="application/json",d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createBot:async(t,e={})=>{let s="/v1/admin/bots",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},l={};i["Content-Type"]="application/json",d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createConversation:async(t,e={})=>{let s="/v1/chat/conversations",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},l={};i["Content-Type"]="application/json",d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createEvent:async(t,e={})=>{let s="/v1/chat/events",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},l={};i["Content-Type"]="application/json",d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createFile:async(t,e={})=>{let s="/v1/storage/files",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},l={};i["Content-Type"]="application/json",d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createIntegration:async(t,e={})=>{let s="/v1/admin/integrations",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},l={};i["Content-Type"]="application/json",d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createMessage:async(t,e={})=>{let s="/v1/chat/messages",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},l={};i["Content-Type"]="application/json",d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createUser:async(t,e={})=>{let s="/v1/chat/users",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},l={};i["Content-Type"]="application/json",d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},deleteBot:async(t,e={})=>{R("deleteBot","id",t);let s="/v1/admin/bots/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"DELETE",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},deleteConversation:async(t,e={})=>{R("deleteConversation","id",t);let s="/v1/chat/conversations/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"DELETE",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},deleteFile:async(t,e={})=>{R("deleteFile","id",t);let s="/v1/storage/files/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"DELETE",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},deleteIntegration:async(t,e={})=>{R("deleteIntegration","id",t);let s="/v1/admin/integrations/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"DELETE",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},deleteMessage:async(t,e={})=>{R("deleteMessage","id",t);let s="/v1/chat/messages/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"DELETE",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},deleteUser:async(t,e={})=>{R("deleteUser","id",t);let s="/v1/chat/users/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"DELETE",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},downloadFile:async(t,e={})=>{R("downloadFile","id",t);let s="/v1/storage/files/{id}/download".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},getBot:async(t,e={})=>{R("getBot","id",t);let s="/v1/admin/bots/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},getBotAnalytics:async(t,e,s,a={})=>{R("getBotAnalytics","id",t),R("getBotAnalytics","startDate",e),R("getBotAnalytics","endDate",s);let r="/v1/admin/bots/{id}/analytics".replace("{id}",encodeURIComponent(String(t))),o=new URL(r,u),i;n&&(i=n.baseOptions);let l={method:"GET",...i,...a},c={},p={};e!==void 0&&(p.startDate=e),s!==void 0&&(p.endDate=s),d(o,p);let P=i&&i.headers?i.headers:{};return l.headers={...c,...P,...a.headers},{url:y(o),options:l}},getBotLogs:async(t,e={})=>{R("getBotLogs","id",t);let s="/v1/admin/bots/{id}/logs".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},getBotWebchat:async(t,e,s={})=>{R("getBotWebchat","id",t),R("getBotWebchat","type",e);let a="/v1/admin/bots/{id}/webchat".replace("{id}",encodeURIComponent(String(t))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"GET",...o,...s},l={},c={};e!==void 0&&(c.type=e),d(r,c);let p=o&&o.headers?o.headers:{};return i.headers={...l,...p,...s.headers},{url:y(r),options:i}},getConversation:async(t,e={})=>{R("getConversation","id",t);let s="/v1/chat/conversations/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},getEvent:async(t,e={})=>{R("getEvent","id",t);let s="/v1/chat/events/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},getFile:async(t,e={})=>{R("getFile","id",t);let s="/v1/storage/files/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},getIntegration:async(t,e={})=>{R("getIntegration","id",t);let s="/v1/admin/integrations/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},getIntegrationByName:async(t,e,s={})=>{R("getIntegrationByName","name",t),R("getIntegrationByName","version",e);let a="/v1/admin/integrations/{name}/{version}".replace("{name}",encodeURIComponent(String(t))).replace("{version}",encodeURIComponent(String(e))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"GET",...o,...s},l={};d(r,{});let p=o&&o.headers?o.headers:{};return i.headers={...l,...p,...s.headers},{url:y(r),options:i}},getMessage:async(t,e={})=>{R("getMessage","id",t);let s="/v1/chat/messages/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},getOrCreateConversation:async(t,e={})=>{let s="/v1/chat/conversations/get-or-create",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},l={};i["Content-Type"]="application/json",d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},getOrCreateMessage:async(t,e={})=>{let s="/v1/chat/messages/get-or-create",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},l={};i["Content-Type"]="application/json",d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},getOrCreateUser:async(t,e={})=>{let s="/v1/chat/users/get-or-create",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},l={};i["Content-Type"]="application/json",d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},getPublicIntegration:async(t,e,s={})=>{R("getPublicIntegration","name",t),R("getPublicIntegration","version",e);let a="/v1/admin/hub/integrations/{name}/{version}".replace("{name}",encodeURIComponent(String(t))).replace("{version}",encodeURIComponent(String(e))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"GET",...o,...s},l={};d(r,{});let p=o&&o.headers?o.headers:{};return i.headers={...l,...p,...s.headers},{url:y(r),options:i}},getPublicIntegrationById:async(t,e={})=>{R("getPublicIntegrationById","id",t);let s="/v1/admin/hub/integrations/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},getState:async(t,e,s,a={})=>{R("getState","type",t),R("getState","id",e),R("getState","name",s);let r="/v1/chat/states/{type}/{id}/{name}".replace("{type}",encodeURIComponent(String(t))).replace("{id}",encodeURIComponent(String(e))).replace("{name}",encodeURIComponent(String(s))),o=new URL(r,u),i;n&&(i=n.baseOptions);let l={method:"GET",...i,...a},c={};d(o,{});let P=i&&i.headers?i.headers:{};return l.headers={...c,...P,...a.headers},{url:y(o),options:l}},getUser:async(t,e={})=>{R("getUser","id",t);let s="/v1/chat/users/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},introspect:async(t,e={})=>{let s="/v1/admin/introspect",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},l={};i["Content-Type"]="application/json",d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},listBots:async(t,e={})=>{let s="/v1/admin/bots",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={},l={};t!==void 0&&(l.nextToken=t),d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},listConversations:async(t,e,s,a={})=>{let r="/v1/chat/conversations",o=new URL(r,u),i;n&&(i=n.baseOptions);let l={method:"GET",...i,...a},c={},p={};t!==void 0&&(p.nextToken=t),e!==void 0&&(p.tags=e),s&&(p.participantIds=s),d(o,p);let P=i&&i.headers?i.headers:{};return l.headers={...c,...P,...a.headers},{url:y(o),options:l}},listEvents:async(t,e={})=>{let s="/v1/chat/events",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={},l={};t!==void 0&&(l.nextToken=t),d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},listFiles:async(t,e,s={})=>{R("listFiles","botId",t);let a="/v1/storage/files",r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"GET",...o,...s},l={},c={};e!==void 0&&(c.nextToken=e),t!==void 0&&(c.botId=t),d(r,c);let p=o&&o.headers?o.headers:{};return i.headers={...l,...p,...s.headers},{url:y(r),options:i}},listIntegrations:async(t,e,s,a={})=>{let r="/v1/admin/integrations",o=new URL(r,u),i;n&&(i=n.baseOptions);let l={method:"GET",...i,...a},c={},p={};t!==void 0&&(p.nextToken=t),e!==void 0&&(p.name=e),s!==void 0&&(p.version=s),d(o,p);let P=i&&i.headers?i.headers:{};return l.headers={...c,...P,...a.headers},{url:y(o),options:l}},listMessages:async(t,e,s,a={})=>{let r="/v1/chat/messages",o=new URL(r,u),i;n&&(i=n.baseOptions);let l={method:"GET",...i,...a},c={},p={};t!==void 0&&(p.nextToken=t),e!==void 0&&(p.conversationId=e),s!==void 0&&(p.tags=s),d(o,p);let P=i&&i.headers?i.headers:{};return l.headers={...c,...P,...a.headers},{url:y(o),options:l}},listPublicIntegrations:async(t,e,s,a={})=>{let r="/v1/admin/hub/integrations",o=new URL(r,u),i;n&&(i=n.baseOptions);let l={method:"GET",...i,...a},c={},p={};t!==void 0&&(p.nextToken=t),e!==void 0&&(p.name=e),s!==void 0&&(p.version=s),d(o,p);let P=i&&i.headers?i.headers:{};return l.headers={...c,...P,...a.headers},{url:y(o),options:l}},listUsers:async(t,e,s,a={})=>{let r="/v1/chat/users",o=new URL(r,u),i;n&&(i=n.baseOptions);let l={method:"GET",...i,...a},c={},p={};t!==void 0&&(p.nextToken=t),e!==void 0&&(p.conversationId=e),s!==void 0&&(p.tags=s),d(o,p);let P=i&&i.headers?i.headers:{};return l.headers={...c,...P,...a.headers},{url:y(o),options:l}},listWorkspaces:async(t,e={})=>{let s="/v1/admin/workspaces",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={},l={};t!==void 0&&(l.nextToken=t),d(a,l);let c=r&&r.headers?r.headers:{};return o.headers={...i,...c,...e.headers},{url:y(a),options:o}},patchState:async(t,e,s,a,r={})=>{R("patchState","type",t),R("patchState","id",e),R("patchState","name",s);let o="/v1/chat/states/{type}/{id}/{name}".replace("{type}",encodeURIComponent(String(t))).replace("{id}",encodeURIComponent(String(e))).replace("{name}",encodeURIComponent(String(s))),i=new URL(o,u),l;n&&(l=n.baseOptions);let c={method:"PATCH",...l,...r},p={},P={};p["Content-Type"]="application/json",d(i,P);let V=l&&l.headers?l.headers:{};return c.headers={...p,...V,...r.headers},c.data=f(a,c,n),{url:y(i),options:c}},setState:async(t,e,s,a,r={})=>{R("setState","type",t),R("setState","id",e),R("setState","name",s);let o="/v1/chat/states/{type}/{id}/{name}".replace("{type}",encodeURIComponent(String(t))).replace("{id}",encodeURIComponent(String(e))).replace("{name}",encodeURIComponent(String(s))),i=new URL(o,u),l;n&&(l=n.baseOptions);let c={method:"POST",...l,...r},p={},P={};p["Content-Type"]="application/json",d(i,P);let V=l&&l.headers?l.headers:{};return c.headers={...p,...V,...r.headers},c.data=f(a,c,n),{url:y(i),options:c}},updateBot:async(t,e,s={})=>{R("updateBot","id",t);let a="/v1/admin/bots/{id}".replace("{id}",encodeURIComponent(String(t))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"PUT",...o,...s},l={},c={};l["Content-Type"]="application/json",d(r,c);let p=o&&o.headers?o.headers:{};return i.headers={...l,...p,...s.headers},i.data=f(e,i,n),{url:y(r),options:i}},updateConversation:async(t,e,s={})=>{R("updateConversation","id",t);let a="/v1/chat/conversations/{id}".replace("{id}",encodeURIComponent(String(t))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"PUT",...o,...s},l={},c={};l["Content-Type"]="application/json",d(r,c);let p=o&&o.headers?o.headers:{};return i.headers={...l,...p,...s.headers},i.data=f(e,i,n),{url:y(r),options:i}},updateIntegration:async(t,e,s={})=>{R("updateIntegration","id",t);let a="/v1/admin/integrations/{id}".replace("{id}",encodeURIComponent(String(t))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"PUT",...o,...s},l={},c={};l["Content-Type"]="application/json",d(r,c);let p=o&&o.headers?o.headers:{};return i.headers={...l,...p,...s.headers},i.data=f(e,i,n),{url:y(r),options:i}},updateMessage:async(t,e,s={})=>{R("updateMessage","id",t);let a="/v1/chat/messages/{id}".replace("{id}",encodeURIComponent(String(t))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"PUT",...o,...s},l={},c={};l["Content-Type"]="application/json",d(r,c);let p=o&&o.headers?o.headers:{};return i.headers={...l,...p,...s.headers},i.data=f(e,i,n),{url:y(r),options:i}},updateUser:async(t,e,s={})=>{R("updateUser","id",t);let a="/v1/chat/users/{id}".replace("{id}",encodeURIComponent(String(t))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"PUT",...o,...s},l={},c={};l["Content-Type"]="application/json",d(r,c);let p=o&&o.headers?o.headers:{};return i.headers={...l,...p,...s.headers},i.data=f(e,i,n),{url:y(r),options:i}}}},C=function(n){let t=xe(n);return{async callAction(e,s){let a=await t.callAction(e,s);return h(a,A,g,n)},async configureIntegration(e,s){let a=await t.configureIntegration(e,s);return h(a,A,g,n)},async createBot(e,s){let a=await t.createBot(e,s);return h(a,A,g,n)},async createConversation(e,s){let a=await t.createConversation(e,s);return h(a,A,g,n)},async createEvent(e,s){let a=await t.createEvent(e,s);return h(a,A,g,n)},async createFile(e,s){let a=await t.createFile(e,s);return h(a,A,g,n)},async createIntegration(e,s){let a=await t.createIntegration(e,s);return h(a,A,g,n)},async createMessage(e,s){let a=await t.createMessage(e,s);return h(a,A,g,n)},async createUser(e,s){let a=await t.createUser(e,s);return h(a,A,g,n)},async deleteBot(e,s){let a=await t.deleteBot(e,s);return h(a,A,g,n)},async deleteConversation(e,s){let a=await t.deleteConversation(e,s);return h(a,A,g,n)},async deleteFile(e,s){let a=await t.deleteFile(e,s);return h(a,A,g,n)},async deleteIntegration(e,s){let a=await t.deleteIntegration(e,s);return h(a,A,g,n)},async deleteMessage(e,s){let a=await t.deleteMessage(e,s);return h(a,A,g,n)},async deleteUser(e,s){let a=await t.deleteUser(e,s);return h(a,A,g,n)},async downloadFile(e,s){let a=await t.downloadFile(e,s);return h(a,A,g,n)},async getBot(e,s){let a=await t.getBot(e,s);return h(a,A,g,n)},async getBotAnalytics(e,s,a,r){let o=await t.getBotAnalytics(e,s,a,r);return h(o,A,g,n)},async getBotLogs(e,s){let a=await t.getBotLogs(e,s);return h(a,A,g,n)},async getBotWebchat(e,s,a){let r=await t.getBotWebchat(e,s,a);return h(r,A,g,n)},async getConversation(e,s){let a=await t.getConversation(e,s);return h(a,A,g,n)},async getEvent(e,s){let a=await t.getEvent(e,s);return h(a,A,g,n)},async getFile(e,s){let a=await t.getFile(e,s);return h(a,A,g,n)},async getIntegration(e,s){let a=await t.getIntegration(e,s);return h(a,A,g,n)},async getIntegrationByName(e,s,a){let r=await t.getIntegrationByName(e,s,a);return h(r,A,g,n)},async getMessage(e,s){let a=await t.getMessage(e,s);return h(a,A,g,n)},async getOrCreateConversation(e,s){let a=await t.getOrCreateConversation(e,s);return h(a,A,g,n)},async getOrCreateMessage(e,s){let a=await t.getOrCreateMessage(e,s);return h(a,A,g,n)},async getOrCreateUser(e,s){let a=await t.getOrCreateUser(e,s);return h(a,A,g,n)},async getPublicIntegration(e,s,a){let r=await t.getPublicIntegration(e,s,a);return h(r,A,g,n)},async getPublicIntegrationById(e,s){let a=await t.getPublicIntegrationById(e,s);return h(a,A,g,n)},async getState(e,s,a,r){let o=await t.getState(e,s,a,r);return h(o,A,g,n)},async getUser(e,s){let a=await t.getUser(e,s);return h(a,A,g,n)},async introspect(e,s){let a=await t.introspect(e,s);return h(a,A,g,n)},async listBots(e,s){let a=await t.listBots(e,s);return h(a,A,g,n)},async listConversations(e,s,a,r){let o=await t.listConversations(e,s,a,r);return h(o,A,g,n)},async listEvents(e,s){let a=await t.listEvents(e,s);return h(a,A,g,n)},async listFiles(e,s,a){let r=await t.listFiles(e,s,a);return h(r,A,g,n)},async listIntegrations(e,s,a,r){let o=await t.listIntegrations(e,s,a,r);return h(o,A,g,n)},async listMessages(e,s,a,r){let o=await t.listMessages(e,s,a,r);return h(o,A,g,n)},async listPublicIntegrations(e,s,a,r){let o=await t.listPublicIntegrations(e,s,a,r);return h(o,A,g,n)},async listUsers(e,s,a,r){let o=await t.listUsers(e,s,a,r);return h(o,A,g,n)},async listWorkspaces(e,s){let a=await t.listWorkspaces(e,s);return h(a,A,g,n)},async patchState(e,s,a,r,o){let i=await t.patchState(e,s,a,r,o);return h(i,A,g,n)},async setState(e,s,a,r,o){let i=await t.setState(e,s,a,r,o);return h(i,A,g,n)},async updateBot(e,s,a){let r=await t.updateBot(e,s,a);return h(r,A,g,n)},async updateConversation(e,s,a){let r=await t.updateConversation(e,s,a);return h(r,A,g,n)},async updateIntegration(e,s,a){let r=await t.updateIntegration(e,s,a);return h(r,A,g,n)},async updateMessage(e,s,a){let r=await t.updateMessage(e,s,a);return h(r,A,g,n)},async updateUser(e,s,a){let r=await t.updateUser(e,s,a);return h(r,A,g,n)}}};var U=class extends q{callAction(t={},e){return C(this.configuration).callAction(t.callActionBody,e).then(s=>s(this.axios,this.basePath))}configureIntegration(t={},e){return C(this.configuration).configureIntegration(t.configureIntegrationBody,e).then(s=>s(this.axios,this.basePath))}createBot(t={},e){return C(this.configuration).createBot(t.createBotBody,e).then(s=>s(this.axios,this.basePath))}createConversation(t={},e){return C(this.configuration).createConversation(t.createConversationBody,e).then(s=>s(this.axios,this.basePath))}createEvent(t={},e){return C(this.configuration).createEvent(t.createEventBody,e).then(s=>s(this.axios,this.basePath))}createFile(t={},e){return C(this.configuration).createFile(t.createFileBody,e).then(s=>s(this.axios,this.basePath))}createIntegration(t={},e){return C(this.configuration).createIntegration(t.createIntegrationBody,e).then(s=>s(this.axios,this.basePath))}createMessage(t={},e){return C(this.configuration).createMessage(t.createMessageBody,e).then(s=>s(this.axios,this.basePath))}createUser(t={},e){return C(this.configuration).createUser(t.createUserBody,e).then(s=>s(this.axios,this.basePath))}deleteBot(t,e){return C(this.configuration).deleteBot(t.id,e).then(s=>s(this.axios,this.basePath))}deleteConversation(t,e){return C(this.configuration).deleteConversation(t.id,e).then(s=>s(this.axios,this.basePath))}deleteFile(t,e){return C(this.configuration).deleteFile(t.id,e).then(s=>s(this.axios,this.basePath))}deleteIntegration(t,e){return C(this.configuration).deleteIntegration(t.id,e).then(s=>s(this.axios,this.basePath))}deleteMessage(t,e){return C(this.configuration).deleteMessage(t.id,e).then(s=>s(this.axios,this.basePath))}deleteUser(t,e){return C(this.configuration).deleteUser(t.id,e).then(s=>s(this.axios,this.basePath))}downloadFile(t,e){return C(this.configuration).downloadFile(t.id,e).then(s=>s(this.axios,this.basePath))}getBot(t,e){return C(this.configuration).getBot(t.id,e).then(s=>s(this.axios,this.basePath))}getBotAnalytics(t,e){return C(this.configuration).getBotAnalytics(t.id,t.startDate,t.endDate,e).then(s=>s(this.axios,this.basePath))}getBotLogs(t,e){return C(this.configuration).getBotLogs(t.id,e).then(s=>s(this.axios,this.basePath))}getBotWebchat(t,e){return C(this.configuration).getBotWebchat(t.id,t.type,e).then(s=>s(this.axios,this.basePath))}getConversation(t,e){return C(this.configuration).getConversation(t.id,e).then(s=>s(this.axios,this.basePath))}getEvent(t,e){return C(this.configuration).getEvent(t.id,e).then(s=>s(this.axios,this.basePath))}getFile(t,e){return C(this.configuration).getFile(t.id,e).then(s=>s(this.axios,this.basePath))}getIntegration(t,e){return C(this.configuration).getIntegration(t.id,e).then(s=>s(this.axios,this.basePath))}getIntegrationByName(t,e){return C(this.configuration).getIntegrationByName(t.name,t.version,e).then(s=>s(this.axios,this.basePath))}getMessage(t,e){return C(this.configuration).getMessage(t.id,e).then(s=>s(this.axios,this.basePath))}getOrCreateConversation(t={},e){return C(this.configuration).getOrCreateConversation(t.getOrCreateConversationBody,e).then(s=>s(this.axios,this.basePath))}getOrCreateMessage(t={},e){return C(this.configuration).getOrCreateMessage(t.getOrCreateMessageBody,e).then(s=>s(this.axios,this.basePath))}getOrCreateUser(t={},e){return C(this.configuration).getOrCreateUser(t.getOrCreateUserBody,e).then(s=>s(this.axios,this.basePath))}getPublicIntegration(t,e){return C(this.configuration).getPublicIntegration(t.name,t.version,e).then(s=>s(this.axios,this.basePath))}getPublicIntegrationById(t,e){return C(this.configuration).getPublicIntegrationById(t.id,e).then(s=>s(this.axios,this.basePath))}getState(t,e){return C(this.configuration).getState(t.type,t.id,t.name,e).then(s=>s(this.axios,this.basePath))}getUser(t,e){return C(this.configuration).getUser(t.id,e).then(s=>s(this.axios,this.basePath))}introspect(t={},e){return C(this.configuration).introspect(t.introspectBody,e).then(s=>s(this.axios,this.basePath))}listBots(t={},e){return C(this.configuration).listBots(t.nextToken,e).then(s=>s(this.axios,this.basePath))}listConversations(t={},e){return C(this.configuration).listConversations(t.nextToken,t.tags,t.participantIds,e).then(s=>s(this.axios,this.basePath))}listEvents(t={},e){return C(this.configuration).listEvents(t.nextToken,e).then(s=>s(this.axios,this.basePath))}listFiles(t,e){return C(this.configuration).listFiles(t.botId,t.nextToken,e).then(s=>s(this.axios,this.basePath))}listIntegrations(t={},e){return C(this.configuration).listIntegrations(t.nextToken,t.name,t.version,e).then(s=>s(this.axios,this.basePath))}listMessages(t={},e){return C(this.configuration).listMessages(t.nextToken,t.conversationId,t.tags,e).then(s=>s(this.axios,this.basePath))}listPublicIntegrations(t={},e){return C(this.configuration).listPublicIntegrations(t.nextToken,t.name,t.version,e).then(s=>s(this.axios,this.basePath))}listUsers(t={},e){return C(this.configuration).listUsers(t.nextToken,t.conversationId,t.tags,e).then(s=>s(this.axios,this.basePath))}listWorkspaces(t={},e){return C(this.configuration).listWorkspaces(t.nextToken,e).then(s=>s(this.axios,this.basePath))}patchState(t,e){return C(this.configuration).patchState(t.type,t.id,t.name,t.patchStateBody,e).then(s=>s(this.axios,this.basePath))}setState(t,e){return C(this.configuration).setState(t.type,t.id,t.name,t.setStateBody,e).then(s=>s(this.axios,this.basePath))}updateBot(t,e){return C(this.configuration).updateBot(t.id,t.updateBotBody,e).then(s=>s(this.axios,this.basePath))}updateConversation(t,e){return C(this.configuration).updateConversation(t.id,t.updateConversationBody,e).then(s=>s(this.axios,this.basePath))}updateIntegration(t,e){return C(this.configuration).updateIntegration(t.id,t.updateIntegrationBody,e).then(s=>s(this.axios,this.basePath))}updateMessage(t,e){return C(this.configuration).updateMessage(t.id,t.updateMessageBody,e).then(s=>s(this.axios,this.basePath))}updateUser(t,e){return C(this.configuration).updateUser(t.id,t.updateUserBody,e).then(s=>s(this.axios,this.basePath))}};var O=class{_innerClient;constructor(t,e,s){this._innerClient=new U(t,e,s)}createConversation=t=>this._innerClient.createConversation({createConversationBody:t}).then(e=>e.data).catch(e=>{throw x(e)});getConversation=t=>this._innerClient.getConversation(t).then(e=>e.data).catch(e=>{throw x(e)});listConversations=t=>this._innerClient.listConversations(t).then(e=>e.data).catch(e=>{throw x(e)});getOrCreateConversation=t=>this._innerClient.getOrCreateConversation({getOrCreateConversationBody:t}).then(e=>e.data).catch(e=>{throw x(e)});updateConversation=({id:t,...e})=>this._innerClient.updateConversation({id:t,updateConversationBody:e}).then(s=>s.data).catch(s=>{throw x(s)});deleteConversation=t=>this._innerClient.deleteConversation(t).then(e=>e.data).catch(e=>{throw x(e)});createEvent=t=>this._innerClient.createEvent({createEventBody:t}).then(e=>e.data).catch(e=>{throw x(e)});getEvent=t=>this._innerClient.getEvent(t).then(e=>e.data).catch(e=>{throw x(e)});listEvents=t=>this._innerClient.listEvents(t).then(e=>e.data).catch(e=>{throw x(e)});createMessage=t=>this._innerClient.createMessage({createMessageBody:t}).then(e=>e.data).catch(e=>{throw x(e)});getOrCreateMessage=t=>this._innerClient.getOrCreateMessage({getOrCreateMessageBody:t}).then(e=>e.data).catch(e=>{throw x(e)});getMessage=t=>this._innerClient.getMessage(t).then(e=>e.data).catch(e=>{throw x(e)});updateMessage=({id:t,...e})=>this._innerClient.updateMessage({id:t,updateMessageBody:e}).then(s=>s.data).catch(s=>{throw x(s)});listMessages=t=>this._innerClient.listMessages(t).then(e=>e.data).catch(e=>{throw x(e)});deleteMessage=t=>this._innerClient.deleteMessage(t).then(e=>e.data).catch(e=>{throw x(e)});createUser=t=>this._innerClient.createUser({createUserBody:t}).then(e=>e.data).catch(e=>{throw x(e)});getUser=t=>this._innerClient.getUser(t).then(e=>e.data).catch(e=>{throw x(e)});listUsers=t=>this._innerClient.listUsers(t).then(e=>e.data).catch(e=>{throw x(e)});getOrCreateUser=t=>this._innerClient.getOrCreateUser({getOrCreateUserBody:t}).then(e=>e.data).catch(e=>{throw x(e)});updateUser=({id:t,...e})=>this._innerClient.updateUser({id:t,updateUserBody:e}).then(s=>s.data).catch(s=>{throw x(s)});deleteUser=t=>this._innerClient.deleteUser(t).then(e=>e.data).catch(e=>{throw x(e)});getState=t=>this._innerClient.getState(t).then(e=>e.data).catch(e=>{throw x(e)});setState=({type:t,id:e,name:s,...a})=>this._innerClient.setState({type:t,id:e,name:s,setStateBody:a}).then(r=>r.data).catch(r=>{throw x(r)});patchState=({type:t,id:e,name:s,...a})=>this._innerClient.patchState({type:t,id:e,name:s,patchStateBody:a}).then(r=>r.data).catch(r=>{throw x(r)});callAction=t=>this._innerClient.callAction({callActionBody:t}).then(e=>e.data).catch(e=>{throw x(e)});configureIntegration=t=>this._innerClient.configureIntegration({configureIntegrationBody:t}).then(e=>e.data).catch(e=>{throw x(e)});listPublicIntegrations=t=>this._innerClient.listPublicIntegrations(t).then(e=>e.data).catch(e=>{throw x(e)});getPublicIntegrationById=t=>this._innerClient.getPublicIntegrationById(t).then(e=>e.data).catch(e=>{throw x(e)});getPublicIntegration=t=>this._innerClient.getPublicIntegration(t).then(e=>e.data).catch(e=>{throw x(e)});createBot=t=>this._innerClient.createBot({createBotBody:t}).then(e=>e.data).catch(e=>{throw x(e)});updateBot=({id:t,...e})=>this._innerClient.updateBot({id:t,updateBotBody:e}).then(s=>s.data).catch(s=>{throw x(s)});listBots=t=>this._innerClient.listBots(t).then(e=>e.data).catch(e=>{throw x(e)});getBot=t=>this._innerClient.getBot(t).then(e=>e.data).catch(e=>{throw x(e)});deleteBot=t=>this._innerClient.deleteBot(t).then(e=>e.data).catch(e=>{throw x(e)});getBotLogs=t=>this._innerClient.getBotLogs(t).then(e=>e.data).catch(e=>{throw x(e)});getBotWebchat=t=>this._innerClient.getBotWebchat(t).then(e=>e.data).catch(e=>{throw x(e)});getBotAnalytics=t=>this._innerClient.getBotAnalytics(t).then(e=>e.data).catch(e=>{throw x(e)});createIntegration=t=>this._innerClient.createIntegration({createIntegrationBody:t}).then(e=>e.data).catch(e=>{throw x(e)});updateIntegration=({id:t,...e})=>this._innerClient.updateIntegration({id:t,updateIntegrationBody:e}).then(s=>s.data).catch(s=>{throw x(s)});listIntegrations=t=>this._innerClient.listIntegrations(t).then(e=>e.data).catch(e=>{throw x(e)});getIntegration=t=>this._innerClient.getIntegration(t).then(e=>e.data).catch(e=>{throw x(e)});getIntegrationByName=t=>this._innerClient.getIntegrationByName(t).then(e=>e.data).catch(e=>{throw x(e)});deleteIntegration=t=>this._innerClient.deleteIntegration(t).then(e=>e.data).catch(e=>{throw x(e)});listWorkspaces=t=>this._innerClient.listWorkspaces(t).then(e=>e.data).catch(e=>{throw x(e)});introspect=t=>this._innerClient.introspect({introspectBody:t}).then(e=>e.data).catch(e=>{throw x(e)});createFile=t=>this._innerClient.createFile({createFileBody:t}).then(e=>e.data).catch(e=>{throw x(e)});getFile=t=>this._innerClient.getFile(t).then(e=>e.data).catch(e=>{throw x(e)});downloadFile=t=>this._innerClient.downloadFile(t).then(e=>e.data).catch(e=>{throw x(e)});deleteFile=t=>this._innerClient.deleteFile(t).then(e=>e.data).catch(e=>{throw x(e)});listFiles=t=>this._innerClient.listFiles(t).then(e=>e.data).catch(e=>{throw x(e)})};function x(n){return Re.isAxiosError(n)?H(n.response?.data):H(n)}import fe,{AxiosHeaders as K}from"axios";function z({oauthUrl:n,clientKey:t,clientSecret:e,getToken:s,getExpiry:a}){let r=null,o=null,i=!1,l=()=>r&&o&&o>Date.now(),c=async()=>{if(l())return r;i&&await Pe(()=>i===!1,1e4),i=!0;try{if(l())return r;let p=await me(n,t,e);return r=s(p),o=Date.now()+a(p),r}catch(p){throw p}finally{i=!1}};return c.reset=()=>{r=null,o=null},c}async function me(n,t,e){let s=await fe.post(n,new URLSearchParams({client_id:t,client_secret:e,grant_type:"client_credentials"}));return{token:s.data.access_token,expiresIn:s.data.expires_in}}var J=n=>async t=>{let e=await n(t),s=K.from({...t.headers,Authorization:`Bearer ${e}`});return{...t,headers:s}},Y=(n,t)=>async e=>{let{config:s}=e;if(e.response?.status===401&&!s._retry){e.config._retry=!0;let a=await t(s);return s.headers=K.from({...s.headers,Authorization:`Bearer ${a}`}),n.request(s)}return Promise.reject(e)};function Pe(n,t){return new Promise((e,s)=>{let a=Date.now(),r=setInterval(()=>{n()?(clearInterval(r),e()):Date.now()-a>t&&s(new Error("Timed out waiting for condition"))},100)})}var Z=class extends O{constructor(t={}){let e=$(t),{host:s,headers:a,withCredentials:r}=e;e.authStrategy==="token"&&(a.Authorization=`Bearer ${e.token}`);let o=Be.create({headers:a,maxBodyLength:100*1024*1024,maxContentLength:1024*1024*1024,withCredentials:r,timeout:1e4});if(e.authStrategy==="oauth"){let i=z({oauthUrl:e.oauthUrl,clientKey:e.clientKey,clientSecret:e.clientSecret,getToken:l=>l.token,getExpiry:l=>l.expiresIn*1e3});o.interceptors.request.use(J(i)),o.interceptors.response.use(void 0,Y(o,i))}super(void 0,s,o)}};export{Z as Client,E as ForbiddenError,D as InternalError,F as InvalidDataFormatError,k as InvalidIdentifierError,L as InvalidJsonSchemaError,w as InvalidPayloadError,j as InvalidQueryError,M as MethodNotFoundError,S as PayloadTooLargeError,N as ReferenceNotFoundError,_ as RelationConflictError,G as ResourceNotFoundError,Q as RuntimeError,T as UnauthorizedError,B as UnknownError,Ps as axios,H as errorFrom,ye as isApiError};
1
+ import Pe from"axios";import*as Ps from"axios";import{isBrowser as b,isNode as ee}from"browser-or-node";var I="https://api.botpress.cloud",te="https://oauth.botpress.cloud/oauth2/token",se="BP_API_URL",re="BP_OAUTH_URL",ne="BP_BOT_ID",ae="BP_INTEGRATION_ID",oe="BP_WORKSPACE_ID",ie="BP_TOKEN",le="BP_CLIENT_KEY",ce="BP_CLIENT_SECRET";function K(n){let t=pe(n),e={};return t.workspaceId&&(e["x-workspace-id"]=t.workspaceId),t.botId&&(e["x-bot-id"]=t.botId),t.integrationId&&(e["x-integration-id"]=t.integrationId),t.token?{authStrategy:"token",host:t.host??I,withCredentials:b,headers:e,token:t.token}:t.clientKey&&t.clientSecret&&t.oauthUrl?{authStrategy:"oauth",host:t.host??I,withCredentials:b,headers:e,clientKey:t.clientKey,clientSecret:t.clientSecret,oauthUrl:t.oauthUrl}:{host:t.host??I,withCredentials:b,headers:e,authStrategy:"none"}}function pe(n){return b?n:ee?ge(n):n}function ge(n){let t={...n,host:n.host??process.env[se]??I,oauthUrl:n.oauthUrl??process.env[re]??te,botId:n.botId??process.env[ne],integrationId:n.integrationId??process.env[ae],workspaceId:n.workspaceId??process.env[oe]},e=t.token??process.env[ie],s=t.clientKey??process.env[le],a=t.clientSecret??process.env[ce];return e?t.token=e:s&&a&&(t.clientKey=s,t.clientSecret=a),t}var m=class extends Error{constructor(e,s,a,r,o){super(r);this.code=e;this.description=s;this.type=a;this.message=r;this.error=o}isApiError=!0;toJSON(){return{code:this.code,type:this.type,message:this.message}}},ue=n=>typeof n=="object"&&!Array.isArray(n)&&n!==null,de=n=>n instanceof m||ue(n)&&n.isApiError===!0,B=class extends m{constructor(t,e){super(500,"An unknown error occurred","Unknown",t,e)}},T=class extends m{constructor(t,e){super(500,"An internal error occurred","Internal",t,e)}},D=class extends m{constructor(t,e){super(401,"The request requires to be authenticated.","Unauthorized",t,e)}},E=class extends m{constructor(t,e){super(403,"The requested action can't be peform by this resource.","Forbidden",t,e)}},M=class extends m{constructor(t,e){super(413,"The request payload is too large.","PayloadTooLarge",t,e)}},S=class extends m{constructor(t,e){super(400,"The request payload is invalid.","InvalidPayload",t,e)}},w=class extends m{constructor(t,e){super(415,"The request is invalid because the content-type is not supported.","UnsupportedMediaType",t,e)}},G=class extends m{constructor(t,e){super(405,"The requested method does not exist.","MethodNotFound",t,e)}},L=class extends m{constructor(t,e){super(404,"The requested resource does not exist.","ResourceNotFound",t,e)}},F=class extends m{constructor(t,e){super(400,"The provided JSON schema is invalid.","InvalidJsonSchema",t,e)}},k=class extends m{constructor(t,e){super(400,"The provided data doesn't respect the provided JSON schema.","InvalidDataFormat",t,e)}},_=class extends m{constructor(t,e){super(400,"The provided identifier is not valid. An identifier must start with a lowercase letter, be between 2 and 100 characters long and use only alphanumeric characters.","InvalidIdentifier",t,e)}},N=class extends m{constructor(t,e){super(409,"The resource is not related with another resource. This is usually caused when providing two resources that aren't linked together.","RelationConflict",t,e)}},j=class extends m{constructor(t,e){super(400,"The provided resource reference is missing. This is usually caused when providing an invalid id inside the payload of a request.","ReferenceNotFound",t,e)}},Q=class extends m{constructor(t,e){super(400,"The provided query is invalid. This is usually caused when providing an invalid parameter for querying a resource.","InvalidQuery",t,e)}},H=class extends m{constructor(t,e){super(400,"An error happened during the execution of a runtime (bot or integration).","Runtime",t,e)}},ye={Unknown:B,Internal:T,Unauthorized:D,Forbidden:E,PayloadTooLarge:M,InvalidPayload:S,UnsupportedMediaType:w,MethodNotFound:G,ResourceNotFound:L,InvalidJsonSchema:F,InvalidDataFormat:k,InvalidIdentifier:_,RelationConflict:N,ReferenceNotFound:j,InvalidQuery:Q,Runtime:H},W=n=>de(n)?n:n instanceof Error?new B(n.message,n):n===null?new B("An unknown error occurred"):typeof n=="string"?new B(n):typeof n!="object"?new B("An unknown error occurred"):he(n);function he(n){if("code"in n&&"type"in n&&"message"in n){if(typeof n.message!="string")return new B("An unknown error occurred");if(typeof n.type!="string")return new B(n.message);let t=ye[n.type];return t?new t(n.message):new B(n.message)}return new B("An unknown error occurred")}import xe from"axios";import A from"axios";import Ae from"axios";var g="https://api.botpress.cloud".replace(/\/+$/,"");var q=class{constructor(t,e=g,s=Ae){this.basePath=e;this.axios=s;t&&(this.configuration=t,this.basePath=t.basePath||this.basePath)}configuration},v=class extends Error{constructor(e,s){super(s);this.field=e}name="RequiredError"};import"axios";var u="https://example.com",R=function(n,t,e){if(e==null)throw new v(t,`Required parameter ${t} was null or undefined when calling ${n}.`)};function $(n,t,e=""){typeof t=="object"?Array.isArray(t)?t.forEach(s=>$(n,s,e)):Object.keys(t).forEach(s=>$(n,t[s],`${e}${e!==""?".":""}${s}`)):n.has(e)?n.append(e,t):n.set(e,t)}var d=function(n,...t){let e=new URLSearchParams(n.search);$(e,t),n.search=e.toString()},f=function(n,t,e){let s=typeof n!="string";return(s&&e&&e.isJsonMime?e.isJsonMime(t.headers["Content-Type"]):s)?JSON.stringify(n!==void 0?n:{}):n||""},y=function(n){return n.pathname+n.search+n.hash},h=function(n,t,e,s){return(a=t,r=e)=>{let o={...n.options,url:(s?.basePath||r)+n.url};return a.request(o)}};var Ce=function(n){return{callAction:async(t,e={})=>{let s="/v1/chat/actions",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},c={};i["Content-Type"]="application/json",d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},configureIntegration:async(t,e={})=>{let s="/v1/chat/integrations/configure",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},c={};i["Content-Type"]="application/json",d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createBot:async(t,e={})=>{let s="/v1/admin/bots",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},c={};i["Content-Type"]="application/json",d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createConversation:async(t,e={})=>{let s="/v1/chat/conversations",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},c={};i["Content-Type"]="application/json",d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createEvent:async(t,e={})=>{let s="/v1/chat/events",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},c={};i["Content-Type"]="application/json",d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createFile:async(t,e={})=>{let s="/v1/storage/files",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},c={};i["Content-Type"]="application/json",d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createIntegration:async(t,e={})=>{let s="/v1/admin/integrations",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},c={};i["Content-Type"]="application/json",d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createMessage:async(t,e={})=>{let s="/v1/chat/messages",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},c={};i["Content-Type"]="application/json",d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},createUser:async(t,e={})=>{let s="/v1/chat/users",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},c={};i["Content-Type"]="application/json",d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},deleteBot:async(t,e={})=>{R("deleteBot","id",t);let s="/v1/admin/bots/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"DELETE",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},deleteConversation:async(t,e={})=>{R("deleteConversation","id",t);let s="/v1/chat/conversations/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"DELETE",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},deleteFile:async(t,e={})=>{R("deleteFile","id",t);let s="/v1/storage/files/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"DELETE",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},deleteIntegration:async(t,e={})=>{R("deleteIntegration","id",t);let s="/v1/admin/integrations/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"DELETE",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},deleteMessage:async(t,e={})=>{R("deleteMessage","id",t);let s="/v1/chat/messages/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"DELETE",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},deleteUser:async(t,e={})=>{R("deleteUser","id",t);let s="/v1/chat/users/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"DELETE",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},downloadFile:async(t,e={})=>{R("downloadFile","id",t);let s="/v1/storage/files/{id}/download".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},getBot:async(t,e={})=>{R("getBot","id",t);let s="/v1/admin/bots/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},getBotAnalytics:async(t,e,s,a={})=>{R("getBotAnalytics","id",t),R("getBotAnalytics","startDate",e),R("getBotAnalytics","endDate",s);let r="/v1/admin/bots/{id}/analytics".replace("{id}",encodeURIComponent(String(t))),o=new URL(r,u),i;n&&(i=n.baseOptions);let c={method:"GET",...i,...a},l={},p={};e!==void 0&&(p.startDate=e),s!==void 0&&(p.endDate=s),d(o,p);let P=i&&i.headers?i.headers:{};return c.headers={...l,...P,...a.headers},{url:y(o),options:c}},getBotLogs:async(t,e={})=>{R("getBotLogs","id",t);let s="/v1/admin/bots/{id}/logs".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},getBotWebchat:async(t,e,s={})=>{R("getBotWebchat","id",t),R("getBotWebchat","type",e);let a="/v1/admin/bots/{id}/webchat".replace("{id}",encodeURIComponent(String(t))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"GET",...o,...s},c={},l={};e!==void 0&&(l.type=e),d(r,l);let p=o&&o.headers?o.headers:{};return i.headers={...c,...p,...s.headers},{url:y(r),options:i}},getConversation:async(t,e={})=>{R("getConversation","id",t);let s="/v1/chat/conversations/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},getEvent:async(t,e={})=>{R("getEvent","id",t);let s="/v1/chat/events/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},getFile:async(t,e={})=>{R("getFile","id",t);let s="/v1/storage/files/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},getIntegration:async(t,e={})=>{R("getIntegration","id",t);let s="/v1/admin/integrations/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},getIntegrationByName:async(t,e,s={})=>{R("getIntegrationByName","name",t),R("getIntegrationByName","version",e);let a="/v1/admin/integrations/{name}/{version}".replace("{name}",encodeURIComponent(String(t))).replace("{version}",encodeURIComponent(String(e))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"GET",...o,...s},c={};d(r,{});let p=o&&o.headers?o.headers:{};return i.headers={...c,...p,...s.headers},{url:y(r),options:i}},getMessage:async(t,e={})=>{R("getMessage","id",t);let s="/v1/chat/messages/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},getOrCreateConversation:async(t,e={})=>{let s="/v1/chat/conversations/get-or-create",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},c={};i["Content-Type"]="application/json",d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},getOrCreateMessage:async(t,e={})=>{let s="/v1/chat/messages/get-or-create",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},c={};i["Content-Type"]="application/json",d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},getOrCreateUser:async(t,e={})=>{let s="/v1/chat/users/get-or-create",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},c={};i["Content-Type"]="application/json",d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},getPublicIntegration:async(t,e,s={})=>{R("getPublicIntegration","name",t),R("getPublicIntegration","version",e);let a="/v1/admin/hub/integrations/{name}/{version}".replace("{name}",encodeURIComponent(String(t))).replace("{version}",encodeURIComponent(String(e))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"GET",...o,...s},c={};d(r,{});let p=o&&o.headers?o.headers:{};return i.headers={...c,...p,...s.headers},{url:y(r),options:i}},getPublicIntegrationById:async(t,e={})=>{R("getPublicIntegrationById","id",t);let s="/v1/admin/hub/integrations/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},getState:async(t,e,s,a={})=>{R("getState","type",t),R("getState","id",e),R("getState","name",s);let r="/v1/chat/states/{type}/{id}/{name}".replace("{type}",encodeURIComponent(String(t))).replace("{id}",encodeURIComponent(String(e))).replace("{name}",encodeURIComponent(String(s))),o=new URL(r,u),i;n&&(i=n.baseOptions);let c={method:"GET",...i,...a},l={};d(o,{});let P=i&&i.headers?i.headers:{};return c.headers={...l,...P,...a.headers},{url:y(o),options:c}},getUser:async(t,e={})=>{R("getUser","id",t);let s="/v1/chat/users/{id}".replace("{id}",encodeURIComponent(String(t))),a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={};d(a,{});let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},introspect:async(t,e={})=>{let s="/v1/admin/introspect",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"POST",...r,...e},i={},c={};i["Content-Type"]="application/json",d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},o.data=f(t,o,n),{url:y(a),options:o}},listBots:async(t,e={})=>{let s="/v1/admin/bots",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={},c={};t!==void 0&&(c.nextToken=t),d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},listConversations:async(t,e,s,a={})=>{let r="/v1/chat/conversations",o=new URL(r,u),i;n&&(i=n.baseOptions);let c={method:"GET",...i,...a},l={},p={};t!==void 0&&(p.nextToken=t),e!==void 0&&(p.tags=e),s&&(p.participantIds=s),d(o,p);let P=i&&i.headers?i.headers:{};return c.headers={...l,...P,...a.headers},{url:y(o),options:c}},listEvents:async(t,e={})=>{let s="/v1/chat/events",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={},c={};t!==void 0&&(c.nextToken=t),d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},listFiles:async(t,e,s={})=>{R("listFiles","botId",t);let a="/v1/storage/files",r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"GET",...o,...s},c={},l={};e!==void 0&&(l.nextToken=e),t!==void 0&&(l.botId=t),d(r,l);let p=o&&o.headers?o.headers:{};return i.headers={...c,...p,...s.headers},{url:y(r),options:i}},listIntegrations:async(t,e,s,a={})=>{let r="/v1/admin/integrations",o=new URL(r,u),i;n&&(i=n.baseOptions);let c={method:"GET",...i,...a},l={},p={};t!==void 0&&(p.nextToken=t),e!==void 0&&(p.name=e),s!==void 0&&(p.version=s),d(o,p);let P=i&&i.headers?i.headers:{};return c.headers={...l,...P,...a.headers},{url:y(o),options:c}},listMessages:async(t,e,s,a={})=>{let r="/v1/chat/messages",o=new URL(r,u),i;n&&(i=n.baseOptions);let c={method:"GET",...i,...a},l={},p={};t!==void 0&&(p.nextToken=t),e!==void 0&&(p.conversationId=e),s!==void 0&&(p.tags=s),d(o,p);let P=i&&i.headers?i.headers:{};return c.headers={...l,...P,...a.headers},{url:y(o),options:c}},listPublicIntegrations:async(t,e,s,a={})=>{let r="/v1/admin/hub/integrations",o=new URL(r,u),i;n&&(i=n.baseOptions);let c={method:"GET",...i,...a},l={},p={};t!==void 0&&(p.nextToken=t),e!==void 0&&(p.name=e),s!==void 0&&(p.version=s),d(o,p);let P=i&&i.headers?i.headers:{};return c.headers={...l,...P,...a.headers},{url:y(o),options:c}},listUsers:async(t,e,s,a={})=>{let r="/v1/chat/users",o=new URL(r,u),i;n&&(i=n.baseOptions);let c={method:"GET",...i,...a},l={},p={};t!==void 0&&(p.nextToken=t),e!==void 0&&(p.conversationId=e),s!==void 0&&(p.tags=s),d(o,p);let P=i&&i.headers?i.headers:{};return c.headers={...l,...P,...a.headers},{url:y(o),options:c}},listWorkspaces:async(t,e={})=>{let s="/v1/admin/workspaces",a=new URL(s,u),r;n&&(r=n.baseOptions);let o={method:"GET",...r,...e},i={},c={};t!==void 0&&(c.nextToken=t),d(a,c);let l=r&&r.headers?r.headers:{};return o.headers={...i,...l,...e.headers},{url:y(a),options:o}},patchState:async(t,e,s,a,r={})=>{R("patchState","type",t),R("patchState","id",e),R("patchState","name",s);let o="/v1/chat/states/{type}/{id}/{name}".replace("{type}",encodeURIComponent(String(t))).replace("{id}",encodeURIComponent(String(e))).replace("{name}",encodeURIComponent(String(s))),i=new URL(o,u),c;n&&(c=n.baseOptions);let l={method:"PATCH",...c,...r},p={},P={};p["Content-Type"]="application/json",d(i,P);let V=c&&c.headers?c.headers:{};return l.headers={...p,...V,...r.headers},l.data=f(a,l,n),{url:y(i),options:l}},setState:async(t,e,s,a,r={})=>{R("setState","type",t),R("setState","id",e),R("setState","name",s);let o="/v1/chat/states/{type}/{id}/{name}".replace("{type}",encodeURIComponent(String(t))).replace("{id}",encodeURIComponent(String(e))).replace("{name}",encodeURIComponent(String(s))),i=new URL(o,u),c;n&&(c=n.baseOptions);let l={method:"POST",...c,...r},p={},P={};p["Content-Type"]="application/json",d(i,P);let V=c&&c.headers?c.headers:{};return l.headers={...p,...V,...r.headers},l.data=f(a,l,n),{url:y(i),options:l}},updateBot:async(t,e,s={})=>{R("updateBot","id",t);let a="/v1/admin/bots/{id}".replace("{id}",encodeURIComponent(String(t))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"PUT",...o,...s},c={},l={};c["Content-Type"]="application/json",d(r,l);let p=o&&o.headers?o.headers:{};return i.headers={...c,...p,...s.headers},i.data=f(e,i,n),{url:y(r),options:i}},updateConversation:async(t,e,s={})=>{R("updateConversation","id",t);let a="/v1/chat/conversations/{id}".replace("{id}",encodeURIComponent(String(t))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"PUT",...o,...s},c={},l={};c["Content-Type"]="application/json",d(r,l);let p=o&&o.headers?o.headers:{};return i.headers={...c,...p,...s.headers},i.data=f(e,i,n),{url:y(r),options:i}},updateIntegration:async(t,e,s={})=>{R("updateIntegration","id",t);let a="/v1/admin/integrations/{id}".replace("{id}",encodeURIComponent(String(t))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"PUT",...o,...s},c={},l={};c["Content-Type"]="application/json",d(r,l);let p=o&&o.headers?o.headers:{};return i.headers={...c,...p,...s.headers},i.data=f(e,i,n),{url:y(r),options:i}},updateMessage:async(t,e,s={})=>{R("updateMessage","id",t);let a="/v1/chat/messages/{id}".replace("{id}",encodeURIComponent(String(t))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"PUT",...o,...s},c={},l={};c["Content-Type"]="application/json",d(r,l);let p=o&&o.headers?o.headers:{};return i.headers={...c,...p,...s.headers},i.data=f(e,i,n),{url:y(r),options:i}},updateUser:async(t,e,s={})=>{R("updateUser","id",t);let a="/v1/chat/users/{id}".replace("{id}",encodeURIComponent(String(t))),r=new URL(a,u),o;n&&(o=n.baseOptions);let i={method:"PUT",...o,...s},c={},l={};c["Content-Type"]="application/json",d(r,l);let p=o&&o.headers?o.headers:{};return i.headers={...c,...p,...s.headers},i.data=f(e,i,n),{url:y(r),options:i}}}},C=function(n){let t=Ce(n);return{async callAction(e,s){let a=await t.callAction(e,s);return h(a,A,g,n)},async configureIntegration(e,s){let a=await t.configureIntegration(e,s);return h(a,A,g,n)},async createBot(e,s){let a=await t.createBot(e,s);return h(a,A,g,n)},async createConversation(e,s){let a=await t.createConversation(e,s);return h(a,A,g,n)},async createEvent(e,s){let a=await t.createEvent(e,s);return h(a,A,g,n)},async createFile(e,s){let a=await t.createFile(e,s);return h(a,A,g,n)},async createIntegration(e,s){let a=await t.createIntegration(e,s);return h(a,A,g,n)},async createMessage(e,s){let a=await t.createMessage(e,s);return h(a,A,g,n)},async createUser(e,s){let a=await t.createUser(e,s);return h(a,A,g,n)},async deleteBot(e,s){let a=await t.deleteBot(e,s);return h(a,A,g,n)},async deleteConversation(e,s){let a=await t.deleteConversation(e,s);return h(a,A,g,n)},async deleteFile(e,s){let a=await t.deleteFile(e,s);return h(a,A,g,n)},async deleteIntegration(e,s){let a=await t.deleteIntegration(e,s);return h(a,A,g,n)},async deleteMessage(e,s){let a=await t.deleteMessage(e,s);return h(a,A,g,n)},async deleteUser(e,s){let a=await t.deleteUser(e,s);return h(a,A,g,n)},async downloadFile(e,s){let a=await t.downloadFile(e,s);return h(a,A,g,n)},async getBot(e,s){let a=await t.getBot(e,s);return h(a,A,g,n)},async getBotAnalytics(e,s,a,r){let o=await t.getBotAnalytics(e,s,a,r);return h(o,A,g,n)},async getBotLogs(e,s){let a=await t.getBotLogs(e,s);return h(a,A,g,n)},async getBotWebchat(e,s,a){let r=await t.getBotWebchat(e,s,a);return h(r,A,g,n)},async getConversation(e,s){let a=await t.getConversation(e,s);return h(a,A,g,n)},async getEvent(e,s){let a=await t.getEvent(e,s);return h(a,A,g,n)},async getFile(e,s){let a=await t.getFile(e,s);return h(a,A,g,n)},async getIntegration(e,s){let a=await t.getIntegration(e,s);return h(a,A,g,n)},async getIntegrationByName(e,s,a){let r=await t.getIntegrationByName(e,s,a);return h(r,A,g,n)},async getMessage(e,s){let a=await t.getMessage(e,s);return h(a,A,g,n)},async getOrCreateConversation(e,s){let a=await t.getOrCreateConversation(e,s);return h(a,A,g,n)},async getOrCreateMessage(e,s){let a=await t.getOrCreateMessage(e,s);return h(a,A,g,n)},async getOrCreateUser(e,s){let a=await t.getOrCreateUser(e,s);return h(a,A,g,n)},async getPublicIntegration(e,s,a){let r=await t.getPublicIntegration(e,s,a);return h(r,A,g,n)},async getPublicIntegrationById(e,s){let a=await t.getPublicIntegrationById(e,s);return h(a,A,g,n)},async getState(e,s,a,r){let o=await t.getState(e,s,a,r);return h(o,A,g,n)},async getUser(e,s){let a=await t.getUser(e,s);return h(a,A,g,n)},async introspect(e,s){let a=await t.introspect(e,s);return h(a,A,g,n)},async listBots(e,s){let a=await t.listBots(e,s);return h(a,A,g,n)},async listConversations(e,s,a,r){let o=await t.listConversations(e,s,a,r);return h(o,A,g,n)},async listEvents(e,s){let a=await t.listEvents(e,s);return h(a,A,g,n)},async listFiles(e,s,a){let r=await t.listFiles(e,s,a);return h(r,A,g,n)},async listIntegrations(e,s,a,r){let o=await t.listIntegrations(e,s,a,r);return h(o,A,g,n)},async listMessages(e,s,a,r){let o=await t.listMessages(e,s,a,r);return h(o,A,g,n)},async listPublicIntegrations(e,s,a,r){let o=await t.listPublicIntegrations(e,s,a,r);return h(o,A,g,n)},async listUsers(e,s,a,r){let o=await t.listUsers(e,s,a,r);return h(o,A,g,n)},async listWorkspaces(e,s){let a=await t.listWorkspaces(e,s);return h(a,A,g,n)},async patchState(e,s,a,r,o){let i=await t.patchState(e,s,a,r,o);return h(i,A,g,n)},async setState(e,s,a,r,o){let i=await t.setState(e,s,a,r,o);return h(i,A,g,n)},async updateBot(e,s,a){let r=await t.updateBot(e,s,a);return h(r,A,g,n)},async updateConversation(e,s,a){let r=await t.updateConversation(e,s,a);return h(r,A,g,n)},async updateIntegration(e,s,a){let r=await t.updateIntegration(e,s,a);return h(r,A,g,n)},async updateMessage(e,s,a){let r=await t.updateMessage(e,s,a);return h(r,A,g,n)},async updateUser(e,s,a){let r=await t.updateUser(e,s,a);return h(r,A,g,n)}}};var U=class extends q{callAction(t={},e){return C(this.configuration).callAction(t.callActionBody,e).then(s=>s(this.axios,this.basePath))}configureIntegration(t={},e){return C(this.configuration).configureIntegration(t.configureIntegrationBody,e).then(s=>s(this.axios,this.basePath))}createBot(t={},e){return C(this.configuration).createBot(t.createBotBody,e).then(s=>s(this.axios,this.basePath))}createConversation(t={},e){return C(this.configuration).createConversation(t.createConversationBody,e).then(s=>s(this.axios,this.basePath))}createEvent(t={},e){return C(this.configuration).createEvent(t.createEventBody,e).then(s=>s(this.axios,this.basePath))}createFile(t={},e){return C(this.configuration).createFile(t.createFileBody,e).then(s=>s(this.axios,this.basePath))}createIntegration(t={},e){return C(this.configuration).createIntegration(t.createIntegrationBody,e).then(s=>s(this.axios,this.basePath))}createMessage(t={},e){return C(this.configuration).createMessage(t.createMessageBody,e).then(s=>s(this.axios,this.basePath))}createUser(t={},e){return C(this.configuration).createUser(t.createUserBody,e).then(s=>s(this.axios,this.basePath))}deleteBot(t,e){return C(this.configuration).deleteBot(t.id,e).then(s=>s(this.axios,this.basePath))}deleteConversation(t,e){return C(this.configuration).deleteConversation(t.id,e).then(s=>s(this.axios,this.basePath))}deleteFile(t,e){return C(this.configuration).deleteFile(t.id,e).then(s=>s(this.axios,this.basePath))}deleteIntegration(t,e){return C(this.configuration).deleteIntegration(t.id,e).then(s=>s(this.axios,this.basePath))}deleteMessage(t,e){return C(this.configuration).deleteMessage(t.id,e).then(s=>s(this.axios,this.basePath))}deleteUser(t,e){return C(this.configuration).deleteUser(t.id,e).then(s=>s(this.axios,this.basePath))}downloadFile(t,e){return C(this.configuration).downloadFile(t.id,e).then(s=>s(this.axios,this.basePath))}getBot(t,e){return C(this.configuration).getBot(t.id,e).then(s=>s(this.axios,this.basePath))}getBotAnalytics(t,e){return C(this.configuration).getBotAnalytics(t.id,t.startDate,t.endDate,e).then(s=>s(this.axios,this.basePath))}getBotLogs(t,e){return C(this.configuration).getBotLogs(t.id,e).then(s=>s(this.axios,this.basePath))}getBotWebchat(t,e){return C(this.configuration).getBotWebchat(t.id,t.type,e).then(s=>s(this.axios,this.basePath))}getConversation(t,e){return C(this.configuration).getConversation(t.id,e).then(s=>s(this.axios,this.basePath))}getEvent(t,e){return C(this.configuration).getEvent(t.id,e).then(s=>s(this.axios,this.basePath))}getFile(t,e){return C(this.configuration).getFile(t.id,e).then(s=>s(this.axios,this.basePath))}getIntegration(t,e){return C(this.configuration).getIntegration(t.id,e).then(s=>s(this.axios,this.basePath))}getIntegrationByName(t,e){return C(this.configuration).getIntegrationByName(t.name,t.version,e).then(s=>s(this.axios,this.basePath))}getMessage(t,e){return C(this.configuration).getMessage(t.id,e).then(s=>s(this.axios,this.basePath))}getOrCreateConversation(t={},e){return C(this.configuration).getOrCreateConversation(t.getOrCreateConversationBody,e).then(s=>s(this.axios,this.basePath))}getOrCreateMessage(t={},e){return C(this.configuration).getOrCreateMessage(t.getOrCreateMessageBody,e).then(s=>s(this.axios,this.basePath))}getOrCreateUser(t={},e){return C(this.configuration).getOrCreateUser(t.getOrCreateUserBody,e).then(s=>s(this.axios,this.basePath))}getPublicIntegration(t,e){return C(this.configuration).getPublicIntegration(t.name,t.version,e).then(s=>s(this.axios,this.basePath))}getPublicIntegrationById(t,e){return C(this.configuration).getPublicIntegrationById(t.id,e).then(s=>s(this.axios,this.basePath))}getState(t,e){return C(this.configuration).getState(t.type,t.id,t.name,e).then(s=>s(this.axios,this.basePath))}getUser(t,e){return C(this.configuration).getUser(t.id,e).then(s=>s(this.axios,this.basePath))}introspect(t={},e){return C(this.configuration).introspect(t.introspectBody,e).then(s=>s(this.axios,this.basePath))}listBots(t={},e){return C(this.configuration).listBots(t.nextToken,e).then(s=>s(this.axios,this.basePath))}listConversations(t={},e){return C(this.configuration).listConversations(t.nextToken,t.tags,t.participantIds,e).then(s=>s(this.axios,this.basePath))}listEvents(t={},e){return C(this.configuration).listEvents(t.nextToken,e).then(s=>s(this.axios,this.basePath))}listFiles(t,e){return C(this.configuration).listFiles(t.botId,t.nextToken,e).then(s=>s(this.axios,this.basePath))}listIntegrations(t={},e){return C(this.configuration).listIntegrations(t.nextToken,t.name,t.version,e).then(s=>s(this.axios,this.basePath))}listMessages(t={},e){return C(this.configuration).listMessages(t.nextToken,t.conversationId,t.tags,e).then(s=>s(this.axios,this.basePath))}listPublicIntegrations(t={},e){return C(this.configuration).listPublicIntegrations(t.nextToken,t.name,t.version,e).then(s=>s(this.axios,this.basePath))}listUsers(t={},e){return C(this.configuration).listUsers(t.nextToken,t.conversationId,t.tags,e).then(s=>s(this.axios,this.basePath))}listWorkspaces(t={},e){return C(this.configuration).listWorkspaces(t.nextToken,e).then(s=>s(this.axios,this.basePath))}patchState(t,e){return C(this.configuration).patchState(t.type,t.id,t.name,t.patchStateBody,e).then(s=>s(this.axios,this.basePath))}setState(t,e){return C(this.configuration).setState(t.type,t.id,t.name,t.setStateBody,e).then(s=>s(this.axios,this.basePath))}updateBot(t,e){return C(this.configuration).updateBot(t.id,t.updateBotBody,e).then(s=>s(this.axios,this.basePath))}updateConversation(t,e){return C(this.configuration).updateConversation(t.id,t.updateConversationBody,e).then(s=>s(this.axios,this.basePath))}updateIntegration(t,e){return C(this.configuration).updateIntegration(t.id,t.updateIntegrationBody,e).then(s=>s(this.axios,this.basePath))}updateMessage(t,e){return C(this.configuration).updateMessage(t.id,t.updateMessageBody,e).then(s=>s(this.axios,this.basePath))}updateUser(t,e){return C(this.configuration).updateUser(t.id,t.updateUserBody,e).then(s=>s(this.axios,this.basePath))}};var O=class{_innerClient;constructor(t,e,s){this._innerClient=new U(t,e,s)}createConversation=t=>this._innerClient.createConversation({createConversationBody:t}).then(e=>e.data).catch(e=>{throw x(e)});getConversation=t=>this._innerClient.getConversation(t).then(e=>e.data).catch(e=>{throw x(e)});listConversations=t=>this._innerClient.listConversations(t).then(e=>e.data).catch(e=>{throw x(e)});getOrCreateConversation=t=>this._innerClient.getOrCreateConversation({getOrCreateConversationBody:t}).then(e=>e.data).catch(e=>{throw x(e)});updateConversation=({id:t,...e})=>this._innerClient.updateConversation({id:t,updateConversationBody:e}).then(s=>s.data).catch(s=>{throw x(s)});deleteConversation=t=>this._innerClient.deleteConversation(t).then(e=>e.data).catch(e=>{throw x(e)});createEvent=t=>this._innerClient.createEvent({createEventBody:t}).then(e=>e.data).catch(e=>{throw x(e)});getEvent=t=>this._innerClient.getEvent(t).then(e=>e.data).catch(e=>{throw x(e)});listEvents=t=>this._innerClient.listEvents(t).then(e=>e.data).catch(e=>{throw x(e)});createMessage=t=>this._innerClient.createMessage({createMessageBody:t}).then(e=>e.data).catch(e=>{throw x(e)});getOrCreateMessage=t=>this._innerClient.getOrCreateMessage({getOrCreateMessageBody:t}).then(e=>e.data).catch(e=>{throw x(e)});getMessage=t=>this._innerClient.getMessage(t).then(e=>e.data).catch(e=>{throw x(e)});updateMessage=({id:t,...e})=>this._innerClient.updateMessage({id:t,updateMessageBody:e}).then(s=>s.data).catch(s=>{throw x(s)});listMessages=t=>this._innerClient.listMessages(t).then(e=>e.data).catch(e=>{throw x(e)});deleteMessage=t=>this._innerClient.deleteMessage(t).then(e=>e.data).catch(e=>{throw x(e)});createUser=t=>this._innerClient.createUser({createUserBody:t}).then(e=>e.data).catch(e=>{throw x(e)});getUser=t=>this._innerClient.getUser(t).then(e=>e.data).catch(e=>{throw x(e)});listUsers=t=>this._innerClient.listUsers(t).then(e=>e.data).catch(e=>{throw x(e)});getOrCreateUser=t=>this._innerClient.getOrCreateUser({getOrCreateUserBody:t}).then(e=>e.data).catch(e=>{throw x(e)});updateUser=({id:t,...e})=>this._innerClient.updateUser({id:t,updateUserBody:e}).then(s=>s.data).catch(s=>{throw x(s)});deleteUser=t=>this._innerClient.deleteUser(t).then(e=>e.data).catch(e=>{throw x(e)});getState=t=>this._innerClient.getState(t).then(e=>e.data).catch(e=>{throw x(e)});setState=({type:t,id:e,name:s,...a})=>this._innerClient.setState({type:t,id:e,name:s,setStateBody:a}).then(r=>r.data).catch(r=>{throw x(r)});patchState=({type:t,id:e,name:s,...a})=>this._innerClient.patchState({type:t,id:e,name:s,patchStateBody:a}).then(r=>r.data).catch(r=>{throw x(r)});callAction=t=>this._innerClient.callAction({callActionBody:t}).then(e=>e.data).catch(e=>{throw x(e)});configureIntegration=t=>this._innerClient.configureIntegration({configureIntegrationBody:t}).then(e=>e.data).catch(e=>{throw x(e)});listPublicIntegrations=t=>this._innerClient.listPublicIntegrations(t).then(e=>e.data).catch(e=>{throw x(e)});getPublicIntegrationById=t=>this._innerClient.getPublicIntegrationById(t).then(e=>e.data).catch(e=>{throw x(e)});getPublicIntegration=t=>this._innerClient.getPublicIntegration(t).then(e=>e.data).catch(e=>{throw x(e)});createBot=t=>this._innerClient.createBot({createBotBody:t}).then(e=>e.data).catch(e=>{throw x(e)});updateBot=({id:t,...e})=>this._innerClient.updateBot({id:t,updateBotBody:e}).then(s=>s.data).catch(s=>{throw x(s)});listBots=t=>this._innerClient.listBots(t).then(e=>e.data).catch(e=>{throw x(e)});getBot=t=>this._innerClient.getBot(t).then(e=>e.data).catch(e=>{throw x(e)});deleteBot=t=>this._innerClient.deleteBot(t).then(e=>e.data).catch(e=>{throw x(e)});getBotLogs=t=>this._innerClient.getBotLogs(t).then(e=>e.data).catch(e=>{throw x(e)});getBotWebchat=t=>this._innerClient.getBotWebchat(t).then(e=>e.data).catch(e=>{throw x(e)});getBotAnalytics=t=>this._innerClient.getBotAnalytics(t).then(e=>e.data).catch(e=>{throw x(e)});createIntegration=t=>this._innerClient.createIntegration({createIntegrationBody:t}).then(e=>e.data).catch(e=>{throw x(e)});updateIntegration=({id:t,...e})=>this._innerClient.updateIntegration({id:t,updateIntegrationBody:e}).then(s=>s.data).catch(s=>{throw x(s)});listIntegrations=t=>this._innerClient.listIntegrations(t).then(e=>e.data).catch(e=>{throw x(e)});getIntegration=t=>this._innerClient.getIntegration(t).then(e=>e.data).catch(e=>{throw x(e)});getIntegrationByName=t=>this._innerClient.getIntegrationByName(t).then(e=>e.data).catch(e=>{throw x(e)});deleteIntegration=t=>this._innerClient.deleteIntegration(t).then(e=>e.data).catch(e=>{throw x(e)});listWorkspaces=t=>this._innerClient.listWorkspaces(t).then(e=>e.data).catch(e=>{throw x(e)});introspect=t=>this._innerClient.introspect({introspectBody:t}).then(e=>e.data).catch(e=>{throw x(e)});createFile=t=>this._innerClient.createFile({createFileBody:t}).then(e=>e.data).catch(e=>{throw x(e)});getFile=t=>this._innerClient.getFile(t).then(e=>e.data).catch(e=>{throw x(e)});downloadFile=t=>this._innerClient.downloadFile(t).then(e=>e.data).catch(e=>{throw x(e)});deleteFile=t=>this._innerClient.deleteFile(t).then(e=>e.data).catch(e=>{throw x(e)});listFiles=t=>this._innerClient.listFiles(t).then(e=>e.data).catch(e=>{throw x(e)})};function x(n){return xe.isAxiosError(n)?W(n.response?.data):W(n)}import Re,{AxiosHeaders as z}from"axios";function J({oauthUrl:n,clientKey:t,clientSecret:e,getToken:s,getExpiry:a}){let r=null,o=null,i=!1,c=()=>r&&o&&o>Date.now(),l=async()=>{if(c())return r;i&&await me(()=>i===!1,1e4),i=!0;try{if(c())return r;let p=await fe(n,t,e);return r=s(p),o=Date.now()+a(p),r}catch(p){throw p}finally{i=!1}};return l.reset=()=>{r=null,o=null},l}async function fe(n,t,e){let s=await Re.post(n,new URLSearchParams({client_id:t,client_secret:e,grant_type:"client_credentials"}));return{token:s.data.access_token,expiresIn:s.data.expires_in}}var Y=n=>async t=>{let e=await n(t),s=z.from({...t.headers,Authorization:`Bearer ${e}`});return{...t,headers:s}},Z=(n,t)=>async e=>{let{config:s}=e;if(e.response?.status===401&&!s._retry){e.config._retry=!0;let a=await t(s);return s.headers=z.from({...s.headers,Authorization:`Bearer ${a}`}),n.request(s)}return Promise.reject(e)};function me(n,t){return new Promise((e,s)=>{let a=Date.now(),r=setInterval(()=>{n()?(clearInterval(r),e()):Date.now()-a>t&&s(new Error("Timed out waiting for condition"))},100)})}var X=class extends O{config;constructor(t={}){let e=K(t),{host:s,headers:a,withCredentials:r,timeout:o}=e;e.authStrategy==="token"&&(a.Authorization=`Bearer ${e.token}`);let i=Pe.create({headers:a,maxBodyLength:100*1024*1024,maxContentLength:1024*1024*1024,withCredentials:r,timeout:o??6e4});if(e.authStrategy==="oauth"){let c=J({oauthUrl:e.oauthUrl,clientKey:e.clientKey,clientSecret:e.clientSecret,getToken:l=>l.token,getExpiry:l=>l.expiresIn*1e3});i.interceptors.request.use(Y(c)),i.interceptors.response.use(void 0,Z(i,c))}super(void 0,s,i),this.config=e}};export{X as Client,E as ForbiddenError,T as InternalError,k as InvalidDataFormatError,_ as InvalidIdentifierError,F as InvalidJsonSchemaError,S as InvalidPayloadError,Q as InvalidQueryError,G as MethodNotFoundError,M as PayloadTooLargeError,j as ReferenceNotFoundError,N as RelationConflictError,L as ResourceNotFoundError,H as RuntimeError,D as UnauthorizedError,B as UnknownError,w as UnsupportedMediaTypeError,Ps as axios,W as errorFrom,de as isApiError};
package/dist/oauth.d.ts CHANGED
@@ -1,24 +1,24 @@
1
- import { AxiosError, AxiosInstance, AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios';
2
- type OauthTokenResponse = {
3
- token: string;
4
- expiresIn: number;
5
- };
6
- export type OauthOptions = {
7
- oauthUrl: string;
8
- clientKey: string;
9
- clientSecret: string;
10
- getToken: (res: OauthTokenResponse) => string;
11
- getExpiry: (res: OauthTokenResponse) => number;
12
- };
13
- export declare function cacheOauth({ oauthUrl, clientKey, clientSecret, getToken, getExpiry }: OauthOptions): {
14
- (): Promise<string>;
15
- reset(): void;
16
- };
17
- export declare const requestInterceptor: (authenticate: (requestConfig: AxiosRequestConfig) => Promise<string>) => (config: AxiosRequestConfig) => Promise<InternalAxiosRequestConfig>;
18
- export type ErrorRetrier = AxiosError & {
19
- config: {
20
- _retry: boolean;
21
- };
22
- };
23
- export declare const errorInterceptor: (instance: AxiosInstance, authenticate: (requestConfig: AxiosRequestConfig) => Promise<string>) => (error: ErrorRetrier) => Promise<import("axios").AxiosResponse<any, any>>;
24
- export {};
1
+ import { AxiosError, AxiosInstance, AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios';
2
+ type OauthTokenResponse = {
3
+ token: string;
4
+ expiresIn: number;
5
+ };
6
+ export type OauthOptions = {
7
+ oauthUrl: string;
8
+ clientKey: string;
9
+ clientSecret: string;
10
+ getToken: (res: OauthTokenResponse) => string;
11
+ getExpiry: (res: OauthTokenResponse) => number;
12
+ };
13
+ export declare function cacheOauth({ oauthUrl, clientKey, clientSecret, getToken, getExpiry }: OauthOptions): {
14
+ (): Promise<string>;
15
+ reset(): void;
16
+ };
17
+ export declare const requestInterceptor: (authenticate: (requestConfig: AxiosRequestConfig) => Promise<string>) => (config: AxiosRequestConfig) => Promise<InternalAxiosRequestConfig>;
18
+ export type ErrorRetrier = AxiosError & {
19
+ config: {
20
+ _retry: boolean;
21
+ };
22
+ };
23
+ export declare const errorInterceptor: (instance: AxiosInstance, authenticate: (requestConfig: AxiosRequestConfig) => Promise<string>) => (error: ErrorRetrier) => Promise<import("axios").AxiosResponse<any, any>>;
24
+ export {};
package/package.json CHANGED
@@ -1,17 +1,11 @@
1
1
  {
2
2
  "name": "@botpress/client",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Botpress Client",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
8
8
  "license": "MIT",
9
- "scripts": {
10
- "build:type": "tsc --emitDeclarationOnly --declaration --target es2019 --module commonjs --moduleResolution node --lib es2019",
11
- "build:browser": "esbuild --bundle --external:axios --external:browser-or-node --platform=browser --format=esm --minify --outfile=dist/index.mjs src/index.ts",
12
- "build:node": "esbuild --bundle --external:axios --external:browser-or-node --platform=node --minify --sourcemap --outfile=dist/index.cjs src/index.ts",
13
- "build": "pnpm build:type && pnpm build:node && pnpm build:browser"
14
- },
15
9
  "dependencies": {
16
10
  "axios": "1.2.5",
17
11
  "browser-or-node": "^2.1.1"
@@ -19,5 +13,12 @@
19
13
  "devDependencies": {
20
14
  "type-fest": "^3.4.0",
21
15
  "esbuild": "^0.16.12"
16
+ },
17
+ "scripts": {
18
+ "build:type": "tsc --emitDeclarationOnly --declaration --target es2019 --module commonjs --moduleResolution node --lib es2019",
19
+ "build:browser": "esbuild --bundle --external:axios --external:browser-or-node --platform=browser --format=esm --minify --outfile=dist/index.mjs src/index.ts",
20
+ "build:node": "esbuild --bundle --external:axios --external:browser-or-node --platform=node --minify --sourcemap --outfile=dist/index.cjs src/index.ts",
21
+ "build:bundle": "esbuild --bundle --platform=node --minify --sourcemap --outfile=dist/bundle.cjs src/index.ts",
22
+ "build": "pnpm build:type && pnpm build:node && pnpm build:browser && pnpm build:bundle"
22
23
  }
23
- }
24
+ }