tsp-scale-sdk 1.0.0 → 1.1.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/README.md CHANGED
@@ -32,6 +32,28 @@ async function run() {
32
32
  run().catch(console.error);
33
33
  ```
34
34
 
35
+ ### WhatsApp Messaging
36
+
37
+ ```js
38
+ const { TspScaleClient } = require("tsp-scale-sdk");
39
+
40
+ const client = new TspScaleClient({
41
+ apiKey: process.env.TSP_API_KEY
42
+ });
43
+
44
+ async function run() {
45
+ const result = await client.sendWhatsApp({
46
+ to: "919988776655",
47
+ text: "Hello from TSP Scale!",
48
+ // mediaUrl: "https://example.com/image.jpg" // Optional
49
+ });
50
+
51
+ console.log(result);
52
+ }
53
+
54
+ run().catch(console.error);
55
+ ```
56
+
35
57
  ## Notes
36
58
 
37
59
  - The SDK automatically adds signed security headers required by the `/emails/send` API.
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.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};
1
+ var m=require("crypto"),y={prod:"https://api.tspscale.in/api/v1",staging:"https://staging-api.tspscale.in/api/v1",local:"http://localhost:4000/api/v1"};function g(l){if(l.baseUrl)return l.baseUrl;let t=(l.env||"prod").toLowerCase();return y[t]||y.prod}var d=class{constructor(t){if(!t||!t.apiKey)throw new Error("apiKey is required");if(this.apiKey=t.apiKey,this.baseUrl=g(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 e="/emails/send",c=`${this.baseUrl}${e}`,a=JSON.stringify(t||{}),n=Date.now().toString(),o=m.randomBytes(16).toString("hex"),h=this._sign({timestamp:n,nonce:o,method:"POST",path:e,body:a}),p=new AbortController,u=setTimeout(()=>p.abort(),this.timeoutMs);try{let s=await this.fetchImpl(c,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey,"x-tsp-client":"tsp-scale-sdk/1.0.0","x-tsp-timestamp":n,"x-tsp-nonce":o,"x-tsp-signature":h},body:a,signal:p.signal}),r=await s.json().catch(()=>({}));if(!s.ok){let i=new Error(r?.error||`Request failed with status ${s.status}`);throw i.status=s.status,i.response=r,i}return r}finally{clearTimeout(u)}}async sendWhatsApp(t){let e="/whatsapp/messages/send",c=`${this.baseUrl}${e}`,a=JSON.stringify(t||{}),n=Date.now().toString(),o=m.randomBytes(16).toString("hex"),h=this._sign({timestamp:n,nonce:o,method:"POST",path:e,body:a}),p=new AbortController,u=setTimeout(()=>p.abort(),this.timeoutMs);try{let s=await this.fetchImpl(c,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey,"x-tsp-client":"tsp-scale-sdk/1.0.0","x-tsp-timestamp":n,"x-tsp-nonce":o,"x-tsp-signature":h},body:a,signal:p.signal}),r=await s.json().catch(()=>({}));if(!s.ok){let i=new Error(r?.error||`Request failed with status ${s.status}`);throw i.status=s.status,i.response=r,i}return r}finally{clearTimeout(u)}}_sign({timestamp:t,nonce:e,method:c,path:a,body:n}){let o=`${t}.${e}.${c}.${a}.${n}`;return m.createHmac("sha256",this.apiKey).update(o).digest("hex")}};module.exports={TspScaleClient:d};
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tsp-scale-sdk",
3
- "version": "1.0.0",
4
- "description": "Official Node.js client for TSP Scale email API",
3
+ "version": "1.1.0",
4
+ "description": "Official Node.js client for TSP Scale Email and WhatsApp API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "author": "TSP Scale",
@@ -11,9 +11,10 @@
11
11
  "tsp",
12
12
  "smtp",
13
13
  "email",
14
+ "whatsapp",
15
+ "automation",
14
16
  "api-client",
15
- "transactional-email",
16
- "developer-tools"
17
+ "transactional-email"
17
18
  ],
18
19
  "files": [
19
20
  "dist/index.js",