@great-detail/support-sdk 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-4WR77KQ5.js +1 -0
- package/dist/{chunk-2WFTGNNI.js → chunk-SEZCGFWP.js} +1 -1
- package/dist/cli/index.cjs +1 -1
- package/dist/cli/index.d.cts +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/{index-DCOax1hX.d.cts → index-CV2Xq9A0.d.cts} +227 -88
- package/dist/{index-DCOax1hX.d.ts → index-CV2Xq9A0.d.ts} +227 -88
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -11
- package/dist/index.d.ts +3 -11
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/Client/index.ts +9 -0
- package/src/{Subscription/CreateContactSubscription.ts → NotificationSubscription/CreateContactNotificationSubscription.ts} +7 -5
- package/src/{Subscription → NotificationSubscription}/index.ts +1 -1
- package/src/Transport/FetchTransport.ts +0 -1
- package/src/Webhook/index.ts +55 -0
- package/src/index.ts +2 -1
- package/dist/chunk-ILW336CI.js +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Nt=Object.create;var lt=Object.defineProperty;var Mt=Object.getOwnPropertyDescriptor;var Gt=Object.getOwnPropertyNames;var Bt=Object.getPrototypeOf,Pt=Object.prototype.hasOwnProperty;var _t=(r,t)=>{for(var e in t)lt(r,e,{get:t[e],enumerable:!0})},Et=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Gt(t))!Pt.call(r,n)&&n!==e&<(r,n,{get:()=>t[n],enumerable:!(s=Mt(t,n))||s.enumerable});return r};var St=(r,t,e)=>(e=r!=null?Nt(Bt(r)):{},Et(t||!r||!r.__esModule?lt(e,"default",{value:r,enumerable:!0}):e,r)),jt=r=>Et(lt({},"__esModule",{value:!0}),r);var zt={};_t(zt,{Client:()=>m,DEFAULT_SUPPORT_BASE_URL:()=>gt,Error:()=>xt,KeyAuthentication:()=>ct,PublicAuthentication:()=>ut,TokenAuthentication:()=>dt,default:()=>m});module.exports=jt(zt);var gt="https://api.support.greatdetail.com",vt={"X-Powered-By":"GDSupport/JavaScript"},Ot="api-key";var f=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/actions",{...t,method:"GET"})}};var h=require("zod"),b=class r{constructor(t){this._transport=t}static SCHEMA=h.z.object({title:h.z.string(),content:h.z.string(),account:h.z.string()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/boilerplate-categories/"+encodeURIComponent(t)+"/boilerplates",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var C=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/boilerplates/"+encodeURIComponent(t),{...e,method:"GET"})}};var A=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/boilerplate-categories/"+encodeURIComponent(t)+"/boilerplates",{...e,method:"GET"})}};var R=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/boilerplates",{...t,method:"GET"})}};var mt=require("zod"),y=class r{constructor(t){this._transport=t}static SCHEMA=mt.z.object({title:mt.z.string().optional(),content:mt.z.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/boilerplates/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var x=require("zod"),T=class r{constructor(t){this._transport=t}static SCHEMA=x.z.object({title:x.z.string(),description:x.z.string().optional(),account:x.z.string()});async send({body:t,request:e={}}){return this._transport.send("v1/boilerplate-categories",{...e,method:"POST",headers:{...e.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(t))})}};var _=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/boilerplate-categories/"+encodeURIComponent(t),{...e,method:"GET"})}};var E=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/boilerplate-categories",{...t,method:"GET"})}};var ft=require("zod"),S=class r{constructor(t){this._transport=t}static SCHEMA=ft.z.object({title:ft.z.string().optional(),description:ft.z.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/boilerplate-categories/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var v=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/channels",{...t,method:"GET"})}};var Ft="SUPPORT_ACCESS_TOKEN",Ut="SUPPORT_API_KEY",wt="SUPPORT_KEY_NAME",It="SUPPORT_BASE_URL";var O=class{constructor(t){this._transport=t}getRelativeURL({id:t,vcf:e={}}){let s=e.variant??"vcard",n=e.format??(e.variant==="vcard"?"vcf":"json");return"v1/contacts/"+encodeURIComponent(t)+"/vcf?variant="+encodeURIComponent(s)+"&format="+encodeURIComponent(n)}getURL(t){return this._transport.getURL(this.getRelativeURL(t))}};var l=require("zod"),F=class r{constructor(t){this._transport=t}static SCHEMA=l.z.object({name:l.z.string(),account:l.z.string(),emailAddress:l.z.string().email().optional(),telephoneNumber:l.z.string().optional()});async send({body:t,request:e={}}){return this._transport.send("v1/contacts",{...e,method:"POST",headers:{...e.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(t))})}};var U=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t),{...e,method:"GET"})}};var w=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/contacts",{...t,method:"GET"})}};var I=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t)+"/contacts",{...e,method:"GET"})}};var L=require("zod"),q=class r{constructor(t){this._transport=t}static SCHEMA=L.z.object({name:L.z.string().optional(),emailAddress:L.z.string().email().optional(),telephoneNumber:L.z.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var H=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t),{...e,method:"GET"})}};var N=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t)+"/conversations",{...e,method:"GET"})}};var M=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/conversations",{...t,method:"GET"})}};var G=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t)+"/conversations",{...e,method:"GET"})}};var ht=require("zod"),B=class r{constructor(t){this._transport=t}static SCHEMA=ht.z.object({conversationStatus:ht.z.enum(["AwaitingContactConversationStatus","AwaitingAgentConversationStatus","ResolvedConversationStatus","ClosedConversationStatus"]).optional(),hasEnded:ht.z.boolean().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var P=require("zod"),j=class r{constructor(t){this._transport=t}static SCHEMA=P.z.object({title:P.z.string(),description:P.z.string().optional(),account:P.z.string()});async send({body:t,request:e={}}){return this._transport.send("v1/labels",{...e,method:"POST",headers:{...e.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(t))})}};var z=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t),{...e,method:"DELETE"})}};var D=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t),{...e,method:"GET"})}};var V=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/labels",{...t,method:"GET"})}};var bt=require("zod"),J=class r{constructor(t){this._transport=t}static SCHEMA=bt.z.object({title:bt.z.string().optional(),description:bt.z.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var K=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t)+"/messages",{...e,method:"GET"})}};var k=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/messages",{...t,method:"GET"})}};var Y=require("zod"),$=class r{constructor(t){this._transport=t}static SCHEMA=Y.z.object({input:Y.z.string().max(65536),original:Y.z.string().max(65536),correction:Y.z.string().max(65536)});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/models/"+encodeURIComponent(t)+"/correction",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var W=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/models/"+encodeURIComponent(t),{...e,method:"GET"})}};var X=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/models",{...t,method:"GET"})}};var Q=require("zod"),Z=class r{constructor(t){this._transport=t}static SCHEMA=Q.z.array(Q.z.object({role:Q.z.enum(["user","assistant"]),content:Q.z.string().max(65536).nullable()})).min(1);async send({id:t,body:e,request:s={}}){return this._transport.send("v1/models/"+encodeURIComponent(t)+"/response",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var At=require("zod"),tt=class r{constructor(t){this._transport=t}static SCHEMA=At.z.object({content:At.z.string()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t)+"/notes",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var Rt=require("zod"),g=class r{constructor(t){this._transport=t}static SCHEMA=Rt.z.object({content:Rt.z.string()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t)+"/notes",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var et=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/notes/"+encodeURIComponent(t),{...e,method:"GET"})}};var rt=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t)+"/notes",{...e,method:"GET"})}};var st=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t)+"/notes",{...e,method:"GET"})}};var yt=require("zod"),ot=class r{constructor(t){this._transport=t}static SCHEMA=yt.z.object({content:yt.z.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/notes/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var nt=class r{constructor(t=r.STANDARD_HEADERS){this._standardHeaders=t}static STANDARD_HEADERS=vt;async filter(){return{headers:this.getHeaders()}}getHeaders(){return this._standardHeaders}};var it=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/sources/"+encodeURIComponent(t),{...e,method:"GET"})}};var at=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/sources",{...t,method:"GET"})}};var Lt=St(require("is-network-error"),1),Ct=St(require("ky"),1);var o=class extends Error{};var i=class extends o{};var p=class extends i{static unauthenticated(){return new this("An unauthenticated request occurred")}};var c=class extends i{static forbidden(){return new this("A forbidden request occurred")}};var a=class extends o{static notFound(t){return new this(`Record not found for request: ${t}`)}static forbiddenMethod(t,e){return new this(`Forbidden method for request: ${t} ${e}`)}};var d=class extends o{};var u=class extends o{static badRequest(){return new this("Bad request")}};var pt=class{client;options;constructor({baseURL:t,...e}){this.options={...e,baseURL:t},this.client=Ct.default.create({prefixUrl:this.options.baseURL,hooks:{beforeRequest:[s=>{for(let n of this.options.requestFilterables){let qt=n.getHeaders();for(let[Tt,Ht]of Object.entries(qt))s.headers.has(Tt)||s.headers.set(Tt,Ht)}}]}})}getURL(t){return new URL(t,this.options.baseURL).toString()}async send(t,e){return await this.client(t,e).catch(s=>{if((0,Lt.default)(s))throw new d("A network error occurred",{cause:s});if(s instanceof Ct.HTTPError){let n=s.response.status;switch(console.error(JSON.stringify(s.response)),n){case 400:throw u.badRequest();case 401:throw p.unauthenticated();case 403:throw c.forbidden();case 404:throw a.notFound(t);case 405:throw a.forbiddenMethod(t,e.method??"GET")}}throw s})}};var m=class r{static DEFAULT_BASE_URL=gt;_transport;constructor(t,{baseURL:e,...s}={}){this._transport=new pt({requestFilterables:[new nt,t],...s,baseURL:e?.toString()??r.getBaseURL()})}static getBaseURL(){return process.env[It]??this.DEFAULT_BASE_URL}get action(){return{list:new f(this._transport)}}get boilerplate(){return{get:new C(this._transport),list:new R(this._transport),update:new y(this._transport)}}get boilerplateCategory(){return{get:new _(this._transport),list:new E(this._transport),create:new T(this._transport),update:new S(this._transport),boilerplate:{list:new A(this._transport),create:new b(this._transport)}}}get channel(){return{list:new v(this._transport)}}get contact(){return{get:new U(this._transport),list:new w(this._transport),update:new q(this._transport),create:new F(this._transport),conversation:{list:new N(this._transport)},note:{list:new rt(this._transport),create:new tt(this._transport)},vcf:{get:new O(this._transport)}}}get conversation(){return{get:new H(this._transport),list:new M(this._transport),update:new B(this._transport),create:new g(this._transport),message:{list:new K(this._transport)},note:{list:new st(this._transport),create:new g(this._transport)}}}get label(){return{create:new j(this._transport),get:new D(this._transport),list:new V(this._transport),update:new J(this._transport),delete:new z(this._transport),contact:{list:new I(this._transport)},conversation:{list:new G(this._transport)}}}get message(){return{list:new k(this._transport)}}get model(){return{get:new W(this._transport),list:new X(this._transport),response:{create:new Z(this._transport)},correction:{create:new $(this._transport)}}}get note(){return{get:new et(this._transport),update:new ot(this._transport)}}get source(){return{get:new it(this._transport),list:new at(this._transport)}}};var xt={};_t(xt,{AuthError:()=>i,AuthenticationError:()=>p,AuthorizationError:()=>c,LogicError:()=>a,NetworkError:()=>d,SupportError:()=>o,ValidationError:()=>u});var ct=class r{static DEFAULT_NAME=Ot;name;#t;constructor({name:t=process.env[wt]??r.DEFAULT_NAME,key:e=process.env[Ut]}={}){if(!e)throw new Error("API Key option must be specified when using Key Authentication");this.name=t,this.#t=e}async filter(){return{headers:this.getHeaders()}}getHeaders(){return{Authorization:`Basic ${btoa(this.name+":"+this.#t)}`}}};var dt=class{#t;constructor({token:t=process.env[Ft]}={}){if(!t)throw new Error("Access Token option must be specified when using Token Authentication");this.#t=t}async filter(){return{headers:this.getHeaders()}}getHeaders(){return{Authorization:`Bearer ${this.#t}`}}};var ut=class{async filter(){return{headers:this.getHeaders()}}getHeaders(){return{}}};0&&(module.exports={Client,DEFAULT_SUPPORT_BASE_URL,Error,KeyAuthentication,PublicAuthentication,TokenAuthentication});
|
|
1
|
+
"use strict";var jt=Object.create;var ht=Object.defineProperty;var zt=Object.getOwnPropertyDescriptor;var Pt=Object.getOwnPropertyNames;var Dt=Object.getPrototypeOf,kt=Object.prototype.hasOwnProperty;var Ot=(r,t)=>{for(var e in t)ht(r,e,{get:t[e],enumerable:!0})},Ft=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Pt(t))!kt.call(r,i)&&i!==e&&ht(r,i,{get:()=>t[i],enumerable:!(s=zt(t,i))||s.enumerable});return r};var Ut=(r,t,e)=>(e=r!=null?jt(Dt(r)):{},Ft(t||!r||!r.__esModule?ht(e,"default",{value:r,enumerable:!0}):e,r)),Vt=r=>Ft(ht({},"__esModule",{value:!0}),r);var Jt={};Ot(Jt,{Client:()=>h,DEFAULT_SUPPORT_BASE_URL:()=>bt,Error:()=>St,KeyAuthentication:()=>gt,PublicAuthentication:()=>ft,TokenAuthentication:()=>mt,default:()=>h});module.exports=Vt(Jt);var bt="https://api.support.greatdetail.com",wt={"X-Powered-By":"GDSupport/JavaScript"},It="api-key";var b=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/actions",{...t,method:"GET"})}};var C=require("zod"),A=class r{constructor(t){this._transport=t}static SCHEMA=C.z.object({title:C.z.string(),content:C.z.string(),account:C.z.string()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/boilerplate-categories/"+encodeURIComponent(t)+"/boilerplates",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var R=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/boilerplates/"+encodeURIComponent(t),{...e,method:"GET"})}};var y=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/boilerplate-categories/"+encodeURIComponent(t)+"/boilerplates",{...e,method:"GET"})}};var x=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/boilerplates",{...t,method:"GET"})}};var Ct=require("zod"),T=class r{constructor(t){this._transport=t}static SCHEMA=Ct.z.object({title:Ct.z.string().optional(),content:Ct.z.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/boilerplates/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var _=require("zod"),E=class r{constructor(t){this._transport=t}static SCHEMA=_.z.object({title:_.z.string(),description:_.z.string().optional(),account:_.z.string()});async send({body:t,request:e={}}){return this._transport.send("v1/boilerplate-categories",{...e,method:"POST",headers:{...e.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(t))})}};var S=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/boilerplate-categories/"+encodeURIComponent(t),{...e,method:"GET"})}};var v=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/boilerplate-categories",{...t,method:"GET"})}};var At=require("zod"),O=class r{constructor(t){this._transport=t}static SCHEMA=At.z.object({title:At.z.string().optional(),description:At.z.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/boilerplate-categories/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var F=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/channels",{...t,method:"GET"})}};var Lt="SUPPORT_ACCESS_TOKEN",qt="SUPPORT_API_KEY",Ht="SUPPORT_KEY_NAME",Nt="SUPPORT_BASE_URL";var U=class{constructor(t){this._transport=t}getRelativeURL({id:t,vcf:e={}}){let s=e.variant??"vcard",i=e.format??(e.variant==="vcard"?"vcf":"json");return"v1/contacts/"+encodeURIComponent(t)+"/vcf?variant="+encodeURIComponent(s)+"&format="+encodeURIComponent(i)}getURL(t){return this._transport.getURL(this.getRelativeURL(t))}};var m=require("zod"),w=class r{constructor(t){this._transport=t}static SCHEMA=m.z.object({name:m.z.string(),account:m.z.string(),emailAddress:m.z.string().email().optional(),telephoneNumber:m.z.string().optional()});async send({body:t,request:e={}}){return this._transport.send("v1/contacts",{...e,method:"POST",headers:{...e.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(t))})}};var I=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t),{...e,method:"GET"})}};var L=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/contacts",{...t,method:"GET"})}};var q=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t)+"/contacts",{...e,method:"GET"})}};var H=require("zod"),N=class r{constructor(t){this._transport=t}static SCHEMA=H.z.object({name:H.z.string().optional(),emailAddress:H.z.string().email().optional(),telephoneNumber:H.z.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var M=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t),{...e,method:"GET"})}};var G=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t)+"/conversations",{...e,method:"GET"})}};var B=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/conversations",{...t,method:"GET"})}};var j=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t)+"/conversations",{...e,method:"GET"})}};var Rt=require("zod"),z=class r{constructor(t){this._transport=t}static SCHEMA=Rt.z.object({conversationStatus:Rt.z.enum(["AwaitingContactConversationStatus","AwaitingAgentConversationStatus","ResolvedConversationStatus","ClosedConversationStatus"]).optional(),hasEnded:Rt.z.boolean().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var P=require("zod"),D=class r{constructor(t){this._transport=t}static SCHEMA=P.z.object({title:P.z.string(),description:P.z.string().optional(),account:P.z.string()});async send({body:t,request:e={}}){return this._transport.send("v1/labels",{...e,method:"POST",headers:{...e.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(t))})}};var k=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t),{...e,method:"DELETE"})}};var V=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t),{...e,method:"GET"})}};var J=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/labels",{...t,method:"GET"})}};var yt=require("zod"),K=class r{constructor(t){this._transport=t}static SCHEMA=yt.z.object({title:yt.z.string().optional(),description:yt.z.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var Y=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t)+"/messages",{...e,method:"GET"})}};var $=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/messages",{...t,method:"GET"})}};var W=require("zod"),X=class r{constructor(t){this._transport=t}static SCHEMA=W.z.object({input:W.z.string().max(65536),original:W.z.string().max(65536),correction:W.z.string().max(65536)});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/models/"+encodeURIComponent(t)+"/correction",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var Q=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/models/"+encodeURIComponent(t),{...e,method:"GET"})}};var Z=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/models",{...t,method:"GET"})}};var tt=require("zod"),et=class r{constructor(t){this._transport=t}static SCHEMA=tt.z.array(tt.z.object({role:tt.z.enum(["user","assistant"]),content:tt.z.string().max(65536).nullable()})).min(1);async send({id:t,body:e,request:s={}}){return this._transport.send("v1/models/"+encodeURIComponent(t)+"/response",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var Tt=require("zod"),rt=class r{constructor(t){this._transport=t}static SCHEMA=Tt.z.object({content:Tt.z.string()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t)+"/notes",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var _t=require("zod"),f=class r{constructor(t){this._transport=t}static SCHEMA=_t.z.object({content:_t.z.string()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t)+"/notes",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var st=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/notes/"+encodeURIComponent(t),{...e,method:"GET"})}};var ot=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t)+"/notes",{...e,method:"GET"})}};var nt=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t)+"/notes",{...e,method:"GET"})}};var Et=require("zod"),it=class r{constructor(t){this._transport=t}static SCHEMA=Et.z.object({content:Et.z.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/notes/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var p=require("zod"),at=class r{constructor(t){this._transport=t}static SCHEMA=p.z.discriminatedUnion("type",[p.z.object({type:p.z.literal("vapid"),endpoint:p.z.string().url(),keys:p.z.object({p256dh:p.z.string(),auth:p.z.string()})})]);async send({id:t,body:e,request:s={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t)+"/subscriptions",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var pt=class r{constructor(t=r.STANDARD_HEADERS){this._standardHeaders=t}static STANDARD_HEADERS=wt;async filter(){return{headers:this.getHeaders()}}getHeaders(){return this._standardHeaders}};var ct=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/sources/"+encodeURIComponent(t),{...e,method:"GET"})}};var dt=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/sources",{...t,method:"GET"})}};var Mt=Ut(require("is-network-error"),1),xt=Ut(require("ky"),1);var o=class extends Error{};var a=class extends o{};var d=class extends a{static unauthenticated(){return new this("An unauthenticated request occurred")}};var u=class extends a{static forbidden(){return new this("A forbidden request occurred")}};var c=class extends o{static notFound(t){return new this(`Record not found for request: ${t}`)}static forbiddenMethod(t,e){return new this(`Forbidden method for request: ${t} ${e}`)}};var l=class extends o{};var g=class extends o{static badRequest(){return new this("Bad request")}};var ut=class{client;options;constructor({baseURL:t,...e}){this.options={...e,baseURL:t},this.client=xt.default.create({prefixUrl:this.options.baseURL,hooks:{beforeRequest:[s=>{for(let i of this.options.requestFilterables){let Gt=i.getHeaders();for(let[vt,Bt]of Object.entries(Gt))s.headers.has(vt)||s.headers.set(vt,Bt)}}]}})}getURL(t){return new URL(t,this.options.baseURL).toString()}async send(t,e){return await this.client(t,e).catch(s=>{if((0,Mt.default)(s))throw new l("A network error occurred",{cause:s});if(s instanceof xt.HTTPError){let i=s.response.status;switch(console.error(JSON.stringify(s.response)),i){case 400:throw g.badRequest();case 401:throw d.unauthenticated();case 403:throw u.forbidden();case 404:throw c.notFound(t);case 405:throw c.forbiddenMethod(t,e.method??"GET")}}throw s})}};var n=require("zod"),lt=class r{constructor(t){this._client=t}static SCHEMA=n.z.object({event:n.z.intersection(n.z.object({id:n.z.string(),createdAt:n.z.string().datetime()}),n.z.discriminatedUnion("type",[n.z.object({type:n.z.literal("contact.created"),contact:n.z.string()}),n.z.object({type:n.z.literal("message.created"),message:n.z.string()})]))});async event({request:t}){let{event:e}=r.SCHEMA.parse(t.body);return{event:e}}};var h=class r{static DEFAULT_BASE_URL=bt;_transport;constructor(t,{baseURL:e,...s}={}){this._transport=new ut({requestFilterables:[new pt,t],...s,baseURL:e?.toString()??r.getBaseURL()})}static getBaseURL(){return process.env[Nt]??this.DEFAULT_BASE_URL}get action(){return{list:new b(this._transport)}}get boilerplate(){return{get:new R(this._transport),list:new x(this._transport),update:new T(this._transport)}}get boilerplateCategory(){return{get:new S(this._transport),list:new v(this._transport),create:new E(this._transport),update:new O(this._transport),boilerplate:{list:new y(this._transport),create:new A(this._transport)}}}get channel(){return{list:new F(this._transport)}}get contact(){return{get:new I(this._transport),list:new L(this._transport),update:new N(this._transport),create:new w(this._transport),conversation:{list:new G(this._transport)},note:{list:new ot(this._transport),create:new rt(this._transport)},notificationSubscription:{create:new at(this._transport)},vcf:{get:new U(this._transport)}}}get conversation(){return{get:new M(this._transport),list:new B(this._transport),update:new z(this._transport),create:new f(this._transport),message:{list:new Y(this._transport)},note:{list:new nt(this._transport),create:new f(this._transport)}}}get label(){return{create:new D(this._transport),get:new V(this._transport),list:new J(this._transport),update:new K(this._transport),delete:new k(this._transport),contact:{list:new q(this._transport)},conversation:{list:new j(this._transport)}}}get message(){return{list:new $(this._transport)}}get model(){return{get:new Q(this._transport),list:new Z(this._transport),response:{create:new et(this._transport)},correction:{create:new X(this._transport)}}}get note(){return{get:new st(this._transport),update:new it(this._transport)}}get source(){return{get:new ct(this._transport),list:new dt(this._transport)}}get webhook(){return new lt(this)}};var St={};Ot(St,{AuthError:()=>a,AuthenticationError:()=>d,AuthorizationError:()=>u,LogicError:()=>c,NetworkError:()=>l,SupportError:()=>o,ValidationError:()=>g});var gt=class r{static DEFAULT_NAME=It;name;#t;constructor({name:t=process.env[Ht]??r.DEFAULT_NAME,key:e=process.env[qt]}={}){if(!e)throw new Error("API Key option must be specified when using Key Authentication");this.name=t,this.#t=e}async filter(){return{headers:this.getHeaders()}}getHeaders(){return{Authorization:`Basic ${btoa(this.name+":"+this.#t)}`}}};var mt=class{#t;constructor({token:t=process.env[Lt]}={}){if(!t)throw new Error("Access Token option must be specified when using Token Authentication");this.#t=t}async filter(){return{headers:this.getHeaders()}}getHeaders(){return{Authorization:`Bearer ${this.#t}`}}};var ft=class{async filter(){return{headers:this.getHeaders()}}getHeaders(){return{}}};0&&(module.exports={Client,DEFAULT_SUPPORT_BASE_URL,Error,KeyAuthentication,PublicAuthentication,TokenAuthentication});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as Authentication } from './index-
|
|
2
|
-
export { C as Client, b as CreateBoilerplateCategoryBoilerplateResponse, e as CreateBoilerplateCategoryResponse, H as CreateContactNoteResponse, j as CreateContactResponse, I as CreateConversationNoteResponse, E as CreateCorrectionResponse, t as CreateLabelResponse, F as CreateResponseResponse, D as DeleteLabelResponse, f as GetBoilerplateCategoryResponse, G as GetBoilerplateResponse, k as GetContactResponse, o as GetConversationResponse, u as GetLabelResponse, z as GetModelResponse, J as GetNoteResponse, P as GetSourceResponse, L as ListActionsResponse, g as ListBoilerplateCategoriesResponse, c as ListBoilerplateCategoryBoilerplatesResponse, d as ListBoilerplatesResponse, i as ListChannelsResponse, s as ListContactConversationsResponse, K as ListContactNotesResponse, l as ListContactsResponse, x as ListConversationMessagesResponse, M as ListConversationNotesResponse, p as ListConversationsResponse, m as ListLabelContactsResponse, q as ListLabelConversationsResponse, v as ListLabelsResponse, y as ListMessagesResponse, B as ListModelsResponse, Q as ListSourcesResponse, O as Options, R as RequestFilterable, a as TransportOptions, h as UpdateBoilerplateCategoryResponse, U as UpdateBoilerplateResponse, n as UpdateContactResponse, r as UpdateConversationResponse, w as UpdateLabelResponse, N as UpdateNoteResponse, C as default } from './index-
|
|
1
|
+
import { A as Authentication } from './index-CV2Xq9A0.cjs';
|
|
2
|
+
export { C as Client, b as CreateBoilerplateCategoryBoilerplateResponse, e as CreateBoilerplateCategoryResponse, H as CreateContactNoteResponse, S as CreateContactNotificationSubscriptionResponse, j as CreateContactResponse, I as CreateConversationNoteResponse, E as CreateCorrectionResponse, t as CreateLabelResponse, F as CreateResponseResponse, D as DeleteLabelResponse, f as GetBoilerplateCategoryResponse, G as GetBoilerplateResponse, k as GetContactResponse, o as GetConversationResponse, u as GetLabelResponse, z as GetModelResponse, J as GetNoteResponse, P as GetSourceResponse, L as ListActionsResponse, g as ListBoilerplateCategoriesResponse, c as ListBoilerplateCategoryBoilerplatesResponse, d as ListBoilerplatesResponse, i as ListChannelsResponse, s as ListContactConversationsResponse, K as ListContactNotesResponse, l as ListContactsResponse, x as ListConversationMessagesResponse, M as ListConversationNotesResponse, p as ListConversationsResponse, m as ListLabelContactsResponse, q as ListLabelConversationsResponse, v as ListLabelsResponse, y as ListMessagesResponse, B as ListModelsResponse, Q as ListSourcesResponse, O as Options, R as RequestFilterable, a as TransportOptions, h as UpdateBoilerplateCategoryResponse, U as UpdateBoilerplateResponse, n as UpdateContactResponse, r as UpdateConversationResponse, w as UpdateLabelResponse, N as UpdateNoteResponse, W as WebhookResponse, C as default } from './index-CV2Xq9A0.cjs';
|
|
3
3
|
import 'ky';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
@@ -224,12 +224,4 @@ type CreateConversationResponse = {
|
|
|
224
224
|
};
|
|
225
225
|
};
|
|
226
226
|
|
|
227
|
-
type
|
|
228
|
-
subscription: {
|
|
229
|
-
id: string;
|
|
230
|
-
createdAt: string;
|
|
231
|
-
updatedAt: string;
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
export { type CreateContactSubscriptionResponse, type CreateConversationResponse, DEFAULT_SUPPORT_BASE_URL, index as Error, KeyAuthentication, PublicAuthentication, TokenAuthentication };
|
|
227
|
+
export { type CreateConversationResponse, DEFAULT_SUPPORT_BASE_URL, index as Error, KeyAuthentication, PublicAuthentication, TokenAuthentication };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as Authentication } from './index-
|
|
2
|
-
export { C as Client, b as CreateBoilerplateCategoryBoilerplateResponse, e as CreateBoilerplateCategoryResponse, H as CreateContactNoteResponse, j as CreateContactResponse, I as CreateConversationNoteResponse, E as CreateCorrectionResponse, t as CreateLabelResponse, F as CreateResponseResponse, D as DeleteLabelResponse, f as GetBoilerplateCategoryResponse, G as GetBoilerplateResponse, k as GetContactResponse, o as GetConversationResponse, u as GetLabelResponse, z as GetModelResponse, J as GetNoteResponse, P as GetSourceResponse, L as ListActionsResponse, g as ListBoilerplateCategoriesResponse, c as ListBoilerplateCategoryBoilerplatesResponse, d as ListBoilerplatesResponse, i as ListChannelsResponse, s as ListContactConversationsResponse, K as ListContactNotesResponse, l as ListContactsResponse, x as ListConversationMessagesResponse, M as ListConversationNotesResponse, p as ListConversationsResponse, m as ListLabelContactsResponse, q as ListLabelConversationsResponse, v as ListLabelsResponse, y as ListMessagesResponse, B as ListModelsResponse, Q as ListSourcesResponse, O as Options, R as RequestFilterable, a as TransportOptions, h as UpdateBoilerplateCategoryResponse, U as UpdateBoilerplateResponse, n as UpdateContactResponse, r as UpdateConversationResponse, w as UpdateLabelResponse, N as UpdateNoteResponse, C as default } from './index-
|
|
1
|
+
import { A as Authentication } from './index-CV2Xq9A0.js';
|
|
2
|
+
export { C as Client, b as CreateBoilerplateCategoryBoilerplateResponse, e as CreateBoilerplateCategoryResponse, H as CreateContactNoteResponse, S as CreateContactNotificationSubscriptionResponse, j as CreateContactResponse, I as CreateConversationNoteResponse, E as CreateCorrectionResponse, t as CreateLabelResponse, F as CreateResponseResponse, D as DeleteLabelResponse, f as GetBoilerplateCategoryResponse, G as GetBoilerplateResponse, k as GetContactResponse, o as GetConversationResponse, u as GetLabelResponse, z as GetModelResponse, J as GetNoteResponse, P as GetSourceResponse, L as ListActionsResponse, g as ListBoilerplateCategoriesResponse, c as ListBoilerplateCategoryBoilerplatesResponse, d as ListBoilerplatesResponse, i as ListChannelsResponse, s as ListContactConversationsResponse, K as ListContactNotesResponse, l as ListContactsResponse, x as ListConversationMessagesResponse, M as ListConversationNotesResponse, p as ListConversationsResponse, m as ListLabelContactsResponse, q as ListLabelConversationsResponse, v as ListLabelsResponse, y as ListMessagesResponse, B as ListModelsResponse, Q as ListSourcesResponse, O as Options, R as RequestFilterable, a as TransportOptions, h as UpdateBoilerplateCategoryResponse, U as UpdateBoilerplateResponse, n as UpdateContactResponse, r as UpdateConversationResponse, w as UpdateLabelResponse, N as UpdateNoteResponse, W as WebhookResponse, C as default } from './index-CV2Xq9A0.js';
|
|
3
3
|
import 'ky';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
@@ -224,12 +224,4 @@ type CreateConversationResponse = {
|
|
|
224
224
|
};
|
|
225
225
|
};
|
|
226
226
|
|
|
227
|
-
type
|
|
228
|
-
subscription: {
|
|
229
|
-
id: string;
|
|
230
|
-
createdAt: string;
|
|
231
|
-
updatedAt: string;
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
export { type CreateContactSubscriptionResponse, type CreateConversationResponse, DEFAULT_SUPPORT_BASE_URL, index as Error, KeyAuthentication, PublicAuthentication, TokenAuthentication };
|
|
227
|
+
export { type CreateConversationResponse, DEFAULT_SUPPORT_BASE_URL, index as Error, KeyAuthentication, PublicAuthentication, TokenAuthentication };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as d,b as g,c as s,d as
|
|
1
|
+
import{a as d,b as g,c as s,d as p,e as n,f as a,g as f,h as m,i as u,j as c,k as l,l as x,m as h,n as A,o as _}from"./chunk-4WR77KQ5.js";var E={};d(E,{AuthError:()=>m,AuthenticationError:()=>u,AuthorizationError:()=>c,LogicError:()=>l,NetworkError:()=>x,SupportError:()=>f,ValidationError:()=>h});var t=class o{static DEFAULT_NAME=s;name;#r;constructor({name:r=process.env[a]??o.DEFAULT_NAME,key:i=process.env[n]}={}){if(!i)throw new Error("API Key option must be specified when using Key Authentication");this.name=r,this.#r=i}async filter(){return{headers:this.getHeaders()}}getHeaders(){return{Authorization:`Basic ${btoa(this.name+":"+this.#r)}`}}};var e=class{#r;constructor({token:r=process.env[p]}={}){if(!r)throw new Error("Access Token option must be specified when using Token Authentication");this.#r=r}async filter(){return{headers:this.getHeaders()}}getHeaders(){return{Authorization:`Bearer ${this.#r}`}}};export{A as Client,g as DEFAULT_SUPPORT_BASE_URL,E as Error,t as KeyAuthentication,_ as PublicAuthentication,e as TokenAuthentication,A as default};
|
package/package.json
CHANGED
package/src/Client/index.ts
CHANGED
|
@@ -49,10 +49,12 @@ import GetNote from "../Note/GetNote.js";
|
|
|
49
49
|
import ListContactNotes from "../Note/ListContactNotes.js";
|
|
50
50
|
import ListConversationNotes from "../Note/ListConversationNotes.js";
|
|
51
51
|
import UpdateNote from "../Note/UpdateNote.js";
|
|
52
|
+
import CreateContactNotificationSubscription from "../NotificationSubscription/CreateContactNotificationSubscription.js";
|
|
52
53
|
import RequestStandardHeaders from "../Request/RequestStandardHeaders.js";
|
|
53
54
|
import GetSource from "../Source/GetSource.js";
|
|
54
55
|
import ListSources from "../Source/ListSources.js";
|
|
55
56
|
import FetchTransport from "../Transport/FetchTransport.js";
|
|
57
|
+
import Webhook from "../Webhook/index.js";
|
|
56
58
|
|
|
57
59
|
export interface Options {
|
|
58
60
|
baseURL?: string | URL;
|
|
@@ -124,6 +126,9 @@ export default class Client {
|
|
|
124
126
|
list: new ListContactNotes(this._transport),
|
|
125
127
|
create: new CreateContactNote(this._transport),
|
|
126
128
|
},
|
|
129
|
+
notificationSubscription: {
|
|
130
|
+
create: new CreateContactNotificationSubscription(this._transport),
|
|
131
|
+
},
|
|
127
132
|
vcf: {
|
|
128
133
|
get: new GetContactVCFURL(this._transport),
|
|
129
134
|
},
|
|
@@ -194,4 +199,8 @@ export default class Client {
|
|
|
194
199
|
list: new ListSources(this._transport),
|
|
195
200
|
};
|
|
196
201
|
}
|
|
202
|
+
|
|
203
|
+
public get webhook() {
|
|
204
|
+
return new Webhook(this);
|
|
205
|
+
}
|
|
197
206
|
}
|
|
@@ -12,11 +12,11 @@ import FetchTransport from "../Transport/FetchTransport.js";
|
|
|
12
12
|
|
|
13
13
|
export interface Options {
|
|
14
14
|
id: string;
|
|
15
|
-
body: z.infer<typeof
|
|
15
|
+
body: z.infer<typeof CreateContactNotificationSubscription.SCHEMA>;
|
|
16
16
|
request?: RequestInit;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export type
|
|
19
|
+
export type CreateContactNotificationSubscriptionResponse = {
|
|
20
20
|
subscription: {
|
|
21
21
|
id: string;
|
|
22
22
|
createdAt: string;
|
|
@@ -24,7 +24,7 @@ export type CreateContactSubscriptionResponse = {
|
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export default class
|
|
27
|
+
export default class CreateContactNotificationSubscription {
|
|
28
28
|
public static SCHEMA = z.discriminatedUnion("type", [
|
|
29
29
|
z.object({
|
|
30
30
|
type: z.literal("vapid"),
|
|
@@ -39,7 +39,7 @@ export default class CreateContactSubscription {
|
|
|
39
39
|
constructor(protected _transport: FetchTransport) {}
|
|
40
40
|
|
|
41
41
|
public async send({ id, body, request = {} }: Options) {
|
|
42
|
-
return this._transport.send<
|
|
42
|
+
return this._transport.send<CreateContactNotificationSubscriptionResponse>(
|
|
43
43
|
"v1/contacts/" + encodeURIComponent(id) + "/subscriptions",
|
|
44
44
|
{
|
|
45
45
|
...request,
|
|
@@ -48,7 +48,9 @@ export default class CreateContactSubscription {
|
|
|
48
48
|
...request.headers,
|
|
49
49
|
"Content-Type": "application/json",
|
|
50
50
|
},
|
|
51
|
-
body: JSON.stringify(
|
|
51
|
+
body: JSON.stringify(
|
|
52
|
+
CreateContactNotificationSubscription.SCHEMA.parse(body),
|
|
53
|
+
),
|
|
52
54
|
},
|
|
53
55
|
);
|
|
54
56
|
}
|
|
@@ -62,7 +62,6 @@ export default class FetchTransport implements Transport {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
public async send<T = unknown>(url: string, request: RequestInit) {
|
|
65
|
-
// See: https://github.com/node-fetch/node-fetch/issues/481#issuecomment-592491825
|
|
66
65
|
return await this.client<T>(url, request).catch((error) => {
|
|
67
66
|
if (isNetworkError(error)) {
|
|
68
67
|
throw new NetworkError("A network error occurred", { cause: error });
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import Client from "../Client/index.js";
|
|
12
|
+
|
|
13
|
+
export type Options = {
|
|
14
|
+
request: {
|
|
15
|
+
body: unknown;
|
|
16
|
+
headers: Record<string, string | string[]>;
|
|
17
|
+
[key: string]: unknown | undefined;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type WebhookResponse = z.infer<typeof Webhook.SCHEMA>;
|
|
22
|
+
|
|
23
|
+
export default class Webhook {
|
|
24
|
+
public static SCHEMA = z.object({
|
|
25
|
+
event: z.intersection(
|
|
26
|
+
z.object({
|
|
27
|
+
id: z.string(),
|
|
28
|
+
createdAt: z.string().datetime(),
|
|
29
|
+
}),
|
|
30
|
+
z.discriminatedUnion("type", [
|
|
31
|
+
z.object({
|
|
32
|
+
type: z.literal("contact.created"),
|
|
33
|
+
contact: z.string(),
|
|
34
|
+
}),
|
|
35
|
+
z.object({
|
|
36
|
+
type: z.literal("message.created"),
|
|
37
|
+
message: z.string(),
|
|
38
|
+
}),
|
|
39
|
+
]),
|
|
40
|
+
),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
constructor(protected _client: Client) {}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Pre-release Functionality
|
|
47
|
+
*/
|
|
48
|
+
public async event({ request }: Options) {
|
|
49
|
+
const { event } = Webhook.SCHEMA.parse(request.body);
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
event,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -35,4 +35,5 @@ export * from "./Message/index.js";
|
|
|
35
35
|
export * from "./Model/index.js";
|
|
36
36
|
export * from "./Note/index.js";
|
|
37
37
|
export * from "./Source/index.js";
|
|
38
|
-
export * from "./
|
|
38
|
+
export * from "./NotificationSubscription/index.js";
|
|
39
|
+
export { type WebhookResponse } from "./Webhook/index.js";
|
package/dist/chunk-ILW336CI.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var xt=Object.defineProperty;var Ot=(r,t)=>{for(var e in t)xt(r,e,{get:t[e],enumerable:!0})};var ht="https://api.support.greatdetail.com",ft={"X-Powered-By":"GDSupport/JavaScript"},Ft="api-key";var c=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/actions",{...t,method:"GET"})}};import{z as rt}from"zod";var d=class r{constructor(t){this._transport=t}static SCHEMA=rt.object({title:rt.string(),content:rt.string(),account:rt.string()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/boilerplate-categories/"+encodeURIComponent(t)+"/boilerplates",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var l=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/boilerplates/"+encodeURIComponent(t),{...e,method:"GET"})}};var u=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/boilerplate-categories/"+encodeURIComponent(t)+"/boilerplates",{...e,method:"GET"})}};var g=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/boilerplates",{...t,method:"GET"})}};import{z as pt}from"zod";var m=class r{constructor(t){this._transport=t}static SCHEMA=pt.object({title:pt.string().optional(),content:pt.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/boilerplates/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};import{z as st}from"zod";var h=class r{constructor(t){this._transport=t}static SCHEMA=st.object({title:st.string(),description:st.string().optional(),account:st.string()});async send({body:t,request:e={}}){return this._transport.send("v1/boilerplate-categories",{...e,method:"POST",headers:{...e.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(t))})}};var f=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/boilerplate-categories/"+encodeURIComponent(t),{...e,method:"GET"})}};var C=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/boilerplate-categories",{...t,method:"GET"})}};import{z as ct}from"zod";var b=class r{constructor(t){this._transport=t}static SCHEMA=ct.object({title:ct.string().optional(),description:ct.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/boilerplate-categories/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var R=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/channels",{...t,method:"GET"})}};var Kt="SUPPORT_ACCESS_TOKEN",kt="SUPPORT_API_KEY",Yt="SUPPORT_KEY_NAME",Ct="SUPPORT_BASE_URL";var A=class{constructor(t){this._transport=t}getRelativeURL({id:t,vcf:e={}}){let s=e.variant??"vcard",p=e.format??(e.variant==="vcard"?"vcf":"json");return"v1/contacts/"+encodeURIComponent(t)+"/vcf?variant="+encodeURIComponent(s)+"&format="+encodeURIComponent(p)}getURL(t){return this._transport.getURL(this.getRelativeURL(t))}};import{z as y}from"zod";var T=class r{constructor(t){this._transport=t}static SCHEMA=y.object({name:y.string(),account:y.string(),emailAddress:y.string().email().optional(),telephoneNumber:y.string().optional()});async send({body:t,request:e={}}){return this._transport.send("v1/contacts",{...e,method:"POST",headers:{...e.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(t))})}};var x=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t),{...e,method:"GET"})}};var _=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/contacts",{...t,method:"GET"})}};var S=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t)+"/contacts",{...e,method:"GET"})}};import{z as nt}from"zod";var v=class r{constructor(t){this._transport=t}static SCHEMA=nt.object({name:nt.string().optional(),emailAddress:nt.string().email().optional(),telephoneNumber:nt.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var O=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t),{...e,method:"GET"})}};var E=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t)+"/conversations",{...e,method:"GET"})}};var F=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/conversations",{...t,method:"GET"})}};var U=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t)+"/conversations",{...e,method:"GET"})}};import{z as dt}from"zod";var w=class r{constructor(t){this._transport=t}static SCHEMA=dt.object({conversationStatus:dt.enum(["AwaitingContactConversationStatus","AwaitingAgentConversationStatus","ResolvedConversationStatus","ClosedConversationStatus"]).optional(),hasEnded:dt.boolean().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};import{z as ot}from"zod";var I=class r{constructor(t){this._transport=t}static SCHEMA=ot.object({title:ot.string(),description:ot.string().optional(),account:ot.string()});async send({body:t,request:e={}}){return this._transport.send("v1/labels",{...e,method:"POST",headers:{...e.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(t))})}};var q=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t),{...e,method:"DELETE"})}};var L=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t),{...e,method:"GET"})}};var H=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/labels",{...t,method:"GET"})}};import{z as lt}from"zod";var M=class r{constructor(t){this._transport=t}static SCHEMA=lt.object({title:lt.string().optional(),description:lt.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/labels/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var N=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t)+"/messages",{...e,method:"GET"})}};var G=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/messages",{...t,method:"GET"})}};import{z as it}from"zod";var B=class r{constructor(t){this._transport=t}static SCHEMA=it.object({input:it.string().max(65536),original:it.string().max(65536),correction:it.string().max(65536)});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/models/"+encodeURIComponent(t)+"/correction",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var j=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/models/"+encodeURIComponent(t),{...e,method:"GET"})}};var P=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/models",{...t,method:"GET"})}};import{z as at}from"zod";var z=class r{constructor(t){this._transport=t}static SCHEMA=at.array(at.object({role:at.enum(["user","assistant"]),content:at.string().max(65536).nullable()})).min(1);async send({id:t,body:e,request:s={}}){return this._transport.send("v1/models/"+encodeURIComponent(t)+"/response",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};import{z as bt}from"zod";var D=class r{constructor(t){this._transport=t}static SCHEMA=bt.object({content:bt.string()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t)+"/notes",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};import{z as Rt}from"zod";var i=class r{constructor(t){this._transport=t}static SCHEMA=Rt.object({content:Rt.string()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t)+"/notes",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var J=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/notes/"+encodeURIComponent(t),{...e,method:"GET"})}};var V=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/contacts/"+encodeURIComponent(t)+"/notes",{...e,method:"GET"})}};var K=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/conversations/"+encodeURIComponent(t)+"/notes",{...e,method:"GET"})}};import{z as At}from"zod";var k=class r{constructor(t){this._transport=t}static SCHEMA=At.object({content:At.string().optional()});async send({id:t,body:e,request:s={}}){return this._transport.send("v1/notes/"+encodeURIComponent(t),{...s,method:"PATCH",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(r.SCHEMA.parse(e))})}};var Y=class r{constructor(t=r.STANDARD_HEADERS){this._standardHeaders=t}static STANDARD_HEADERS=ft;async filter(){return{headers:this.getHeaders()}}getHeaders(){return this._standardHeaders}};var $=class{constructor(t){this._transport=t}async send({id:t,request:e={}}){return this._transport.send("v1/sources/"+encodeURIComponent(t),{...e,method:"GET"})}};var W=class{constructor(t){this._transport=t}async send({request:t={}}={}){return this._transport.send("v1/sources",{...t,method:"GET"})}};import _t from"is-network-error";import St,{HTTPError as vt}from"ky";var n=class extends Error{};var o=class extends n{};var X=class extends o{static unauthenticated(){return new this("An unauthenticated request occurred")}};var Q=class extends o{static forbidden(){return new this("A forbidden request occurred")}};var a=class extends n{static notFound(t){return new this(`Record not found for request: ${t}`)}static forbiddenMethod(t,e){return new this(`Forbidden method for request: ${t} ${e}`)}};var Z=class extends n{};var tt=class extends n{static badRequest(){return new this("Bad request")}};var et=class{client;options;constructor({baseURL:t,...e}){this.options={...e,baseURL:t},this.client=St.create({prefixUrl:this.options.baseURL,hooks:{beforeRequest:[s=>{for(let p of this.options.requestFilterables){let yt=p.getHeaders();for(let[mt,Tt]of Object.entries(yt))s.headers.has(mt)||s.headers.set(mt,Tt)}}]}})}getURL(t){return new URL(t,this.options.baseURL).toString()}async send(t,e){return await this.client(t,e).catch(s=>{if(_t(s))throw new Z("A network error occurred",{cause:s});if(s instanceof vt){let p=s.response.status;switch(console.error(JSON.stringify(s.response)),p){case 400:throw tt.badRequest();case 401:throw X.unauthenticated();case 403:throw Q.forbidden();case 404:throw a.notFound(t);case 405:throw a.forbiddenMethod(t,e.method??"GET")}}throw s})}};var ut=class r{static DEFAULT_BASE_URL=ht;_transport;constructor(t,{baseURL:e,...s}={}){this._transport=new et({requestFilterables:[new Y,t],...s,baseURL:e?.toString()??r.getBaseURL()})}static getBaseURL(){return process.env[Ct]??this.DEFAULT_BASE_URL}get action(){return{list:new c(this._transport)}}get boilerplate(){return{get:new l(this._transport),list:new g(this._transport),update:new m(this._transport)}}get boilerplateCategory(){return{get:new f(this._transport),list:new C(this._transport),create:new h(this._transport),update:new b(this._transport),boilerplate:{list:new u(this._transport),create:new d(this._transport)}}}get channel(){return{list:new R(this._transport)}}get contact(){return{get:new x(this._transport),list:new _(this._transport),update:new v(this._transport),create:new T(this._transport),conversation:{list:new E(this._transport)},note:{list:new V(this._transport),create:new D(this._transport)},vcf:{get:new A(this._transport)}}}get conversation(){return{get:new O(this._transport),list:new F(this._transport),update:new w(this._transport),create:new i(this._transport),message:{list:new N(this._transport)},note:{list:new K(this._transport),create:new i(this._transport)}}}get label(){return{create:new I(this._transport),get:new L(this._transport),list:new H(this._transport),update:new M(this._transport),delete:new q(this._transport),contact:{list:new S(this._transport)},conversation:{list:new U(this._transport)}}}get message(){return{list:new G(this._transport)}}get model(){return{get:new j(this._transport),list:new P(this._transport),response:{create:new z(this._transport)},correction:{create:new B(this._transport)}}}get note(){return{get:new J(this._transport),update:new k(this._transport)}}get source(){return{get:new $(this._transport),list:new W(this._transport)}}};var gt=class{async filter(){return{headers:this.getHeaders()}}getHeaders(){return{}}};export{Ot as a,ht as b,Ft as c,Kt as d,kt as e,Yt as f,n as g,o as h,X as i,Q as j,a as k,Z as l,tt as m,ut as n,gt as o};
|