@rkfl/transact-server 1.0.1

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 ADDED
@@ -0,0 +1,174 @@
1
+ # Rocketfuel SDK (Node.js)
2
+
3
+ A secure and minimal Node.js SDK to interact with Rocketfuel payment APIs. (This SDK is for Node.js server-side usage.)
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i @rkfl/transact-server
9
+ ```
10
+ ## Documentation
11
+ Click here for more detailed [Documentation](https://rocketfuel-gitbook.gitbook.io/rocketfuel-sdks/)
12
+ ## Usage
13
+
14
+ ### Create order
15
+
16
+ ```ts
17
+ import { Rocketfuel } from '@rocketfuel/plugin';
18
+
19
+ const client = new Rocketfuel({
20
+ clientId: 'YOUR_ID',
21
+ clientSecret: 'YOUR_SECRET',
22
+ merchantId: 'YOUR_MERCHANT_ID',
23
+ domain: 'production' // or 'sandbox'
24
+ });
25
+
26
+ const orderData = {
27
+ amount: "10",
28
+ currency: "USD",
29
+ cart: [
30
+ {
31
+ id: "iphone_14_pro_max",
32
+ name: "iPhone 14 Pro Max",
33
+ price: "10",
34
+ quantity: 1
35
+ }
36
+ ],
37
+ customerInfo: {
38
+ name: "John Doe",
39
+ email: "john.doe@example.com"
40
+ },
41
+ customParameter: {
42
+ returnMethod: "GET",
43
+ params: [
44
+ {
45
+ name: "submerchant",
46
+ value: "mobilesale"
47
+ }
48
+ ]
49
+ },
50
+ merchant_id: '14ec584d-53af-476d-aacd-2b7f025cf21b'
51
+ };
52
+
53
+ const result = await client.createOrder(orderData);
54
+
55
+ ```
56
+
57
+ ### Transaction Lookup
58
+ To check or confirm the transaction status using order id or Rocketfuel provided transaction id
59
+
60
+ ```
61
+
62
+ async function checkTransaction(txId) {
63
+ try {
64
+ const result = await client.transactionLookup(txId, 'ORDERID');
65
+ console.log('Transaction Details:', result);
66
+ // Process the transaction details as needed
67
+ } catch (error) {
68
+ console.error('Error fetching transaction details:', error.message);
69
+ }
70
+ }
71
+ ​
72
+ // Example call:
73
+ checkTransaction('12345ABC');
74
+ ```
75
+
76
+ ### Webook Verification
77
+ Use this function to verify that a webhook is valid and trusted before processing its contents. It prevents spoofed requests, data tampering, and unauthorized events.
78
+ This function returns true if the signature is valid, otherwise false.
79
+
80
+ ```
81
+
82
+ function handleWebhook(req, res) {
83
+ const isValid = client.verifyWebhookSignature(req.body);
84
+ ​
85
+ if (!isValid) {
86
+ console.warn('Webhook signature verification failed');
87
+ return res.status(403).send('Invalid signature');
88
+ }
89
+ ​
90
+ const payload = JSON.parse(req.body.data.data);
91
+ console.log('Verified Webhook Payload:', payload);
92
+ ​
93
+ // Process your payload
94
+ res.status(200).send('Webhook received');
95
+ }
96
+ ```
97
+
98
+ ## πŸ“¦ NPM Commands Documentation
99
+ ### 1. npm:login
100
+
101
+ Logs you into your npm account from the terminal.
102
+ You’ll be prompted for your npm username, password, and email.
103
+ ```
104
+ npm run npm:login
105
+ ```
106
+ Use this before your first publish or if you’re logged out.
107
+
108
+ ### 2. npm:publish
109
+ Publishes the current package to npm with public access.
110
+ The package name and version must be unique on npm.
111
+ ```
112
+ npm run npm:publish
113
+ ```
114
+
115
+ ### 3. npm:patch
116
+ Increments the patch version (last digit) in package.json by +1.
117
+ Used for bug fixes or small improvements.
118
+ ```
119
+ npm run npm:patch
120
+ ```
121
+ Example Version Change:
122
+ ```
123
+ 1.0.9 β†’ 1.0.10
124
+ 1.0.10 β†’ 1.0.11
125
+ ```
126
+ ### 4. npm:minor
127
+ Increments the minor version (middle digit) by +1 and resets patch to 0.
128
+ Used for adding new features without breaking compatibility.
129
+ ```
130
+ npm run npm:minor
131
+ ```
132
+ Example Version Change:
133
+ ```
134
+ 1.0.5 β†’ 1.1.0
135
+ 1.2.7 β†’ 1.3.0
136
+ ```
137
+ ### 5. npm:major
138
+ Increments the major version (first digit) by +1 and resets minor and patch to 0.
139
+ Used for breaking changes or major redesigns.
140
+ ```
141
+ npm run npm:major
142
+ ```
143
+ Example Version Change:
144
+ ```
145
+ 1.4.8 β†’ 2.0.0
146
+ 2.1.3 β†’ 3.0.0
147
+ ```
148
+ ## πŸš€ Recommended Workflow
149
+ ### Login once:
150
+ ```
151
+ npm run npm:login
152
+ ```
153
+ Make changes to your code.
154
+
155
+ ### Bump version:
156
+ ```
157
+ npm run npm:patch
158
+ ```
159
+ Minor:
160
+
161
+ ```
162
+ npm run npm:minor
163
+ ```
164
+ Major:
165
+ ```
166
+ npm run npm:major
167
+ ```
168
+
169
+ ### Publish:
170
+ ```
171
+ npm run npm:publish
172
+ ```
173
+ ## πŸ“„ License
174
+ MIT License Β© RocketFuel Blockchain, Inc.
@@ -0,0 +1,7 @@
1
+ export declare const apiDomains: {
2
+ readonly production: "https://app.rocketfuel.inc/api";
3
+ readonly qa: "https://qa-app.rfdemo.co/api";
4
+ readonly preprod: "https://preprod-app.rocketdemo.net/api";
5
+ readonly sandbox: "https://app-sandbox.rocketfuel.inc/api";
6
+ };
7
+ export type Environment = keyof typeof apiDomains;
@@ -0,0 +1,13 @@
1
+ import type { Environment } from './constants';
2
+ export declare class Rocketfuel {
3
+ #private;
4
+ constructor({ clientId, clientSecret, merchantId, environment, }: {
5
+ clientId: string;
6
+ clientSecret: string;
7
+ merchantId: string;
8
+ environment: Environment;
9
+ });
10
+ createOrder(payload: Record<string, any>): Promise<any>;
11
+ transactionLookup(txId: string, type?: 'ORDERID' | 'TXID'): Promise<any>;
12
+ verifyWebhookSignature(body: any): boolean;
13
+ }
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import t from"crypto-js";import*as e from"crypto";const s={production:"https://app.rocketfuel.inc/api",qa:"https://qa-app.rfdemo.co/api",preprod:"https://preprod-app.rocketdemo.net/api",sandbox:"https://app-sandbox.rocketfuel.inc/api"};class r{#t;#e;#s;#r;#n=null;#a=null;constructor({clientId:t,clientSecret:e,merchantId:r,environment:n}){this.#t=t,this.#e=e,this.#s=r,this.#r=s[n||"production"]}#o(){const e=JSON.stringify({merchantId:this.#s,totop:""});return t.AES.encrypt(e,this.#e).toString()}#i(){const t={"Content-Type":"application/json"};return this.#n&&(t.Authorization=`Bearer ${this.#n}`),t}async#c(){const t={clientId:this.#t,encryptedPayload:this.#o()},e=await fetch(`${this.#r}/auth/generate-auth-token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!e.ok)throw new Error(`Auth failed: ${e.status}`);const s=await e.json(),r=s?.result;if(!r?.access)throw new Error("Token missing in response");this.#n=r.access,this.#a=r.refresh}async#h(t,e,s=!0){const r=await fetch(t,e);if(403===r.status&&s){console.warn(`Received 403, refreshing token and retrying: ${t}`),await this.#c();const s={...e,headers:this.#i()};return this.#h(t,s,!1)}if(!r.ok)throw new Error(`Request failed: ${r.status}`);return r.json()}async createOrder(t){this.#n||await this.#c();const e=await this.#h(`${this.#r}/hosted-page`,{method:"POST",headers:this.#i(),body:JSON.stringify(t)});return{uuid:e?.result?.uuid}}async transactionLookup(t,e="ORDERID"){this.#n||await this.#c();const s=await this.#h(`${this.#r}/purchase/transactionLookup`,{method:"POST",headers:this.#i(),body:JSON.stringify({txId:t,type:e})});return s?.result}verifyWebhookSignature(t){try{const{data:{data:s},signature:r}=t,n=e.createVerify("RSA-SHA256");return n.update(s),n.verify("-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2e4stIYooUrKHVQmwztC\n/l0YktX6uz4bE1iDtA2qu4OaXx+IKkwBWa0hO2mzv6dAoawyzxa2jmN01vrpMkMj\nrB+Dxmoq7tRvRTx1hXzZWaKuv37BAYosOIKjom8S8axM1j6zPkX1zpMLE8ys3dUX\nFN5Dl/kBfeCTwGRV4PZjP4a+QwgFRzZVVfnpcRI/O6zhfkdlRah8MrAPWYSoGBpG\nCPiAjUeHO/4JA5zZ6IdfZuy/DKxbcOlt9H+z14iJwB7eVUByoeCE+Bkw+QE4msKs\naIn4xl9GBoyfDZKajTzL50W/oeoE1UcuvVfaULZ9DWnHOy6idCFH1WbYDxYYIWLi\nAQIDAQAB\n-----END PUBLIC KEY-----",r,"base64")}catch(t){return console.error("Signature verification failed:",t),!1}}}export{r as Rocketfuel};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@rkfl/transact-server",
3
+ "main": "./dist/index.js",
4
+ "type": "module",
5
+ "version": "1.0.1",
6
+ "scripts": {
7
+ "build": "rollup -c",
8
+ "npm:login": "npm login",
9
+ "npm:publish": "npm run build && npm publish --access public",
10
+ "npm:patch": "npm version patch",
11
+ "npm:minor": "npm version minor",
12
+ "npm:major": "npm version major",
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "author": "Rocketfuel",
20
+ "license": "ISC",
21
+ "description": "Package for the node js server side. to create orders and do more",
22
+ "keywords": [
23
+ "rocketfuel",
24
+ "server",
25
+ "crypto",
26
+ "payments"
27
+ ],
28
+ "devDependencies": {
29
+ "@types/crypto-js": "^4.2.2",
30
+ "rollup": "^2.79.2",
31
+ "rollup-plugin-terser": "^7.0.2",
32
+ "rollup-plugin-typescript2": "^0.36.0",
33
+ "typescript": "^5.8.3"
34
+ },
35
+ "dependencies": {
36
+ "axios": "^1.11.0",
37
+ "crypto": "^1.0.1",
38
+ "crypto-js": "^4.2.0"
39
+ }
40
+ }