@lssm/integration.providers-impls 0.0.0-canary-20251217080011 → 1.41.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/_virtual/rolldown_runtime.js +1 -42
- package/dist/calendar.js +1 -0
- package/dist/email.js +1 -0
- package/dist/embedding.js +1 -0
- package/dist/impls/elevenlabs-voice.js +1 -95
- package/dist/impls/gcs-storage.js +1 -88
- package/dist/impls/gmail-inbound.js +1 -200
- package/dist/impls/gmail-outbound.js +5 -104
- package/dist/impls/google-calendar.js +1 -154
- package/dist/impls/index.js +1 -16
- package/dist/impls/mistral-embedding.js +1 -41
- package/dist/impls/mistral-llm.js +1 -247
- package/dist/impls/postmark-email.js +1 -55
- package/dist/impls/powens-client.js +1 -171
- package/dist/impls/powens-openbanking.js +1 -218
- package/dist/impls/provider-factory.js +1 -142
- package/dist/impls/qdrant-vector.js +1 -69
- package/dist/impls/stripe-payments.js +1 -202
- package/dist/impls/twilio-sms.js +1 -58
- package/dist/index.js +1 -17
- package/dist/llm.js +1 -0
- package/dist/openbanking.js +1 -0
- package/dist/payments.js +1 -0
- package/dist/secrets/provider.js +1 -3
- package/dist/sms.js +1 -0
- package/dist/storage.js +1 -0
- package/dist/vector-store.js +1 -0
- package/dist/voice.js +1 -0
- package/package.json +33 -34
- package/dist/calendar.d.ts +0 -7
- package/dist/email.d.ts +0 -7
- package/dist/embedding.d.ts +0 -7
- package/dist/impls/elevenlabs-voice.d.ts +0 -20
- package/dist/impls/gcs-storage.d.ts +0 -24
- package/dist/impls/gmail-inbound.d.ts +0 -26
- package/dist/impls/gmail-outbound.d.ts +0 -18
- package/dist/impls/google-calendar.d.ts +0 -23
- package/dist/impls/index.d.ts +0 -15
- package/dist/impls/mistral-embedding.d.ts +0 -23
- package/dist/impls/mistral-llm.d.ts +0 -31
- package/dist/impls/postmark-email.d.ts +0 -19
- package/dist/impls/powens-client.d.ts +0 -124
- package/dist/impls/powens-openbanking.d.ts +0 -27
- package/dist/impls/provider-factory.d.ts +0 -26
- package/dist/impls/qdrant-vector.d.ts +0 -24
- package/dist/impls/stripe-payments.d.ts +0 -28
- package/dist/impls/twilio-sms.d.ts +0 -20
- package/dist/index.d.ts +0 -43
- package/dist/llm.d.ts +0 -7
- package/dist/openbanking.d.ts +0 -7
- package/dist/payments.d.ts +0 -7
- package/dist/runtime/dist/secrets/provider.js +0 -58
- package/dist/runtime.d.ts +0 -2
- package/dist/secrets/provider.d.ts +0 -2
- package/dist/sms.d.ts +0 -7
- package/dist/storage.d.ts +0 -7
- package/dist/vector-store.d.ts +0 -7
- package/dist/voice.d.ts +0 -7
|
@@ -1,171 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/impls/powens-client.ts
|
|
4
|
-
const POWENS_BASE_URL = {
|
|
5
|
-
sandbox: "https://api-sandbox.powens.com/v2",
|
|
6
|
-
production: "https://api.powens.com/v2"
|
|
7
|
-
};
|
|
8
|
-
var PowensClientError = class extends Error {
|
|
9
|
-
status;
|
|
10
|
-
code;
|
|
11
|
-
requestId;
|
|
12
|
-
response;
|
|
13
|
-
constructor(message, status, code, requestId, response) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.name = "PowensClientError";
|
|
16
|
-
this.status = status;
|
|
17
|
-
this.code = code;
|
|
18
|
-
this.requestId = requestId;
|
|
19
|
-
this.response = response;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
var PowensClient = class {
|
|
23
|
-
clientId;
|
|
24
|
-
clientSecret;
|
|
25
|
-
apiKey;
|
|
26
|
-
fetchImpl;
|
|
27
|
-
logger;
|
|
28
|
-
defaultTimeoutMs;
|
|
29
|
-
token;
|
|
30
|
-
baseUrl;
|
|
31
|
-
constructor(options) {
|
|
32
|
-
this.clientId = options.clientId;
|
|
33
|
-
this.clientSecret = options.clientSecret;
|
|
34
|
-
this.apiKey = options.apiKey;
|
|
35
|
-
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
36
|
-
this.logger = options.logger;
|
|
37
|
-
this.defaultTimeoutMs = options.defaultTimeoutMs ?? 15e3;
|
|
38
|
-
this.baseUrl = options.baseUrl ?? POWENS_BASE_URL[options.environment] ?? POWENS_BASE_URL.production;
|
|
39
|
-
}
|
|
40
|
-
async listAccounts(params) {
|
|
41
|
-
const searchParams = {
|
|
42
|
-
cursor: params.cursor,
|
|
43
|
-
limit: params.limit,
|
|
44
|
-
include_balances: params.includeBalances,
|
|
45
|
-
institution_uuid: params.institutionUuid
|
|
46
|
-
};
|
|
47
|
-
return await this.request({
|
|
48
|
-
method: "GET",
|
|
49
|
-
path: `/users/${encodeURIComponent(params.userUuid)}/accounts`,
|
|
50
|
-
searchParams
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
async getAccount(accountUuid) {
|
|
54
|
-
return this.request({
|
|
55
|
-
method: "GET",
|
|
56
|
-
path: `/accounts/${encodeURIComponent(accountUuid)}`
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
async listTransactions(params) {
|
|
60
|
-
const searchParams = {
|
|
61
|
-
cursor: params.cursor,
|
|
62
|
-
limit: params.limit,
|
|
63
|
-
from: params.from,
|
|
64
|
-
to: params.to,
|
|
65
|
-
include_pending: params.includePending
|
|
66
|
-
};
|
|
67
|
-
return this.request({
|
|
68
|
-
method: "GET",
|
|
69
|
-
path: `/accounts/${encodeURIComponent(params.accountUuid)}/transactions`,
|
|
70
|
-
searchParams
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
async getBalances(accountUuid) {
|
|
74
|
-
return this.request({
|
|
75
|
-
method: "GET",
|
|
76
|
-
path: `/accounts/${encodeURIComponent(accountUuid)}/balances`
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
async getConnectionStatus(connectionUuid) {
|
|
80
|
-
return this.request({
|
|
81
|
-
method: "GET",
|
|
82
|
-
path: `/connections/${encodeURIComponent(connectionUuid)}`
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
async request(options) {
|
|
86
|
-
const url = new URL(options.path, this.baseUrl);
|
|
87
|
-
if (options.searchParams) for (const [key, value] of Object.entries(options.searchParams)) {
|
|
88
|
-
if (value === void 0 || value === null) continue;
|
|
89
|
-
url.searchParams.set(key, String(value));
|
|
90
|
-
}
|
|
91
|
-
const headers = {
|
|
92
|
-
Accept: "application/json",
|
|
93
|
-
"Content-Type": "application/json",
|
|
94
|
-
...options.headers
|
|
95
|
-
};
|
|
96
|
-
if (this.apiKey) headers["x-api-key"] = this.apiKey;
|
|
97
|
-
if (!options.skipAuth) headers.Authorization = `Bearer ${await this.ensureAccessToken()}`;
|
|
98
|
-
const controller = new AbortController();
|
|
99
|
-
const timeout = setTimeout(() => controller.abort(), options.timeoutMs ?? this.defaultTimeoutMs);
|
|
100
|
-
try {
|
|
101
|
-
const response = await this.fetchImpl(url, {
|
|
102
|
-
method: options.method,
|
|
103
|
-
headers,
|
|
104
|
-
body: options.body ? JSON.stringify(options.body) : void 0,
|
|
105
|
-
signal: controller.signal
|
|
106
|
-
});
|
|
107
|
-
const requestId = response.headers.get("x-request-id") ?? void 0;
|
|
108
|
-
if (!response.ok) {
|
|
109
|
-
let errorBody;
|
|
110
|
-
try {
|
|
111
|
-
errorBody = await response.json();
|
|
112
|
-
} catch {}
|
|
113
|
-
const errorObject = typeof errorBody === "object" && errorBody !== null ? errorBody : void 0;
|
|
114
|
-
const message = typeof errorObject?.message === "string" ? errorObject.message : `Powens API request failed with status ${response.status}`;
|
|
115
|
-
const code = typeof errorObject?.code === "string" ? errorObject.code : void 0;
|
|
116
|
-
throw new PowensClientError(message, response.status, code, requestId, errorBody);
|
|
117
|
-
}
|
|
118
|
-
if (response.status === 204) return;
|
|
119
|
-
try {
|
|
120
|
-
return await response.json();
|
|
121
|
-
} catch (error) {
|
|
122
|
-
this.logger?.error?.("[PowensClient] Failed to parse JSON response", error);
|
|
123
|
-
throw new PowensClientError("Failed to parse Powens response payload as JSON", response.status, void 0, requestId);
|
|
124
|
-
}
|
|
125
|
-
} catch (error) {
|
|
126
|
-
if (error instanceof PowensClientError) throw error;
|
|
127
|
-
if (error.name === "AbortError") throw new PowensClientError(`Powens API request timed out after ${options.timeoutMs ?? this.defaultTimeoutMs}ms`, 408);
|
|
128
|
-
this.logger?.error?.("[PowensClient] Request failed", error);
|
|
129
|
-
throw new PowensClientError(error.message ?? "Powens API request failed", 500);
|
|
130
|
-
} finally {
|
|
131
|
-
clearTimeout(timeout);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
async ensureAccessToken() {
|
|
135
|
-
if (this.token && Date.now() < this.token.expiresAt - 5e3) return this.token.accessToken;
|
|
136
|
-
this.token = await this.fetchAccessToken();
|
|
137
|
-
return this.token.accessToken;
|
|
138
|
-
}
|
|
139
|
-
async fetchAccessToken() {
|
|
140
|
-
const url = new URL("/oauth/token", this.baseUrl);
|
|
141
|
-
const basicAuth = Buffer.from(`${this.clientId}:${this.clientSecret}`, "utf-8").toString("base64");
|
|
142
|
-
const response = await this.fetchImpl(url, {
|
|
143
|
-
method: "POST",
|
|
144
|
-
headers: {
|
|
145
|
-
Authorization: `Basic ${basicAuth}`,
|
|
146
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
147
|
-
Accept: "application/json"
|
|
148
|
-
},
|
|
149
|
-
body: new URLSearchParams({ grant_type: "client_credentials" }).toString()
|
|
150
|
-
});
|
|
151
|
-
if (!response.ok) {
|
|
152
|
-
let errorBody;
|
|
153
|
-
try {
|
|
154
|
-
errorBody = await response.json();
|
|
155
|
-
} catch {}
|
|
156
|
-
const errorObject = typeof errorBody === "object" && errorBody !== null ? errorBody : void 0;
|
|
157
|
-
throw new PowensClientError(typeof errorObject?.error_description === "string" ? errorObject.error_description : "Failed to obtain Powens access token", response.status, void 0, void 0, errorBody);
|
|
158
|
-
}
|
|
159
|
-
const payload = await response.json();
|
|
160
|
-
const expiresAt = Date.now() + payload.expires_in * 1e3;
|
|
161
|
-
this.logger?.debug?.("[PowensClient] Received access token", { expiresIn: payload.expires_in });
|
|
162
|
-
return {
|
|
163
|
-
accessToken: payload.access_token,
|
|
164
|
-
expiresAt,
|
|
165
|
-
scope: payload.scope
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
//#endregion
|
|
171
|
-
export { PowensClient, PowensClientError };
|
|
1
|
+
import{URL as e}from"node:url";const t={sandbox:`https://api-sandbox.powens.com/v2`,production:`https://api.powens.com/v2`};var n=class extends Error{status;code;requestId;response;constructor(e,t,n,r,i){super(e),this.name=`PowensClientError`,this.status=t,this.code=n,this.requestId=r,this.response=i}},r=class{clientId;clientSecret;apiKey;fetchImpl;logger;defaultTimeoutMs;token;baseUrl;constructor(e){this.clientId=e.clientId,this.clientSecret=e.clientSecret,this.apiKey=e.apiKey,this.fetchImpl=e.fetchImpl??fetch,this.logger=e.logger,this.defaultTimeoutMs=e.defaultTimeoutMs??15e3,this.baseUrl=e.baseUrl??t[e.environment]??t.production}async listAccounts(e){let t={cursor:e.cursor,limit:e.limit,include_balances:e.includeBalances,institution_uuid:e.institutionUuid};return await this.request({method:`GET`,path:`/users/${encodeURIComponent(e.userUuid)}/accounts`,searchParams:t})}async getAccount(e){return this.request({method:`GET`,path:`/accounts/${encodeURIComponent(e)}`})}async listTransactions(e){let t={cursor:e.cursor,limit:e.limit,from:e.from,to:e.to,include_pending:e.includePending};return this.request({method:`GET`,path:`/accounts/${encodeURIComponent(e.accountUuid)}/transactions`,searchParams:t})}async getBalances(e){return this.request({method:`GET`,path:`/accounts/${encodeURIComponent(e)}/balances`})}async getConnectionStatus(e){return this.request({method:`GET`,path:`/connections/${encodeURIComponent(e)}`})}async request(t){let r=new e(t.path,this.baseUrl);if(t.searchParams)for(let[e,n]of Object.entries(t.searchParams))n!=null&&r.searchParams.set(e,String(n));let i={Accept:`application/json`,"Content-Type":`application/json`,...t.headers};this.apiKey&&(i[`x-api-key`]=this.apiKey),t.skipAuth||(i.Authorization=`Bearer ${await this.ensureAccessToken()}`);let a=new AbortController,o=setTimeout(()=>a.abort(),t.timeoutMs??this.defaultTimeoutMs);try{let e=await this.fetchImpl(r,{method:t.method,headers:i,body:t.body?JSON.stringify(t.body):void 0,signal:a.signal}),o=e.headers.get(`x-request-id`)??void 0;if(!e.ok){let t;try{t=await e.json()}catch{}let r=typeof t==`object`&&t?t:void 0,i=typeof r?.message==`string`?r.message:`Powens API request failed with status ${e.status}`,a=typeof r?.code==`string`?r.code:void 0;throw new n(i,e.status,a,o,t)}if(e.status===204)return;try{return await e.json()}catch(t){throw this.logger?.error?.(`[PowensClient] Failed to parse JSON response`,t),new n(`Failed to parse Powens response payload as JSON`,e.status,void 0,o)}}catch(e){throw e instanceof n?e:e.name===`AbortError`?new n(`Powens API request timed out after ${t.timeoutMs??this.defaultTimeoutMs}ms`,408):(this.logger?.error?.(`[PowensClient] Request failed`,e),new n(e.message??`Powens API request failed`,500))}finally{clearTimeout(o)}}async ensureAccessToken(){return this.token&&Date.now()<this.token.expiresAt-5e3||(this.token=await this.fetchAccessToken()),this.token.accessToken}async fetchAccessToken(){let t=new e(`/oauth/token`,this.baseUrl),r=Buffer.from(`${this.clientId}:${this.clientSecret}`,`utf-8`).toString(`base64`),i=await this.fetchImpl(t,{method:`POST`,headers:{Authorization:`Basic ${r}`,"Content-Type":`application/x-www-form-urlencoded`,Accept:`application/json`},body:new URLSearchParams({grant_type:`client_credentials`}).toString()});if(!i.ok){let e;try{e=await i.json()}catch{}let t=typeof e==`object`&&e?e:void 0;throw new n(typeof t?.error_description==`string`?t.error_description:`Failed to obtain Powens access token`,i.status,void 0,void 0,e)}let a=await i.json(),o=Date.now()+a.expires_in*1e3;return this.logger?.debug?.(`[PowensClient] Received access token`,{expiresIn:a.expires_in}),{accessToken:a.access_token,expiresAt:o,scope:a.scope}}};export{r as PowensClient,n as PowensClientError};
|
|
@@ -1,218 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/impls/powens-openbanking.ts
|
|
4
|
-
var PowensOpenBankingProvider = class {
|
|
5
|
-
client;
|
|
6
|
-
logger;
|
|
7
|
-
constructor(options) {
|
|
8
|
-
this.client = new PowensClient(options);
|
|
9
|
-
this.logger = options.logger;
|
|
10
|
-
}
|
|
11
|
-
async listAccounts(params) {
|
|
12
|
-
if (!params.userId) throw new PowensClientError("Powens account listing requires the upstream userId mapped to Powens user UUID.", 400);
|
|
13
|
-
const context = this.toContext(params.tenantId, params.connectionId);
|
|
14
|
-
try {
|
|
15
|
-
const response = await this.client.listAccounts({
|
|
16
|
-
userUuid: params.userId,
|
|
17
|
-
cursor: params.cursor,
|
|
18
|
-
limit: params.pageSize,
|
|
19
|
-
includeBalances: params.includeBalances,
|
|
20
|
-
institutionUuid: params.institutionId
|
|
21
|
-
});
|
|
22
|
-
return {
|
|
23
|
-
accounts: response.accounts.map((account) => this.mapAccount(account, context)),
|
|
24
|
-
nextCursor: response.pagination?.nextCursor,
|
|
25
|
-
hasMore: response.pagination?.hasMore
|
|
26
|
-
};
|
|
27
|
-
} catch (error) {
|
|
28
|
-
this.handleError("listAccounts", error);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
async getAccountDetails(params) {
|
|
32
|
-
const context = this.toContext(params.tenantId, params.connectionId);
|
|
33
|
-
try {
|
|
34
|
-
const account = await this.client.getAccount(params.accountId);
|
|
35
|
-
return this.mapAccountDetails(account, context);
|
|
36
|
-
} catch (error) {
|
|
37
|
-
this.handleError("getAccountDetails", error);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async listTransactions(params) {
|
|
41
|
-
const context = this.toContext(params.tenantId, params.connectionId);
|
|
42
|
-
try {
|
|
43
|
-
const response = await this.client.listTransactions({
|
|
44
|
-
accountUuid: params.accountId,
|
|
45
|
-
cursor: params.cursor,
|
|
46
|
-
limit: params.pageSize,
|
|
47
|
-
from: params.from,
|
|
48
|
-
to: params.to,
|
|
49
|
-
includePending: params.includePending
|
|
50
|
-
});
|
|
51
|
-
return {
|
|
52
|
-
transactions: response.transactions.map((transaction) => this.mapTransaction(transaction, context)),
|
|
53
|
-
nextCursor: response.pagination?.nextCursor,
|
|
54
|
-
hasMore: response.pagination?.hasMore
|
|
55
|
-
};
|
|
56
|
-
} catch (error) {
|
|
57
|
-
this.handleError("listTransactions", error);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async getBalances(params) {
|
|
61
|
-
const context = this.toContext(params.tenantId, params.connectionId);
|
|
62
|
-
try {
|
|
63
|
-
return (await this.client.getBalances(params.accountId)).filter((balance) => params.balanceTypes?.length ? params.balanceTypes.includes(balance.type) : true).map((balance) => this.mapBalance(balance, context));
|
|
64
|
-
} catch (error) {
|
|
65
|
-
this.handleError("getBalances", error);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
async getConnectionStatus(params) {
|
|
69
|
-
try {
|
|
70
|
-
const status = await this.client.getConnectionStatus(params.connectionId);
|
|
71
|
-
return {
|
|
72
|
-
connectionId: params.connectionId,
|
|
73
|
-
tenantId: params.tenantId,
|
|
74
|
-
status: this.mapConnectionStatus(status.status),
|
|
75
|
-
lastCheckedAt: status.lastAttemptAt,
|
|
76
|
-
errorCode: status.errorCode,
|
|
77
|
-
errorMessage: status.errorMessage,
|
|
78
|
-
details: status.metadata
|
|
79
|
-
};
|
|
80
|
-
} catch (error) {
|
|
81
|
-
this.handleError("getConnectionStatus", error);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
mapAccount(account, context) {
|
|
85
|
-
return {
|
|
86
|
-
id: account.uuid,
|
|
87
|
-
externalId: account.reference ?? account.uuid,
|
|
88
|
-
tenantId: context.tenantId,
|
|
89
|
-
connectionId: context.connectionId,
|
|
90
|
-
userId: account.userUuid,
|
|
91
|
-
displayName: account.name,
|
|
92
|
-
institutionId: account.institution.id,
|
|
93
|
-
institutionName: account.institution.name,
|
|
94
|
-
institutionLogoUrl: account.institution.logoUrl,
|
|
95
|
-
accountType: account.type ?? "unknown",
|
|
96
|
-
iban: account.iban,
|
|
97
|
-
bic: account.bic,
|
|
98
|
-
currency: account.currency ?? "EUR",
|
|
99
|
-
accountNumberMasked: account.metadata?.account_number_masked,
|
|
100
|
-
ownership: this.mapOwnership(account.metadata?.ownership),
|
|
101
|
-
status: this.mapAccountStatus(account.status),
|
|
102
|
-
lastSyncedAt: account.metadata?.last_sync_at,
|
|
103
|
-
metadata: account.metadata
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
mapAccountDetails(account, context) {
|
|
107
|
-
return {
|
|
108
|
-
...this.mapAccount(account, context),
|
|
109
|
-
productCode: account.metadata?.product_code,
|
|
110
|
-
openedAt: account.metadata?.opened_at,
|
|
111
|
-
closedAt: account.metadata?.closed_at,
|
|
112
|
-
availableBalance: account.availableBalance ?? void 0,
|
|
113
|
-
currentBalance: account.balance ?? void 0,
|
|
114
|
-
creditLimit: account.metadata?.credit_limit,
|
|
115
|
-
customFields: account.metadata
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
mapTransaction(transaction, context) {
|
|
119
|
-
return {
|
|
120
|
-
id: transaction.uuid,
|
|
121
|
-
externalId: transaction.uuid,
|
|
122
|
-
tenantId: context.tenantId,
|
|
123
|
-
accountId: transaction.accountUuid,
|
|
124
|
-
connectionId: context.connectionId,
|
|
125
|
-
amount: transaction.amount,
|
|
126
|
-
currency: transaction.currency,
|
|
127
|
-
direction: transaction.direction === "credit" ? "credit" : "debit",
|
|
128
|
-
description: transaction.description ?? transaction.rawLabel,
|
|
129
|
-
bookingDate: transaction.bookingDate,
|
|
130
|
-
valueDate: transaction.valueDate,
|
|
131
|
-
postedAt: transaction.bookingDate,
|
|
132
|
-
category: transaction.category,
|
|
133
|
-
rawCategory: transaction.rawLabel,
|
|
134
|
-
merchantName: transaction.merchantName,
|
|
135
|
-
merchantCategoryCode: transaction.merchantCategoryCode,
|
|
136
|
-
counterpartyName: transaction.counterpartyName,
|
|
137
|
-
counterpartyAccount: transaction.counterpartyAccount,
|
|
138
|
-
reference: transaction.metadata?.reference,
|
|
139
|
-
status: this.mapTransactionStatus(transaction.status),
|
|
140
|
-
metadata: transaction.metadata
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
mapBalance(balance, context) {
|
|
144
|
-
return {
|
|
145
|
-
accountId: balance.accountUuid,
|
|
146
|
-
connectionId: context.connectionId,
|
|
147
|
-
tenantId: context.tenantId,
|
|
148
|
-
type: balance.type ?? "current",
|
|
149
|
-
currency: balance.currency ?? "EUR",
|
|
150
|
-
amount: balance.amount,
|
|
151
|
-
lastUpdatedAt: balance.updatedAt,
|
|
152
|
-
metadata: balance.metadata
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
toContext(tenantId, connectionId) {
|
|
156
|
-
return {
|
|
157
|
-
tenantId,
|
|
158
|
-
connectionId
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
mapOwnership(value) {
|
|
162
|
-
switch (value?.toLowerCase()) {
|
|
163
|
-
case "individual":
|
|
164
|
-
case "personal": return "individual";
|
|
165
|
-
case "joint": return "joint";
|
|
166
|
-
case "business":
|
|
167
|
-
case "corporate": return "business";
|
|
168
|
-
default: return "unknown";
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
mapAccountStatus(status) {
|
|
172
|
-
switch (status?.toLowerCase()) {
|
|
173
|
-
case "active":
|
|
174
|
-
case "enabled": return "active";
|
|
175
|
-
case "disabled":
|
|
176
|
-
case "inactive": return "inactive";
|
|
177
|
-
case "closed": return "closed";
|
|
178
|
-
case "suspended": return "suspended";
|
|
179
|
-
default: return "active";
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
mapTransactionStatus(status) {
|
|
183
|
-
switch (status?.toLowerCase()) {
|
|
184
|
-
case "pending":
|
|
185
|
-
case "authorised": return "pending";
|
|
186
|
-
case "booked":
|
|
187
|
-
case "posted": return "booked";
|
|
188
|
-
case "cancelled":
|
|
189
|
-
case "rejected": return "cancelled";
|
|
190
|
-
default: return "booked";
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
mapConnectionStatus(status) {
|
|
194
|
-
switch (status) {
|
|
195
|
-
case "healthy": return "healthy";
|
|
196
|
-
case "pending": return "degraded";
|
|
197
|
-
case "error": return "error";
|
|
198
|
-
case "revoked": return "disconnected";
|
|
199
|
-
default: return "degraded";
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
handleError(operation, error) {
|
|
203
|
-
if (error instanceof PowensClientError) {
|
|
204
|
-
this.logger?.error?.(`[PowensOpenBankingProvider] ${operation} failed`, {
|
|
205
|
-
status: error.status,
|
|
206
|
-
code: error.code,
|
|
207
|
-
requestId: error.requestId,
|
|
208
|
-
message: error.message
|
|
209
|
-
});
|
|
210
|
-
throw error;
|
|
211
|
-
}
|
|
212
|
-
this.logger?.error?.(`[PowensOpenBankingProvider] ${operation} failed with unexpected error`, error);
|
|
213
|
-
throw error instanceof Error ? error : /* @__PURE__ */ new Error(`Powens operation "${operation}" failed`);
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
//#endregion
|
|
218
|
-
export { PowensOpenBankingProvider };
|
|
1
|
+
import{PowensClient as e,PowensClientError as t}from"./powens-client.js";var n=class{client;logger;constructor(t){this.client=new e(t),this.logger=t.logger}async listAccounts(e){if(!e.userId)throw new t(`Powens account listing requires the upstream userId mapped to Powens user UUID.`,400);let n=this.toContext(e.tenantId,e.connectionId);try{let t=await this.client.listAccounts({userUuid:e.userId,cursor:e.cursor,limit:e.pageSize,includeBalances:e.includeBalances,institutionUuid:e.institutionId});return{accounts:t.accounts.map(e=>this.mapAccount(e,n)),nextCursor:t.pagination?.nextCursor,hasMore:t.pagination?.hasMore}}catch(e){this.handleError(`listAccounts`,e)}}async getAccountDetails(e){let t=this.toContext(e.tenantId,e.connectionId);try{let n=await this.client.getAccount(e.accountId);return this.mapAccountDetails(n,t)}catch(e){this.handleError(`getAccountDetails`,e)}}async listTransactions(e){let t=this.toContext(e.tenantId,e.connectionId);try{let n=await this.client.listTransactions({accountUuid:e.accountId,cursor:e.cursor,limit:e.pageSize,from:e.from,to:e.to,includePending:e.includePending});return{transactions:n.transactions.map(e=>this.mapTransaction(e,t)),nextCursor:n.pagination?.nextCursor,hasMore:n.pagination?.hasMore}}catch(e){this.handleError(`listTransactions`,e)}}async getBalances(e){let t=this.toContext(e.tenantId,e.connectionId);try{return(await this.client.getBalances(e.accountId)).filter(t=>e.balanceTypes?.length?e.balanceTypes.includes(t.type):!0).map(e=>this.mapBalance(e,t))}catch(e){this.handleError(`getBalances`,e)}}async getConnectionStatus(e){try{let t=await this.client.getConnectionStatus(e.connectionId);return{connectionId:e.connectionId,tenantId:e.tenantId,status:this.mapConnectionStatus(t.status),lastCheckedAt:t.lastAttemptAt,errorCode:t.errorCode,errorMessage:t.errorMessage,details:t.metadata}}catch(e){this.handleError(`getConnectionStatus`,e)}}mapAccount(e,t){return{id:e.uuid,externalId:e.reference??e.uuid,tenantId:t.tenantId,connectionId:t.connectionId,userId:e.userUuid,displayName:e.name,institutionId:e.institution.id,institutionName:e.institution.name,institutionLogoUrl:e.institution.logoUrl,accountType:e.type??`unknown`,iban:e.iban,bic:e.bic,currency:e.currency??`EUR`,accountNumberMasked:e.metadata?.account_number_masked,ownership:this.mapOwnership(e.metadata?.ownership),status:this.mapAccountStatus(e.status),lastSyncedAt:e.metadata?.last_sync_at,metadata:e.metadata}}mapAccountDetails(e,t){return{...this.mapAccount(e,t),productCode:e.metadata?.product_code,openedAt:e.metadata?.opened_at,closedAt:e.metadata?.closed_at,availableBalance:e.availableBalance??void 0,currentBalance:e.balance??void 0,creditLimit:e.metadata?.credit_limit,customFields:e.metadata}}mapTransaction(e,t){return{id:e.uuid,externalId:e.uuid,tenantId:t.tenantId,accountId:e.accountUuid,connectionId:t.connectionId,amount:e.amount,currency:e.currency,direction:e.direction===`credit`?`credit`:`debit`,description:e.description??e.rawLabel,bookingDate:e.bookingDate,valueDate:e.valueDate,postedAt:e.bookingDate,category:e.category,rawCategory:e.rawLabel,merchantName:e.merchantName,merchantCategoryCode:e.merchantCategoryCode,counterpartyName:e.counterpartyName,counterpartyAccount:e.counterpartyAccount,reference:e.metadata?.reference,status:this.mapTransactionStatus(e.status),metadata:e.metadata}}mapBalance(e,t){return{accountId:e.accountUuid,connectionId:t.connectionId,tenantId:t.tenantId,type:e.type??`current`,currency:e.currency??`EUR`,amount:e.amount,lastUpdatedAt:e.updatedAt,metadata:e.metadata}}toContext(e,t){return{tenantId:e,connectionId:t}}mapOwnership(e){switch(e?.toLowerCase()){case`individual`:case`personal`:return`individual`;case`joint`:return`joint`;case`business`:case`corporate`:return`business`;default:return`unknown`}}mapAccountStatus(e){switch(e?.toLowerCase()){case`active`:case`enabled`:return`active`;case`disabled`:case`inactive`:return`inactive`;case`closed`:return`closed`;case`suspended`:return`suspended`;default:return`active`}}mapTransactionStatus(e){switch(e?.toLowerCase()){case`pending`:case`authorised`:return`pending`;case`booked`:case`posted`:return`booked`;case`cancelled`:case`rejected`:return`cancelled`;default:return`booked`}}mapConnectionStatus(e){switch(e){case`healthy`:return`healthy`;case`pending`:return`degraded`;case`error`:return`error`;case`revoked`:return`disconnected`;default:return`degraded`}}handleError(e,n){throw n instanceof t?(this.logger?.error?.(`[PowensOpenBankingProvider] ${e} failed`,{status:n.status,code:n.code,requestId:n.requestId,message:n.message}),n):(this.logger?.error?.(`[PowensOpenBankingProvider] ${e} failed with unexpected error`,n),n instanceof Error?n:Error(`Powens operation "${e}" failed`))}};export{n as PowensOpenBankingProvider};
|
|
@@ -1,142 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MistralEmbeddingProvider } from "./mistral-embedding.js";
|
|
3
|
-
import { QdrantVectorProvider } from "./qdrant-vector.js";
|
|
4
|
-
import { GoogleCloudStorageProvider } from "./gcs-storage.js";
|
|
5
|
-
import { StripePaymentsProvider } from "./stripe-payments.js";
|
|
6
|
-
import { PostmarkEmailProvider } from "./postmark-email.js";
|
|
7
|
-
import { TwilioSmsProvider } from "./twilio-sms.js";
|
|
8
|
-
import { ElevenLabsVoiceProvider } from "./elevenlabs-voice.js";
|
|
9
|
-
import { PowensOpenBankingProvider } from "./powens-openbanking.js";
|
|
10
|
-
import { Buffer } from "node:buffer";
|
|
11
|
-
|
|
12
|
-
//#region src/impls/provider-factory.ts
|
|
13
|
-
const SECRET_CACHE = /* @__PURE__ */ new Map();
|
|
14
|
-
var IntegrationProviderFactory = class {
|
|
15
|
-
async createPaymentsProvider(context) {
|
|
16
|
-
const secrets = await this.loadSecrets(context);
|
|
17
|
-
switch (context.spec.meta.key) {
|
|
18
|
-
case "payments.stripe": return new StripePaymentsProvider({ apiKey: requireSecret(secrets, "apiKey", "Stripe API key is required") });
|
|
19
|
-
default: throw new Error(`Unsupported payments integration: ${context.spec.meta.key}`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async createEmailOutboundProvider(context) {
|
|
23
|
-
const secrets = await this.loadSecrets(context);
|
|
24
|
-
switch (context.spec.meta.key) {
|
|
25
|
-
case "email.postmark": return new PostmarkEmailProvider({
|
|
26
|
-
serverToken: requireSecret(secrets, "serverToken", "Postmark server token is required"),
|
|
27
|
-
defaultFromEmail: context.config.fromEmail,
|
|
28
|
-
messageStream: context.config.messageStream
|
|
29
|
-
});
|
|
30
|
-
default: throw new Error(`Unsupported email integration: ${context.spec.meta.key}`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async createSmsProvider(context) {
|
|
34
|
-
const secrets = await this.loadSecrets(context);
|
|
35
|
-
switch (context.spec.meta.key) {
|
|
36
|
-
case "sms.twilio": return new TwilioSmsProvider({
|
|
37
|
-
accountSid: requireSecret(secrets, "accountSid", "Twilio account SID is required"),
|
|
38
|
-
authToken: requireSecret(secrets, "authToken", "Twilio auth token is required"),
|
|
39
|
-
fromNumber: context.config.fromNumber
|
|
40
|
-
});
|
|
41
|
-
default: throw new Error(`Unsupported SMS integration: ${context.spec.meta.key}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
async createVectorStoreProvider(context) {
|
|
45
|
-
const secrets = await this.loadSecrets(context);
|
|
46
|
-
switch (context.spec.meta.key) {
|
|
47
|
-
case "vectordb.qdrant": return new QdrantVectorProvider({
|
|
48
|
-
url: requireConfig(context, "apiUrl", "Qdrant apiUrl config is required"),
|
|
49
|
-
apiKey: secrets.apiKey
|
|
50
|
-
});
|
|
51
|
-
default: throw new Error(`Unsupported vector store integration: ${context.spec.meta.key}`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async createObjectStorageProvider(context) {
|
|
55
|
-
const secrets = await this.loadSecrets(context);
|
|
56
|
-
switch (context.spec.meta.key) {
|
|
57
|
-
case "storage.s3":
|
|
58
|
-
case "storage.gcs": return new GoogleCloudStorageProvider({
|
|
59
|
-
bucket: requireConfig(context, "bucket", "Storage bucket is required"),
|
|
60
|
-
clientOptions: secrets.type === "service_account" ? { credentials: secrets } : void 0
|
|
61
|
-
});
|
|
62
|
-
default: throw new Error(`Unsupported storage integration: ${context.spec.meta.key}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async createVoiceProvider(context) {
|
|
66
|
-
const secrets = await this.loadSecrets(context);
|
|
67
|
-
switch (context.spec.meta.key) {
|
|
68
|
-
case "ai-voice.elevenlabs": return new ElevenLabsVoiceProvider({
|
|
69
|
-
apiKey: requireSecret(secrets, "apiKey", "ElevenLabs API key is required"),
|
|
70
|
-
defaultVoiceId: context.config.defaultVoiceId
|
|
71
|
-
});
|
|
72
|
-
default: throw new Error(`Unsupported voice integration: ${context.spec.meta.key}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
async createLlmProvider(context) {
|
|
76
|
-
const secrets = await this.loadSecrets(context);
|
|
77
|
-
switch (context.spec.meta.key) {
|
|
78
|
-
case "ai-llm.mistral": return new MistralLLMProvider({
|
|
79
|
-
apiKey: requireSecret(secrets, "apiKey", "Mistral API key is required"),
|
|
80
|
-
defaultModel: context.config.model
|
|
81
|
-
});
|
|
82
|
-
default: throw new Error(`Unsupported LLM integration: ${context.spec.meta.key}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async createEmbeddingProvider(context) {
|
|
86
|
-
const secrets = await this.loadSecrets(context);
|
|
87
|
-
switch (context.spec.meta.key) {
|
|
88
|
-
case "ai-llm.mistral": return new MistralEmbeddingProvider({
|
|
89
|
-
apiKey: requireSecret(secrets, "apiKey", "Mistral API key is required"),
|
|
90
|
-
defaultModel: context.config.embeddingModel
|
|
91
|
-
});
|
|
92
|
-
default: throw new Error(`Unsupported embeddings integration: ${context.spec.meta.key}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
async createOpenBankingProvider(context) {
|
|
96
|
-
const secrets = await this.loadSecrets(context);
|
|
97
|
-
const config = context.config;
|
|
98
|
-
switch (context.spec.meta.key) {
|
|
99
|
-
case "openbanking.powens": {
|
|
100
|
-
const environmentValue = requireConfig(context, "environment", "Powens environment (sandbox | production) must be specified in integration config.");
|
|
101
|
-
if (environmentValue !== "sandbox" && environmentValue !== "production") throw new Error(`Powens environment "${environmentValue}" is invalid. Expected "sandbox" or "production".`);
|
|
102
|
-
return new PowensOpenBankingProvider({
|
|
103
|
-
clientId: requireSecret(secrets, "clientId", "Powens clientId is required"),
|
|
104
|
-
clientSecret: requireSecret(secrets, "clientSecret", "Powens clientSecret is required"),
|
|
105
|
-
apiKey: secrets.apiKey,
|
|
106
|
-
environment: environmentValue,
|
|
107
|
-
baseUrl: config?.baseUrl
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
default: throw new Error(`Unsupported open banking integration: ${context.spec.meta.key}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
async loadSecrets(context) {
|
|
114
|
-
const cacheKey = context.connection.meta.id;
|
|
115
|
-
if (SECRET_CACHE.has(cacheKey)) return SECRET_CACHE.get(cacheKey);
|
|
116
|
-
const value = parseSecret(await context.secretProvider.getSecret(context.secretReference));
|
|
117
|
-
SECRET_CACHE.set(cacheKey, value);
|
|
118
|
-
return value;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
function parseSecret(secret) {
|
|
122
|
-
const text = Buffer.from(secret.data).toString("utf-8").trim();
|
|
123
|
-
if (!text) return {};
|
|
124
|
-
try {
|
|
125
|
-
return JSON.parse(text);
|
|
126
|
-
} catch {
|
|
127
|
-
return { apiKey: text };
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function requireSecret(secrets, key, message) {
|
|
131
|
-
const value = secrets[key];
|
|
132
|
-
if (value == null || value === "") throw new Error(message);
|
|
133
|
-
return value;
|
|
134
|
-
}
|
|
135
|
-
function requireConfig(context, key, message) {
|
|
136
|
-
const value = context.config?.[key];
|
|
137
|
-
if (value == null) throw new Error(message);
|
|
138
|
-
return value;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
//#endregion
|
|
142
|
-
export { IntegrationProviderFactory };
|
|
1
|
+
import{MistralLLMProvider as e}from"./mistral-llm.js";import{MistralEmbeddingProvider as t}from"./mistral-embedding.js";import{QdrantVectorProvider as n}from"./qdrant-vector.js";import{GoogleCloudStorageProvider as r}from"./gcs-storage.js";import{StripePaymentsProvider as i}from"./stripe-payments.js";import{PostmarkEmailProvider as a}from"./postmark-email.js";import{TwilioSmsProvider as o}from"./twilio-sms.js";import{ElevenLabsVoiceProvider as s}from"./elevenlabs-voice.js";import{PowensOpenBankingProvider as c}from"./powens-openbanking.js";import{Buffer as l}from"node:buffer";const u=new Map;var d=class{async createPaymentsProvider(e){let t=await this.loadSecrets(e);switch(e.spec.meta.key){case`payments.stripe`:return new i({apiKey:p(t,`apiKey`,`Stripe API key is required`)});default:throw Error(`Unsupported payments integration: ${e.spec.meta.key}`)}}async createEmailOutboundProvider(e){let t=await this.loadSecrets(e);switch(e.spec.meta.key){case`email.postmark`:return new a({serverToken:p(t,`serverToken`,`Postmark server token is required`),defaultFromEmail:e.config.fromEmail,messageStream:e.config.messageStream});default:throw Error(`Unsupported email integration: ${e.spec.meta.key}`)}}async createSmsProvider(e){let t=await this.loadSecrets(e);switch(e.spec.meta.key){case`sms.twilio`:return new o({accountSid:p(t,`accountSid`,`Twilio account SID is required`),authToken:p(t,`authToken`,`Twilio auth token is required`),fromNumber:e.config.fromNumber});default:throw Error(`Unsupported SMS integration: ${e.spec.meta.key}`)}}async createVectorStoreProvider(e){let t=await this.loadSecrets(e);switch(e.spec.meta.key){case`vectordb.qdrant`:return new n({url:m(e,`apiUrl`,`Qdrant apiUrl config is required`),apiKey:t.apiKey});default:throw Error(`Unsupported vector store integration: ${e.spec.meta.key}`)}}async createObjectStorageProvider(e){let t=await this.loadSecrets(e);switch(e.spec.meta.key){case`storage.s3`:case`storage.gcs`:return new r({bucket:m(e,`bucket`,`Storage bucket is required`),clientOptions:t.type===`service_account`?{credentials:t}:void 0});default:throw Error(`Unsupported storage integration: ${e.spec.meta.key}`)}}async createVoiceProvider(e){let t=await this.loadSecrets(e);switch(e.spec.meta.key){case`ai-voice.elevenlabs`:return new s({apiKey:p(t,`apiKey`,`ElevenLabs API key is required`),defaultVoiceId:e.config.defaultVoiceId});default:throw Error(`Unsupported voice integration: ${e.spec.meta.key}`)}}async createLlmProvider(t){let n=await this.loadSecrets(t);switch(t.spec.meta.key){case`ai-llm.mistral`:return new e({apiKey:p(n,`apiKey`,`Mistral API key is required`),defaultModel:t.config.model});default:throw Error(`Unsupported LLM integration: ${t.spec.meta.key}`)}}async createEmbeddingProvider(e){let n=await this.loadSecrets(e);switch(e.spec.meta.key){case`ai-llm.mistral`:return new t({apiKey:p(n,`apiKey`,`Mistral API key is required`),defaultModel:e.config.embeddingModel});default:throw Error(`Unsupported embeddings integration: ${e.spec.meta.key}`)}}async createOpenBankingProvider(e){let t=await this.loadSecrets(e),n=e.config;switch(e.spec.meta.key){case`openbanking.powens`:{let r=m(e,`environment`,`Powens environment (sandbox | production) must be specified in integration config.`);if(r!==`sandbox`&&r!==`production`)throw Error(`Powens environment "${r}" is invalid. Expected "sandbox" or "production".`);return new c({clientId:p(t,`clientId`,`Powens clientId is required`),clientSecret:p(t,`clientSecret`,`Powens clientSecret is required`),apiKey:t.apiKey,environment:r,baseUrl:n?.baseUrl})}default:throw Error(`Unsupported open banking integration: ${e.spec.meta.key}`)}}async loadSecrets(e){let t=e.connection.meta.id;if(u.has(t))return u.get(t);let n=f(await e.secretProvider.getSecret(e.secretReference));return u.set(t,n),n}};function f(e){let t=l.from(e.data).toString(`utf-8`).trim();if(!t)return{};try{return JSON.parse(t)}catch{return{apiKey:t}}}function p(e,t,n){let r=e[t];if(r==null||r===``)throw Error(n);return r}function m(e,t,n){let r=e.config?.[t];if(r==null)throw Error(n);return r}export{d as IntegrationProviderFactory};
|
|
@@ -1,69 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/impls/qdrant-vector.ts
|
|
4
|
-
var QdrantVectorProvider = class {
|
|
5
|
-
client;
|
|
6
|
-
createCollectionIfMissing;
|
|
7
|
-
distance;
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.client = options.client ?? new QdrantClient({
|
|
10
|
-
url: options.url,
|
|
11
|
-
apiKey: options.apiKey,
|
|
12
|
-
...options.clientParams
|
|
13
|
-
});
|
|
14
|
-
this.createCollectionIfMissing = options.createCollectionIfMissing ?? true;
|
|
15
|
-
this.distance = options.distance ?? "Cosine";
|
|
16
|
-
}
|
|
17
|
-
async upsert(request) {
|
|
18
|
-
if (request.documents.length === 0) return;
|
|
19
|
-
const vectorSize = request.documents[0].vector.length;
|
|
20
|
-
if (this.createCollectionIfMissing) await this.ensureCollection(request.collection, vectorSize);
|
|
21
|
-
const points = request.documents.map((document) => ({
|
|
22
|
-
id: document.id,
|
|
23
|
-
vector: document.vector,
|
|
24
|
-
payload: {
|
|
25
|
-
...document.payload,
|
|
26
|
-
...document.namespace ? { namespace: document.namespace } : {},
|
|
27
|
-
...document.expiresAt ? { expiresAt: document.expiresAt.toISOString() } : {}
|
|
28
|
-
}
|
|
29
|
-
}));
|
|
30
|
-
await this.client.upsert(request.collection, {
|
|
31
|
-
wait: true,
|
|
32
|
-
points
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
async search(query) {
|
|
36
|
-
return (await this.client.search(query.collection, {
|
|
37
|
-
vector: query.vector,
|
|
38
|
-
limit: query.topK,
|
|
39
|
-
filter: query.filter,
|
|
40
|
-
score_threshold: query.scoreThreshold,
|
|
41
|
-
with_payload: true,
|
|
42
|
-
with_vector: false
|
|
43
|
-
})).map((item) => ({
|
|
44
|
-
id: String(item.id),
|
|
45
|
-
score: item.score,
|
|
46
|
-
payload: item.payload ?? void 0,
|
|
47
|
-
namespace: typeof item.payload === "object" && item.payload !== null ? item.payload.namespace : void 0
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
async delete(request) {
|
|
51
|
-
await this.client.delete(request.collection, {
|
|
52
|
-
wait: true,
|
|
53
|
-
points: request.ids
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
async ensureCollection(collectionName, vectorSize) {
|
|
57
|
-
try {
|
|
58
|
-
await this.client.getCollection(collectionName);
|
|
59
|
-
} catch (error) {
|
|
60
|
-
await this.client.createCollection(collectionName, { vectors: {
|
|
61
|
-
size: vectorSize,
|
|
62
|
-
distance: this.distance
|
|
63
|
-
} });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
//#endregion
|
|
69
|
-
export { QdrantVectorProvider };
|
|
1
|
+
import{QdrantClient as e}from"@qdrant/js-client-rest";var t=class{client;createCollectionIfMissing;distance;constructor(t){this.client=t.client??new e({url:t.url,apiKey:t.apiKey,...t.clientParams}),this.createCollectionIfMissing=t.createCollectionIfMissing??!0,this.distance=t.distance??`Cosine`}async upsert(e){if(e.documents.length===0)return;let t=e.documents[0].vector.length;this.createCollectionIfMissing&&await this.ensureCollection(e.collection,t);let n=e.documents.map(e=>({id:e.id,vector:e.vector,payload:{...e.payload,...e.namespace?{namespace:e.namespace}:{},...e.expiresAt?{expiresAt:e.expiresAt.toISOString()}:{}}}));await this.client.upsert(e.collection,{wait:!0,points:n})}async search(e){return(await this.client.search(e.collection,{vector:e.vector,limit:e.topK,filter:e.filter,score_threshold:e.scoreThreshold,with_payload:!0,with_vector:!1})).map(e=>({id:String(e.id),score:e.score,payload:e.payload??void 0,namespace:typeof e.payload==`object`&&e.payload!==null?e.payload.namespace:void 0}))}async delete(e){await this.client.delete(e.collection,{wait:!0,points:e.ids})}async ensureCollection(e,t){try{await this.client.getCollection(e)}catch{await this.client.createCollection(e,{vectors:{size:t,distance:this.distance}})}}};export{t as QdrantVectorProvider};
|