tsp-scale-sdk 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var u=require("crypto"),m={prod:"https://api.tspscale.in/api/v1",staging:"https://staging-api.tspscale.in/api/v1",local:"http://localhost:4000/api/v1"};function f(e){if(e.baseUrl)return e.baseUrl;let t=(e.env||"prod").toLowerCase();return m[t]||m.prod}var p=class{constructor(t){if(!t||!t.apiKey)throw new Error("apiKey is required");if(this.apiKey=t.apiKey,this.baseUrl=f(t).replace(/\/+$/,""),this.timeoutMs=t.timeoutMs||15e3,this.fetchImpl=t.fetchImpl||globalThis.fetch,typeof this.fetchImpl!="function")throw new Error("Fetch implementation is not available. Use Node 18+ or pass fetchImpl.")}async sendEmail(t){let s="/emails/send",o=`${this.baseUrl}${s}`,a=JSON.stringify(t||{}),r=Date.now().toString(),i=u.randomBytes(16).toString("hex"),d=this._sign({timestamp:r,nonce:i,method:"POST",path:s,body:a}),h=new AbortController,y=setTimeout(()=>h.abort(),this.timeoutMs);try{let n=await this.fetchImpl(o,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey,"x-tsp-client":"tsp-scale-sdk/
|
|
1
|
+
var u=require("crypto"),m={prod:"https://api.tspscale.in/api/v1",staging:"https://staging-api.tspscale.in/api/v1",local:"http://localhost:4000/api/v1"};function f(e){if(e.baseUrl)return e.baseUrl;let t=(e.env||"prod").toLowerCase();return m[t]||m.prod}var p=class{constructor(t){if(!t||!t.apiKey)throw new Error("apiKey is required");if(this.apiKey=t.apiKey,this.baseUrl=f(t).replace(/\/+$/,""),this.timeoutMs=t.timeoutMs||15e3,this.fetchImpl=t.fetchImpl||globalThis.fetch,typeof this.fetchImpl!="function")throw new Error("Fetch implementation is not available. Use Node 18+ or pass fetchImpl.")}async sendEmail(t){let s="/emails/send",o=`${this.baseUrl}${s}`,a=JSON.stringify(t||{}),r=Date.now().toString(),i=u.randomBytes(16).toString("hex"),d=this._sign({timestamp:r,nonce:i,method:"POST",path:s,body:a}),h=new AbortController,y=setTimeout(()=>h.abort(),this.timeoutMs);try{let n=await this.fetchImpl(o,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey,"x-tsp-client":"tsp-scale-sdk/1.0.0","x-tsp-timestamp":r,"x-tsp-nonce":i,"x-tsp-signature":d},body:a,signal:h.signal}),c=await n.json().catch(()=>({}));if(!n.ok){let l=new Error(c?.error||`Request failed with status ${n.status}`);throw l.status=n.status,l.response=c,l}return c}finally{clearTimeout(y)}}_sign({timestamp:t,nonce:s,method:o,path:a,body:r}){let i=`${t}.${s}.${o}.${a}.${r}`;return u.createHmac("sha256",this.apiKey).update(i).digest("hex")}};module.exports={TspScaleClient:p};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|