@alphawebai/hs-prism 0.1.0-rc.27
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/LICENSE +201 -0
- package/README.md +493 -0
- package/dist/src/alphaweb/contracts.d.ts +6 -0
- package/dist/src/alphaweb/contracts.js +14 -0
- package/dist/src/alphaweb/error.d.ts +13 -0
- package/dist/src/alphaweb/error.js +100 -0
- package/dist/src/alphaweb/index.d.ts +3 -0
- package/dist/src/alphaweb/index.js +22 -0
- package/dist/src/alphaweb/manifest.d.ts +28 -0
- package/dist/src/alphaweb/manifest.js +55 -0
- package/dist/src/alphaweb/money.d.ts +19 -0
- package/dist/src/alphaweb/money.js +128 -0
- package/dist/src/alphaweb/stripe-connector.d.ts +58 -0
- package/dist/src/alphaweb/stripe-connector.js +1402 -0
- package/dist/src/alphaweb/types.d.ts +255 -0
- package/dist/src/alphaweb/types.js +3 -0
- package/dist/src/http_client.d.ts +58 -0
- package/dist/src/http_client.js +179 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +41 -0
- package/dist/src/payments/_generated_connector_client_flows.d.ts +112 -0
- package/dist/src/payments/_generated_connector_client_flows.js +215 -0
- package/dist/src/payments/_generated_flows.js +141 -0
- package/dist/src/payments/_generated_grpc_client.d.ts +194 -0
- package/dist/src/payments/_generated_grpc_client.js +905 -0
- package/dist/src/payments/_generated_uniffi_client_flows.d.ts +169 -0
- package/dist/src/payments/_generated_uniffi_client_flows.js +342 -0
- package/dist/src/payments/connector_client.d.ts +51 -0
- package/dist/src/payments/connector_client.js +152 -0
- package/dist/src/payments/errors.d.ts +27 -0
- package/dist/src/payments/errors.js +39 -0
- package/dist/src/payments/generated/libconnector_service_ffi.so +0 -0
- package/dist/src/payments/generated/proto.d.ts +49087 -0
- package/dist/src/payments/generated/proto.js +154163 -0
- package/dist/src/payments/grpc_client.d.ts +1 -0
- package/dist/src/payments/grpc_client.js +20 -0
- package/dist/src/payments/uniffi_client.d.ts +40 -0
- package/dist/src/payments/uniffi_client.js +249 -0
- package/package.json +79 -0
|
@@ -0,0 +1,152 @@
|
|
|
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: edit sdk/flows.yaml and run `make codegen`.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.ConnectorClient = exports.ConnectorError = exports.IntegrationError = 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.types;
|
|
22
|
+
// Re-export error classes from errors.ts
|
|
23
|
+
var errors_1 = require("./errors");
|
|
24
|
+
Object.defineProperty(exports, "IntegrationError", { enumerable: true, get: function () { return errors_1.IntegrationError; } });
|
|
25
|
+
Object.defineProperty(exports, "ConnectorError", { enumerable: true, get: function () { return errors_1.ConnectorError; } });
|
|
26
|
+
class ConnectorClient {
|
|
27
|
+
uniffi;
|
|
28
|
+
config;
|
|
29
|
+
defaults;
|
|
30
|
+
baseHttpConfig;
|
|
31
|
+
dispatcherCache;
|
|
32
|
+
/**
|
|
33
|
+
* Initialize the client with mandatory config and optional request defaults.
|
|
34
|
+
*
|
|
35
|
+
* @param config - Immutable connector config and environment (ConnectorSpecificConfig, SdkOptions).
|
|
36
|
+
* @param defaults - Optional per-request defaults (Http, Vault).
|
|
37
|
+
* @param libPath - optional path to the UniFFI shared library.
|
|
38
|
+
*/
|
|
39
|
+
constructor(config, defaults = {}, libPath) {
|
|
40
|
+
this.uniffi = new uniffi_client_1.UniffiClient(libPath);
|
|
41
|
+
this.config = proto_1.types.ConnectorConfig.create(config);
|
|
42
|
+
this.defaults = defaults;
|
|
43
|
+
const hasConnectorVariant = !!config.connectorConfig
|
|
44
|
+
&& Object.values(config.connectorConfig).some((value) => value != null);
|
|
45
|
+
if (!hasConnectorVariant) {
|
|
46
|
+
throw new http_client_1.NetworkError("connectorConfig with a connector variant is required in ConnectorConfig", proto_1.types.NetworkErrorCode.CLIENT_INITIALIZATION_FAILURE, 400);
|
|
47
|
+
}
|
|
48
|
+
// Store base HTTP config (merged with defaults)
|
|
49
|
+
this.baseHttpConfig = defaults.http || {};
|
|
50
|
+
this.dispatcherCache = new Map();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Merges request-level options with client defaults. Environment comes from config (immutable).
|
|
54
|
+
*/
|
|
55
|
+
_resolveConfig(overrides) {
|
|
56
|
+
const opt = overrides || {};
|
|
57
|
+
const overrideHttp = opt.http || {};
|
|
58
|
+
const http = {
|
|
59
|
+
totalTimeoutMs: overrideHttp.totalTimeoutMs ?? this.baseHttpConfig.totalTimeoutMs,
|
|
60
|
+
connectTimeoutMs: overrideHttp.connectTimeoutMs ?? this.baseHttpConfig.connectTimeoutMs,
|
|
61
|
+
responseTimeoutMs: overrideHttp.responseTimeoutMs ?? this.baseHttpConfig.responseTimeoutMs,
|
|
62
|
+
keepAliveTimeoutMs: overrideHttp.keepAliveTimeoutMs ?? this.baseHttpConfig.keepAliveTimeoutMs,
|
|
63
|
+
proxy: overrideHttp.proxy ?? this.baseHttpConfig.proxy,
|
|
64
|
+
caCert: overrideHttp.caCert ?? this.baseHttpConfig.caCert,
|
|
65
|
+
};
|
|
66
|
+
const ffi = proto_1.types.FfiOptions.create({
|
|
67
|
+
environment: this.config.options?.environment ?? proto_1.types.Environment.SANDBOX,
|
|
68
|
+
connectorConfig: this.config.connectorConfig,
|
|
69
|
+
});
|
|
70
|
+
return { ffi, http };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get or create a cached dispatcher based on the effective proxy configuration.
|
|
74
|
+
*/
|
|
75
|
+
_getOrCreateDispatcher(httpConfig) {
|
|
76
|
+
const cacheKey = (0, http_client_1.generateProxyCacheKey)(httpConfig.proxy);
|
|
77
|
+
// Fast path - check cache
|
|
78
|
+
const cached = this.dispatcherCache.get(cacheKey);
|
|
79
|
+
if (cached !== undefined) {
|
|
80
|
+
return cached;
|
|
81
|
+
}
|
|
82
|
+
// Slow path - create new dispatcher
|
|
83
|
+
const newDispatcher = (0, http_client_1.createDispatcher)(httpConfig);
|
|
84
|
+
this.dispatcherCache.set(cacheKey, newDispatcher);
|
|
85
|
+
return newDispatcher;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Execute a full round-trip for any registered payment flow.
|
|
89
|
+
*
|
|
90
|
+
* @param flow - Flow name matching the FFI transformer prefix (e.g. "authorize").
|
|
91
|
+
* @param requestMsg - Protobuf request message object.
|
|
92
|
+
* @param options - Optional ConfigOptions override (Environment, Http).
|
|
93
|
+
*/
|
|
94
|
+
async _executeFlow(flow, requestMsg, options, reqTypeName, resTypeName) {
|
|
95
|
+
const reqType = reqTypeName ? v2[reqTypeName] : undefined;
|
|
96
|
+
const resType = resTypeName ? v2[resTypeName] : undefined;
|
|
97
|
+
if (!reqType || !resType) {
|
|
98
|
+
throw new Error(`Unknown flow: '${flow}' or missing type names.`);
|
|
99
|
+
}
|
|
100
|
+
// 1. Resolve final configuration
|
|
101
|
+
const { ffi, http } = this._resolveConfig(options);
|
|
102
|
+
const optionsBytes = Buffer.from(v2.FfiOptions.encode(ffi).finish());
|
|
103
|
+
// 2. Serialize domain request
|
|
104
|
+
const requestBytes = Buffer.from(reqType.encode(requestMsg).finish());
|
|
105
|
+
// 3. Build connector HTTP request via FFI
|
|
106
|
+
const resultBytes = this.uniffi.callReq(flow, requestBytes, optionsBytes);
|
|
107
|
+
const connectorReq = v2.FfiConnectorHttpRequest.decode(resultBytes);
|
|
108
|
+
const connectorRequest = {
|
|
109
|
+
url: connectorReq.url,
|
|
110
|
+
method: connectorReq.method,
|
|
111
|
+
headers: connectorReq.headers || {},
|
|
112
|
+
body: connectorReq.body ?? undefined
|
|
113
|
+
};
|
|
114
|
+
// 4. Get or create cached dispatcher based on effective proxy config
|
|
115
|
+
const dispatcher = this._getOrCreateDispatcher(http);
|
|
116
|
+
// 5. Execute HTTP using the cached connection pool
|
|
117
|
+
const response = await (0, http_client_1.execute)(connectorRequest, http, dispatcher);
|
|
118
|
+
// 6. Encode HTTP response for FFI
|
|
119
|
+
const resProto = v2.FfiConnectorHttpResponse.create({
|
|
120
|
+
statusCode: response.statusCode,
|
|
121
|
+
headers: response.headers,
|
|
122
|
+
body: response.body
|
|
123
|
+
});
|
|
124
|
+
const resBytes = Buffer.from(v2.FfiConnectorHttpResponse.encode(resProto).finish());
|
|
125
|
+
// 7. Parse connector response via FFI and decode
|
|
126
|
+
const resultBytesRes = this.uniffi.callRes(flow, resBytes, requestBytes, optionsBytes);
|
|
127
|
+
// callRes returns FfiConnectorHttpResponse, extract domain response from body
|
|
128
|
+
const httpResponse = v2.FfiConnectorHttpResponse.decode(resultBytesRes);
|
|
129
|
+
return resType.decode(httpResponse.body);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Execute a single-step flow directly via FFI (no HTTP round-trip).
|
|
133
|
+
* Used for inbound flows like webhook processing where the connector sends data to us.
|
|
134
|
+
*/
|
|
135
|
+
async _executeDirect(flow, requestMsg, options, reqTypeName, resTypeName) {
|
|
136
|
+
const reqType = reqTypeName ? v2[reqTypeName] : undefined;
|
|
137
|
+
const resType = resTypeName ? v2[resTypeName] : undefined;
|
|
138
|
+
if (!reqType || !resType) {
|
|
139
|
+
throw new Error(`Unknown flow: '${flow}' or missing type names.`);
|
|
140
|
+
}
|
|
141
|
+
// 1. Serialize request
|
|
142
|
+
const requestBytes = Buffer.from(reqType.encode(requestMsg).finish());
|
|
143
|
+
// 2. Resolve FFI options from identity + defaults + request override
|
|
144
|
+
const { ffi } = this._resolveConfig(options);
|
|
145
|
+
const optionsBytes = Buffer.from(v2.FfiOptions.encode(ffi).finish());
|
|
146
|
+
// 3. Call the single-step transformer directly (no HTTP)
|
|
147
|
+
const resultBytes = this.uniffi.callDirect(flow, requestBytes, optionsBytes);
|
|
148
|
+
return resType.decode(resultBytes);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.ConnectorClient = ConnectorClient;
|
|
152
|
+
//# sourceMappingURL=connector_client.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes for FFI-level errors.
|
|
3
|
+
*
|
|
4
|
+
* These wrap the protobuf error types and provide proper Error inheritance
|
|
5
|
+
* for use with instanceof checks and stack traces.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Exception raised when req_transformer fails (integration error).
|
|
9
|
+
* Wraps IntegrationError proto and provides access to proto fields.
|
|
10
|
+
*/
|
|
11
|
+
export declare class IntegrationError extends Error {
|
|
12
|
+
proto: any;
|
|
13
|
+
constructor(proto: any);
|
|
14
|
+
get errorCode(): string;
|
|
15
|
+
get suggestedAction(): string | undefined;
|
|
16
|
+
get docUrl(): string | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Exception raised when res_transformer fails (response transformation error).
|
|
20
|
+
* Wraps ConnectorError proto and provides access to proto fields.
|
|
21
|
+
*/
|
|
22
|
+
export declare class ConnectorError extends Error {
|
|
23
|
+
proto: any;
|
|
24
|
+
constructor(proto: any);
|
|
25
|
+
get errorCode(): string;
|
|
26
|
+
get httpStatusCode(): number | undefined;
|
|
27
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error classes for FFI-level errors.
|
|
4
|
+
*
|
|
5
|
+
* These wrap the protobuf error types and provide proper Error inheritance
|
|
6
|
+
* for use with instanceof checks and stack traces.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ConnectorError = exports.IntegrationError = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Exception raised when req_transformer fails (integration error).
|
|
12
|
+
* Wraps IntegrationError proto and provides access to proto fields.
|
|
13
|
+
*/
|
|
14
|
+
class IntegrationError extends Error {
|
|
15
|
+
proto;
|
|
16
|
+
constructor(proto) {
|
|
17
|
+
super(proto.errorMessage || proto.error_message);
|
|
18
|
+
this.proto = proto;
|
|
19
|
+
}
|
|
20
|
+
get errorCode() { return this.proto.errorCode || this.proto.error_code; }
|
|
21
|
+
get suggestedAction() { return this.proto.suggestedAction || this.proto.suggested_action; }
|
|
22
|
+
get docUrl() { return this.proto.docUrl || this.proto.doc_url; }
|
|
23
|
+
}
|
|
24
|
+
exports.IntegrationError = IntegrationError;
|
|
25
|
+
/**
|
|
26
|
+
* Exception raised when res_transformer fails (response transformation error).
|
|
27
|
+
* Wraps ConnectorError proto and provides access to proto fields.
|
|
28
|
+
*/
|
|
29
|
+
class ConnectorError extends Error {
|
|
30
|
+
proto;
|
|
31
|
+
constructor(proto) {
|
|
32
|
+
super(proto.errorMessage || proto.error_message);
|
|
33
|
+
this.proto = proto;
|
|
34
|
+
}
|
|
35
|
+
get errorCode() { return this.proto.errorCode || this.proto.error_code; }
|
|
36
|
+
get httpStatusCode() { return this.proto.httpStatusCode || this.proto.http_status_code; }
|
|
37
|
+
}
|
|
38
|
+
exports.ConnectorError = ConnectorError;
|
|
39
|
+
//# sourceMappingURL=errors.js.map
|
|
Binary file
|