hs-playlib 0.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 +59 -0
- package/dist/src/http_client.d.ts +52 -0
- package/dist/src/http_client.js +128 -0
- package/dist/src/index.d.ts +183 -0
- package/dist/src/index.js +117 -0
- package/dist/src/payments/_generated_connector_client_flows.d.ts +16 -0
- package/dist/src/payments/_generated_connector_client_flows.js +34 -0
- package/dist/src/payments/_generated_flows.js +26 -0
- package/dist/src/payments/_generated_uniffi_client_flows.d.ts +27 -0
- package/dist/src/payments/_generated_uniffi_client_flows.js +58 -0
- package/dist/src/payments/connector_client.d.ts +41 -0
- package/dist/src/payments/connector_client.js +102 -0
- package/dist/src/payments/generated/libconnector_service_ffi.dylib +0 -0
- package/dist/src/payments/generated/proto.d.ts +27658 -0
- package/dist/src/payments/generated/proto.js +82064 -0
- package/dist/src/payments/uniffi_client.d.ts +34 -0
- package/dist/src/payments/uniffi_client.js +213 -0
- package/package.json +41 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// AUTO-GENERATED — do not edit by hand.
|
|
3
|
+
// Source: services.proto ∩ bindings/uniffi.rs | Regenerate: make generate
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.UniffiClient = void 0;
|
|
6
|
+
const uniffi_client_1 = require("./uniffi_client");
|
|
7
|
+
class UniffiClient extends uniffi_client_1.UniffiClient {
|
|
8
|
+
/** Build connector HTTP request for authorize flow. */
|
|
9
|
+
authorizeReq(requestBytes, metadata, optionsBytes) {
|
|
10
|
+
return this.callReq('authorize', requestBytes, metadata, optionsBytes);
|
|
11
|
+
}
|
|
12
|
+
/** Parse connector HTTP response for authorize flow. */
|
|
13
|
+
authorizeRes(responseBytes, requestBytes, metadata, optionsBytes) {
|
|
14
|
+
return this.callRes('authorize', responseBytes, requestBytes, metadata, optionsBytes);
|
|
15
|
+
}
|
|
16
|
+
/** Build connector HTTP request for capture flow. */
|
|
17
|
+
captureReq(requestBytes, metadata, optionsBytes) {
|
|
18
|
+
return this.callReq('capture', requestBytes, metadata, optionsBytes);
|
|
19
|
+
}
|
|
20
|
+
/** Parse connector HTTP response for capture flow. */
|
|
21
|
+
captureRes(responseBytes, requestBytes, metadata, optionsBytes) {
|
|
22
|
+
return this.callRes('capture', responseBytes, requestBytes, metadata, optionsBytes);
|
|
23
|
+
}
|
|
24
|
+
/** Build connector HTTP request for create_access_token flow. */
|
|
25
|
+
createAccessTokenReq(requestBytes, metadata, optionsBytes) {
|
|
26
|
+
return this.callReq('create_access_token', requestBytes, metadata, optionsBytes);
|
|
27
|
+
}
|
|
28
|
+
/** Parse connector HTTP response for create_access_token flow. */
|
|
29
|
+
createAccessTokenRes(responseBytes, requestBytes, metadata, optionsBytes) {
|
|
30
|
+
return this.callRes('create_access_token', responseBytes, requestBytes, metadata, optionsBytes);
|
|
31
|
+
}
|
|
32
|
+
/** Build connector HTTP request for get flow. */
|
|
33
|
+
getReq(requestBytes, metadata, optionsBytes) {
|
|
34
|
+
return this.callReq('get', requestBytes, metadata, optionsBytes);
|
|
35
|
+
}
|
|
36
|
+
/** Parse connector HTTP response for get flow. */
|
|
37
|
+
getRes(responseBytes, requestBytes, metadata, optionsBytes) {
|
|
38
|
+
return this.callRes('get', responseBytes, requestBytes, metadata, optionsBytes);
|
|
39
|
+
}
|
|
40
|
+
/** Build connector HTTP request for refund flow. */
|
|
41
|
+
refundReq(requestBytes, metadata, optionsBytes) {
|
|
42
|
+
return this.callReq('refund', requestBytes, metadata, optionsBytes);
|
|
43
|
+
}
|
|
44
|
+
/** Parse connector HTTP response for refund flow. */
|
|
45
|
+
refundRes(responseBytes, requestBytes, metadata, optionsBytes) {
|
|
46
|
+
return this.callRes('refund', responseBytes, requestBytes, metadata, optionsBytes);
|
|
47
|
+
}
|
|
48
|
+
/** Build connector HTTP request for void flow. */
|
|
49
|
+
voidReq(requestBytes, metadata, optionsBytes) {
|
|
50
|
+
return this.callReq('void', requestBytes, metadata, optionsBytes);
|
|
51
|
+
}
|
|
52
|
+
/** Parse connector HTTP response for void flow. */
|
|
53
|
+
voidRes(responseBytes, requestBytes, metadata, optionsBytes) {
|
|
54
|
+
return this.callRes('void', responseBytes, requestBytes, metadata, optionsBytes);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.UniffiClient = UniffiClient;
|
|
58
|
+
//# sourceMappingURL=_generated_uniffi_client_flows.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConnectorClient — high-level wrapper using UniFFI bindings via koffi.
|
|
3
|
+
*
|
|
4
|
+
* Handles the full round-trip for any payment flow:
|
|
5
|
+
* 1. Serialize protobuf request to bytes
|
|
6
|
+
* 2. Build connector HTTP request via UniffiClient.callReq (generic FFI dispatch)
|
|
7
|
+
* 3. Execute the HTTP request via our standardized HttpClient
|
|
8
|
+
* 4. Parse the connector response via UniffiClient.callRes (generic FFI dispatch)
|
|
9
|
+
* 5. Deserialize protobuf response from bytes
|
|
10
|
+
*
|
|
11
|
+
* Flow methods (authorize, capture, void, refund, …) are in _generated_connector_client_flows.ts.
|
|
12
|
+
* To add a new flow: implement it in the FFI crate and run `make generate`.
|
|
13
|
+
*/
|
|
14
|
+
import { ucs } from "./generated/proto";
|
|
15
|
+
export declare class ConnectorClient {
|
|
16
|
+
private uniffi;
|
|
17
|
+
private options;
|
|
18
|
+
private dispatcher;
|
|
19
|
+
/**
|
|
20
|
+
* @param libPath - optional path to the UniFFI shared library
|
|
21
|
+
* @param options - unified SDK configuration from Protobuf (Options message)
|
|
22
|
+
*/
|
|
23
|
+
constructor(libPath?: string, options?: ucs.v2.IOptions);
|
|
24
|
+
/**
|
|
25
|
+
* Internal helper to map Protobuf HttpOptions to Native HttpClient options.
|
|
26
|
+
*/
|
|
27
|
+
private getNativeHttpOptions;
|
|
28
|
+
/**
|
|
29
|
+
* Execute a full round-trip for any registered payment flow.
|
|
30
|
+
*
|
|
31
|
+
* Looks up the request/response protobuf type names from FLOWS, encodes the
|
|
32
|
+
* request, calls callReq → HTTP → callRes via the generic FFI dispatcher,
|
|
33
|
+
* then decodes and returns the response.
|
|
34
|
+
*
|
|
35
|
+
* @param flow - Flow name matching the FFI transformer prefix (e.g. "authorize").
|
|
36
|
+
* @param requestMsg - Protobuf request message object.
|
|
37
|
+
* @param metadata - Dict with connector routing and auth info.
|
|
38
|
+
* @param ffiOptions - Optional IFfiOptions override.
|
|
39
|
+
*/
|
|
40
|
+
_executeFlow(flow: string, requestMsg: object, metadata: Record<string, string>, ffiOptions?: ucs.v2.IFfiOptions | null, reqTypeName?: string, resTypeName?: string): Promise<unknown>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ConnectorClient — high-level wrapper using UniFFI bindings via koffi.
|
|
4
|
+
*
|
|
5
|
+
* Handles the full round-trip for any payment flow:
|
|
6
|
+
* 1. Serialize protobuf request to bytes
|
|
7
|
+
* 2. Build connector HTTP request via UniffiClient.callReq (generic FFI dispatch)
|
|
8
|
+
* 3. Execute the HTTP request via our standardized HttpClient
|
|
9
|
+
* 4. Parse the connector response via UniffiClient.callRes (generic FFI dispatch)
|
|
10
|
+
* 5. Deserialize protobuf response from bytes
|
|
11
|
+
*
|
|
12
|
+
* Flow methods (authorize, capture, void, refund, …) are in _generated_connector_client_flows.ts.
|
|
13
|
+
* To add a new flow: implement it in the FFI crate and run `make generate`.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.ConnectorClient = void 0;
|
|
17
|
+
const uniffi_client_1 = require("./uniffi_client");
|
|
18
|
+
const http_client_1 = require("../http_client");
|
|
19
|
+
// @ts-ignore - protobuf generated files might not have types yet
|
|
20
|
+
const proto_1 = require("./generated/proto");
|
|
21
|
+
const v2 = proto_1.ucs.v2;
|
|
22
|
+
class ConnectorClient {
|
|
23
|
+
uniffi;
|
|
24
|
+
options;
|
|
25
|
+
dispatcher;
|
|
26
|
+
/**
|
|
27
|
+
* @param libPath - optional path to the UniFFI shared library
|
|
28
|
+
* @param options - unified SDK configuration from Protobuf (Options message)
|
|
29
|
+
*/
|
|
30
|
+
constructor(libPath, options = {}) {
|
|
31
|
+
this.uniffi = new uniffi_client_1.UniffiClient(libPath);
|
|
32
|
+
this.options = options;
|
|
33
|
+
// Instance-level cache: create the primary connection pool at startup
|
|
34
|
+
this.dispatcher = (0, http_client_1.createDispatcher)(this.getNativeHttpOptions(options.http));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Internal helper to map Protobuf HttpOptions to Native HttpClient options.
|
|
38
|
+
*/
|
|
39
|
+
getNativeHttpOptions(proto) {
|
|
40
|
+
if (!proto)
|
|
41
|
+
return {};
|
|
42
|
+
return {
|
|
43
|
+
totalTimeoutMs: proto.totalTimeoutMs ?? undefined,
|
|
44
|
+
connectTimeoutMs: proto.connectTimeoutMs ?? undefined,
|
|
45
|
+
responseTimeoutMs: proto.responseTimeoutMs ?? undefined,
|
|
46
|
+
keepAliveTimeoutMs: proto.keepAliveTimeoutMs ?? undefined,
|
|
47
|
+
proxy: proto.proxy ? {
|
|
48
|
+
httpUrl: proto.proxy.httpUrl ?? undefined,
|
|
49
|
+
httpsUrl: proto.proxy.httpsUrl ?? undefined,
|
|
50
|
+
bypassUrls: proto.proxy.bypassUrls ?? undefined,
|
|
51
|
+
} : undefined,
|
|
52
|
+
caCert: proto.caCert ?? undefined,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Execute a full round-trip for any registered payment flow.
|
|
57
|
+
*
|
|
58
|
+
* Looks up the request/response protobuf type names from FLOWS, encodes the
|
|
59
|
+
* request, calls callReq → HTTP → callRes via the generic FFI dispatcher,
|
|
60
|
+
* then decodes and returns the response.
|
|
61
|
+
*
|
|
62
|
+
* @param flow - Flow name matching the FFI transformer prefix (e.g. "authorize").
|
|
63
|
+
* @param requestMsg - Protobuf request message object.
|
|
64
|
+
* @param metadata - Dict with connector routing and auth info.
|
|
65
|
+
* @param ffiOptions - Optional IFfiOptions override.
|
|
66
|
+
*/
|
|
67
|
+
async _executeFlow(flow, requestMsg, metadata, ffiOptions, reqTypeName, resTypeName) {
|
|
68
|
+
const reqType = reqTypeName ? v2[reqTypeName] : undefined;
|
|
69
|
+
const resType = resTypeName ? v2[resTypeName] : undefined;
|
|
70
|
+
if (!reqType || !resType) {
|
|
71
|
+
throw new Error(`Unknown flow: '${flow}' or missing type names.`);
|
|
72
|
+
}
|
|
73
|
+
// 1. Serialize request
|
|
74
|
+
const requestBytes = Buffer.from(reqType.encode(requestMsg).finish());
|
|
75
|
+
// 2. Resolve FFI options (prefer call-specific)
|
|
76
|
+
const ffi = ffiOptions || this.options.ffi;
|
|
77
|
+
const optionsBytes = ffi ? Buffer.from(v2.FfiOptions.encode(ffi).finish()) : Buffer.alloc(0);
|
|
78
|
+
// 3. Build connector HTTP request via FFI (returns FfiConnectorHttpRequest protobuf bytes)
|
|
79
|
+
const resultBytes = this.uniffi.callReq(flow, requestBytes, metadata, optionsBytes);
|
|
80
|
+
const connectorReq = v2.FfiConnectorHttpRequest.decode(resultBytes);
|
|
81
|
+
const connectorRequest = {
|
|
82
|
+
url: connectorReq.url,
|
|
83
|
+
method: connectorReq.method,
|
|
84
|
+
headers: connectorReq.headers || {},
|
|
85
|
+
body: connectorReq.body ?? undefined
|
|
86
|
+
};
|
|
87
|
+
// 4. Execute HTTP using the instance-owned connection pool
|
|
88
|
+
const response = await (0, http_client_1.execute)(connectorRequest, this.getNativeHttpOptions(this.options.http), this.dispatcher);
|
|
89
|
+
// 5. Encode HTTP response as FfiConnectorHttpResponse protobuf bytes
|
|
90
|
+
const resProto = v2.FfiConnectorHttpResponse.create({
|
|
91
|
+
statusCode: response.statusCode,
|
|
92
|
+
headers: response.headers,
|
|
93
|
+
body: response.body
|
|
94
|
+
});
|
|
95
|
+
const resBytes = Buffer.from(v2.FfiConnectorHttpResponse.encode(resProto).finish());
|
|
96
|
+
// 6. Parse connector response via FFI and decode
|
|
97
|
+
const resultBytesRes = this.uniffi.callRes(flow, resBytes, requestBytes, metadata, optionsBytes);
|
|
98
|
+
return resType.decode(resultBytesRes);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.ConnectorClient = ConnectorClient;
|
|
102
|
+
//# sourceMappingURL=connector_client.js.map
|
|
Binary file
|