hs-playlib 0.1.0 → 0.3.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/src/http_client.d.ts +5 -13
- package/dist/src/http_client.js +9 -13
- package/dist/src/index.d.ts +2 -180
- package/dist/src/index.js +6 -93
- package/dist/src/payments/_generated_connector_client_flows.d.ts +43 -9
- package/dist/src/payments/_generated_connector_client_flows.js +78 -16
- package/dist/src/payments/_generated_flows.js +44 -7
- package/dist/src/payments/_generated_uniffi_client_flows.d.ts +54 -12
- package/dist/src/payments/_generated_uniffi_client_flows.js +108 -24
- package/dist/src/payments/connector_client.d.ts +19 -15
- package/dist/src/payments/connector_client.js +64 -39
- package/dist/src/payments/generated/libconnector_service_ffi.dylib +0 -0
- package/dist/src/payments/generated/proto.d.ts +22069 -21901
- package/dist/src/payments/generated/proto.js +76914 -76263
- package/dist/src/payments/uniffi_client.d.ts +8 -2
- package/dist/src/payments/uniffi_client.js +32 -37
- package/package.json +2 -14
|
@@ -24,11 +24,17 @@ export declare class UniffiClient {
|
|
|
24
24
|
* Build the connector HTTP request for any flow.
|
|
25
25
|
* Returns protobuf-encoded FfiConnectorHttpRequest bytes.
|
|
26
26
|
*/
|
|
27
|
-
callReq(flow: string, requestBytes: Buffer | Uint8Array,
|
|
27
|
+
callReq(flow: string, requestBytes: Buffer | Uint8Array, optionsBytes: Buffer | Uint8Array): Buffer;
|
|
28
28
|
/**
|
|
29
29
|
* Parse the connector HTTP response for any flow.
|
|
30
30
|
* responseBytes: protobuf-encoded FfiConnectorHttpResponse.
|
|
31
31
|
* Returns protobuf-encoded response bytes for the flow's response type.
|
|
32
32
|
*/
|
|
33
|
-
callRes(flow: string, responseBytes: Buffer | Uint8Array, requestBytes: Buffer | Uint8Array,
|
|
33
|
+
callRes(flow: string, responseBytes: Buffer | Uint8Array, requestBytes: Buffer | Uint8Array, optionsBytes: Buffer | Uint8Array): Buffer;
|
|
34
|
+
/**
|
|
35
|
+
* Execute a single-step transformer directly (no HTTP round-trip).
|
|
36
|
+
* Used for inbound flows like webhook processing.
|
|
37
|
+
* Returns protobuf-encoded response bytes.
|
|
38
|
+
*/
|
|
39
|
+
callDirect(flow: string, requestBytes: Buffer | Uint8Array, optionsBytes: Buffer | Uint8Array): Buffer;
|
|
34
40
|
}
|
|
@@ -20,6 +20,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
20
20
|
const _generated_flows_js_1 = require("./_generated_flows.js");
|
|
21
21
|
const _dirname = __dirname;
|
|
22
22
|
const FLOW_NAMES = Object.keys(_generated_flows_js_1.FLOWS);
|
|
23
|
+
const SINGLE_FLOW_NAMES = Object.keys((_generated_flows_js_1.SINGLE_FLOWS || {}));
|
|
23
24
|
const RustBufferStruct = koffi_1.default.struct("RustBuffer", {
|
|
24
25
|
capacity: "uint64",
|
|
25
26
|
len: "uint64",
|
|
@@ -41,8 +42,12 @@ function loadLib(libPath) {
|
|
|
41
42
|
};
|
|
42
43
|
// Load req and res transformer symbols for every registered flow.
|
|
43
44
|
for (const flow of FLOW_NAMES) {
|
|
44
|
-
fns[`${flow}_req`] = lib.func(`uniffi_connector_service_ffi_fn_func_${flow}_req_transformer`, RustBufferStruct, [RustBufferStruct, RustBufferStruct,
|
|
45
|
-
fns[`${flow}_res`] = lib.func(`uniffi_connector_service_ffi_fn_func_${flow}_res_transformer`, RustBufferStruct, [RustBufferStruct, RustBufferStruct, RustBufferStruct,
|
|
45
|
+
fns[`${flow}_req`] = lib.func(`uniffi_connector_service_ffi_fn_func_${flow}_req_transformer`, RustBufferStruct, [RustBufferStruct, RustBufferStruct, koffi_1.default.out(koffi_1.default.pointer(RustCallStatusStruct))]);
|
|
46
|
+
fns[`${flow}_res`] = lib.func(`uniffi_connector_service_ffi_fn_func_${flow}_res_transformer`, RustBufferStruct, [RustBufferStruct, RustBufferStruct, RustBufferStruct, koffi_1.default.out(koffi_1.default.pointer(RustCallStatusStruct))]);
|
|
47
|
+
}
|
|
48
|
+
// Load single-step transformer symbols (no HTTP round-trip, e.g. webhook processing).
|
|
49
|
+
for (const flow of SINGLE_FLOW_NAMES) {
|
|
50
|
+
fns[`${flow}_direct`] = lib.func(`uniffi_connector_service_ffi_fn_func_${flow}_transformer`, RustBufferStruct, [RustBufferStruct, RustBufferStruct, koffi_1.default.out(koffi_1.default.pointer(RustCallStatusStruct))]);
|
|
46
51
|
}
|
|
47
52
|
return fns;
|
|
48
53
|
}
|
|
@@ -130,35 +135,6 @@ function lowerBytes(ffi, data) {
|
|
|
130
135
|
Buffer.from(data).copy(buf, 4);
|
|
131
136
|
return allocRustBuffer(ffi, buf);
|
|
132
137
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Lowers a Map into a UniFFI-compliant serialized buffer.
|
|
135
|
-
* Protocol: [i32 count] + [ [i32 key_len]+[key_bytes] + [i32 val_len]+[val_bytes] ] * count
|
|
136
|
-
*/
|
|
137
|
-
function lowerMap(ffi, map) {
|
|
138
|
-
const entries = Object.entries(map);
|
|
139
|
-
let totalSize = 4; // count
|
|
140
|
-
const encoded = entries.map(([k, v]) => {
|
|
141
|
-
const kBuf = Buffer.from(k, "utf-8");
|
|
142
|
-
const vBuf = Buffer.from(v, "utf-8");
|
|
143
|
-
totalSize += 4 + kBuf.length + 4 + vBuf.length;
|
|
144
|
-
return { kBuf, vBuf };
|
|
145
|
-
});
|
|
146
|
-
const buf = Buffer.alloc(totalSize);
|
|
147
|
-
let offset = 0;
|
|
148
|
-
buf.writeInt32BE(entries.length, offset);
|
|
149
|
-
offset += 4;
|
|
150
|
-
for (const { kBuf, vBuf } of encoded) {
|
|
151
|
-
buf.writeInt32BE(kBuf.length, offset);
|
|
152
|
-
offset += 4;
|
|
153
|
-
kBuf.copy(buf, offset);
|
|
154
|
-
offset += kBuf.length;
|
|
155
|
-
buf.writeInt32BE(vBuf.length, offset);
|
|
156
|
-
offset += 4;
|
|
157
|
-
vBuf.copy(buf, offset);
|
|
158
|
-
offset += vBuf.length;
|
|
159
|
-
}
|
|
160
|
-
return allocRustBuffer(ffi, buf);
|
|
161
|
-
}
|
|
162
138
|
class UniffiClient {
|
|
163
139
|
_ffi;
|
|
164
140
|
constructor(libPath) {
|
|
@@ -168,15 +144,14 @@ class UniffiClient {
|
|
|
168
144
|
* Build the connector HTTP request for any flow.
|
|
169
145
|
* Returns protobuf-encoded FfiConnectorHttpRequest bytes.
|
|
170
146
|
*/
|
|
171
|
-
callReq(flow, requestBytes,
|
|
147
|
+
callReq(flow, requestBytes, optionsBytes) {
|
|
172
148
|
const fn = this._ffi[`${flow}_req`];
|
|
173
149
|
if (!fn)
|
|
174
150
|
throw new Error(`Unknown flow: '${flow}'. Supported: ${FLOW_NAMES.join(", ")}`);
|
|
175
151
|
const rbReq = lowerBytes(this._ffi, requestBytes);
|
|
176
|
-
const rbMeta = lowerMap(this._ffi, metadata);
|
|
177
152
|
const rbOpts = lowerBytes(this._ffi, optionsBytes);
|
|
178
153
|
const status = makeCallStatus();
|
|
179
|
-
const result = fn(rbReq,
|
|
154
|
+
const result = fn(rbReq, rbOpts, status);
|
|
180
155
|
try {
|
|
181
156
|
checkCallStatus(this._ffi, status);
|
|
182
157
|
return liftBytes(result);
|
|
@@ -190,16 +165,36 @@ class UniffiClient {
|
|
|
190
165
|
* responseBytes: protobuf-encoded FfiConnectorHttpResponse.
|
|
191
166
|
* Returns protobuf-encoded response bytes for the flow's response type.
|
|
192
167
|
*/
|
|
193
|
-
callRes(flow, responseBytes, requestBytes,
|
|
168
|
+
callRes(flow, responseBytes, requestBytes, optionsBytes) {
|
|
194
169
|
const fn = this._ffi[`${flow}_res`];
|
|
195
170
|
if (!fn)
|
|
196
171
|
throw new Error(`Unknown flow: '${flow}'. Supported: ${FLOW_NAMES.join(", ")}`);
|
|
197
172
|
const rbRes = lowerBytes(this._ffi, responseBytes);
|
|
198
173
|
const rbReq = lowerBytes(this._ffi, requestBytes);
|
|
199
|
-
const rbMeta = lowerMap(this._ffi, metadata);
|
|
200
174
|
const rbOpts = lowerBytes(this._ffi, optionsBytes);
|
|
201
175
|
const status = makeCallStatus();
|
|
202
|
-
const result = fn(rbRes, rbReq,
|
|
176
|
+
const result = fn(rbRes, rbReq, rbOpts, status);
|
|
177
|
+
try {
|
|
178
|
+
checkCallStatus(this._ffi, status);
|
|
179
|
+
return liftBytes(result);
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
freeRustBuffer(this._ffi, result);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Execute a single-step transformer directly (no HTTP round-trip).
|
|
187
|
+
* Used for inbound flows like webhook processing.
|
|
188
|
+
* Returns protobuf-encoded response bytes.
|
|
189
|
+
*/
|
|
190
|
+
callDirect(flow, requestBytes, optionsBytes) {
|
|
191
|
+
const fn = this._ffi[`${flow}_direct`];
|
|
192
|
+
if (!fn)
|
|
193
|
+
throw new Error(`Unknown single-step flow: '${flow}'. Supported: ${SINGLE_FLOW_NAMES.join(", ")}`);
|
|
194
|
+
const rbReq = lowerBytes(this._ffi, requestBytes);
|
|
195
|
+
const rbOpts = lowerBytes(this._ffi, optionsBytes);
|
|
196
|
+
const status = makeCallStatus();
|
|
197
|
+
const result = fn(rbReq, rbOpts, status);
|
|
203
198
|
try {
|
|
204
199
|
checkCallStatus(this._ffi, status);
|
|
205
200
|
return liftBytes(result);
|
package/package.json
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hs-playlib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Hyperswitch Payments SDK — Node.js client for connector integrations via UniFFI FFI",
|
|
5
|
-
"author": "Juspay <hyperswitch@juspay.in>",
|
|
6
|
-
"license": "Apache-2.0",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/juspay/connector-service.git",
|
|
10
|
-
"directory": "sdk/javascript"
|
|
11
|
-
},
|
|
12
|
-
"keywords": ["payments", "hyperswitch", "juspay", "ffi"],
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/juspay/connector-service/issues"
|
|
15
|
-
},
|
|
16
|
-
"homepage": "https://github.com/juspay/connector-service#readme",
|
|
17
5
|
"main": "dist/src/index.js",
|
|
18
6
|
"types": "dist/src/index.d.ts",
|
|
19
7
|
"files": [
|
|
@@ -38,4 +26,4 @@
|
|
|
38
26
|
"tsconfig-paths": "^4.2.0",
|
|
39
27
|
"typescript": "^5.9.3"
|
|
40
28
|
}
|
|
41
|
-
}
|
|
29
|
+
}
|