@contractspec/integration.providers-impls 3.8.9 → 3.8.11

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.
Files changed (147) hide show
  1. package/dist/analytics.js +1 -2
  2. package/dist/calendar.js +1 -2
  3. package/dist/database.js +1 -2
  4. package/dist/email.js +1 -2
  5. package/dist/embedding.js +1 -2
  6. package/dist/health.js +1 -2
  7. package/dist/impls/async-event-queue.js +1 -48
  8. package/dist/impls/composio-fallback-resolver.js +1 -579
  9. package/dist/impls/composio-mcp.js +1 -163
  10. package/dist/impls/composio-proxies.js +1 -310
  11. package/dist/impls/composio-sdk.js +1 -77
  12. package/dist/impls/composio-types.js +1 -53
  13. package/dist/impls/elevenlabs-voice.js +1 -104
  14. package/dist/impls/fal-voice.js +1 -117
  15. package/dist/impls/fathom-meeting-recorder.js +2 -289
  16. package/dist/impls/fathom-meeting-recorder.mapper.js +1 -107
  17. package/dist/impls/fathom-meeting-recorder.utils.js +1 -74
  18. package/dist/impls/fathom-meeting-recorder.webhooks.js +1 -31
  19. package/dist/impls/fireflies-meeting-recorder.js +5 -203
  20. package/dist/impls/fireflies-meeting-recorder.queries.js +4 -14
  21. package/dist/impls/fireflies-meeting-recorder.utils.js +1 -44
  22. package/dist/impls/gcs-storage.js +1 -99
  23. package/dist/impls/gmail-inbound.js +1 -229
  24. package/dist/impls/gmail-outbound.js +25 -137
  25. package/dist/impls/google-calendar.js +1 -193
  26. package/dist/impls/gradium-voice.js +1 -95
  27. package/dist/impls/granola-meeting-recorder.js +3 -514
  28. package/dist/impls/granola-meeting-recorder.mcp.js +1 -280
  29. package/dist/impls/health/base-health-provider.js +1 -617
  30. package/dist/impls/health/hybrid-health-providers.js +1 -1089
  31. package/dist/impls/health/official-health-providers.js +1 -969
  32. package/dist/impls/health/provider-normalizers.js +1 -288
  33. package/dist/impls/health/providers.js +1 -1095
  34. package/dist/impls/health-provider-factory.js +1 -1309
  35. package/dist/impls/index.js +42 -7448
  36. package/dist/impls/jira.js +1 -126
  37. package/dist/impls/linear.js +1 -85
  38. package/dist/impls/messaging-github.js +1 -111
  39. package/dist/impls/messaging-slack.js +1 -81
  40. package/dist/impls/messaging-telegram.js +1 -48
  41. package/dist/impls/messaging-whatsapp-meta.js +1 -53
  42. package/dist/impls/messaging-whatsapp-twilio.js +1 -83
  43. package/dist/impls/mistral-conversational.js +2 -477
  44. package/dist/impls/mistral-conversational.session.js +2 -207
  45. package/dist/impls/mistral-embedding.js +1 -45
  46. package/dist/impls/mistral-llm.js +1 -271
  47. package/dist/impls/mistral-stt.js +1 -168
  48. package/dist/impls/notion.js +1 -162
  49. package/dist/impls/posthog-reader.js +1 -161
  50. package/dist/impls/posthog-utils.js +1 -40
  51. package/dist/impls/posthog.js +1 -324
  52. package/dist/impls/postmark-email.js +1 -62
  53. package/dist/impls/powens-client.js +1 -197
  54. package/dist/impls/powens-openbanking.js +1 -428
  55. package/dist/impls/provider-factory.js +18 -6268
  56. package/dist/impls/qdrant-vector.js +1 -80
  57. package/dist/impls/stripe-payments.js +1 -230
  58. package/dist/impls/supabase-psql.js +1 -152
  59. package/dist/impls/supabase-vector.js +9 -298
  60. package/dist/impls/tldv-meeting-recorder.js +2 -147
  61. package/dist/impls/twilio-sms.js +1 -67
  62. package/dist/index.js +42 -7495
  63. package/dist/llm.js +1 -2
  64. package/dist/meeting-recorder.js +1 -2
  65. package/dist/messaging.js +1 -2
  66. package/dist/node/analytics.js +1 -2
  67. package/dist/node/calendar.js +1 -2
  68. package/dist/node/database.js +1 -2
  69. package/dist/node/email.js +1 -2
  70. package/dist/node/embedding.js +1 -2
  71. package/dist/node/health.js +1 -2
  72. package/dist/node/impls/async-event-queue.js +1 -49
  73. package/dist/node/impls/composio-fallback-resolver.js +1 -580
  74. package/dist/node/impls/composio-mcp.js +1 -164
  75. package/dist/node/impls/composio-proxies.js +1 -311
  76. package/dist/node/impls/composio-sdk.js +1 -78
  77. package/dist/node/impls/composio-types.js +1 -54
  78. package/dist/node/impls/elevenlabs-voice.js +1 -105
  79. package/dist/node/impls/fal-voice.js +1 -118
  80. package/dist/node/impls/fathom-meeting-recorder.js +2 -290
  81. package/dist/node/impls/fathom-meeting-recorder.mapper.js +1 -108
  82. package/dist/node/impls/fathom-meeting-recorder.utils.js +1 -75
  83. package/dist/node/impls/fathom-meeting-recorder.webhooks.js +1 -32
  84. package/dist/node/impls/fireflies-meeting-recorder.js +5 -204
  85. package/dist/node/impls/fireflies-meeting-recorder.queries.js +4 -15
  86. package/dist/node/impls/fireflies-meeting-recorder.utils.js +1 -45
  87. package/dist/node/impls/gcs-storage.js +1 -100
  88. package/dist/node/impls/gmail-inbound.js +1 -230
  89. package/dist/node/impls/gmail-outbound.js +25 -138
  90. package/dist/node/impls/google-calendar.js +1 -194
  91. package/dist/node/impls/gradium-voice.js +1 -96
  92. package/dist/node/impls/granola-meeting-recorder.js +3 -515
  93. package/dist/node/impls/granola-meeting-recorder.mcp.js +1 -281
  94. package/dist/node/impls/health/base-health-provider.js +1 -618
  95. package/dist/node/impls/health/hybrid-health-providers.js +1 -1090
  96. package/dist/node/impls/health/official-health-providers.js +1 -970
  97. package/dist/node/impls/health/provider-normalizers.js +1 -289
  98. package/dist/node/impls/health/providers.js +1 -1096
  99. package/dist/node/impls/health-provider-factory.js +1 -1310
  100. package/dist/node/impls/index.js +42 -7449
  101. package/dist/node/impls/jira.js +1 -127
  102. package/dist/node/impls/linear.js +1 -86
  103. package/dist/node/impls/messaging-github.js +1 -112
  104. package/dist/node/impls/messaging-slack.js +1 -82
  105. package/dist/node/impls/messaging-telegram.js +1 -49
  106. package/dist/node/impls/messaging-whatsapp-meta.js +1 -54
  107. package/dist/node/impls/messaging-whatsapp-twilio.js +1 -84
  108. package/dist/node/impls/mistral-conversational.js +2 -478
  109. package/dist/node/impls/mistral-conversational.session.js +2 -208
  110. package/dist/node/impls/mistral-embedding.js +1 -46
  111. package/dist/node/impls/mistral-llm.js +1 -272
  112. package/dist/node/impls/mistral-stt.js +1 -169
  113. package/dist/node/impls/notion.js +1 -163
  114. package/dist/node/impls/posthog-reader.js +1 -162
  115. package/dist/node/impls/posthog-utils.js +1 -41
  116. package/dist/node/impls/posthog.js +1 -325
  117. package/dist/node/impls/postmark-email.js +1 -63
  118. package/dist/node/impls/powens-client.js +1 -198
  119. package/dist/node/impls/powens-openbanking.js +1 -429
  120. package/dist/node/impls/provider-factory.js +18 -6269
  121. package/dist/node/impls/qdrant-vector.js +1 -81
  122. package/dist/node/impls/stripe-payments.js +1 -231
  123. package/dist/node/impls/supabase-psql.js +1 -153
  124. package/dist/node/impls/supabase-vector.js +9 -299
  125. package/dist/node/impls/tldv-meeting-recorder.js +2 -148
  126. package/dist/node/impls/twilio-sms.js +1 -68
  127. package/dist/node/index.js +42 -7496
  128. package/dist/node/llm.js +1 -2
  129. package/dist/node/meeting-recorder.js +1 -2
  130. package/dist/node/messaging.js +1 -2
  131. package/dist/node/openbanking.js +1 -2
  132. package/dist/node/payments.js +1 -2
  133. package/dist/node/project-management.js +1 -2
  134. package/dist/node/secrets/provider.js +1 -14
  135. package/dist/node/sms.js +1 -2
  136. package/dist/node/storage.js +1 -2
  137. package/dist/node/vector-store.js +1 -2
  138. package/dist/node/voice.js +1 -2
  139. package/dist/openbanking.js +1 -2
  140. package/dist/payments.js +1 -2
  141. package/dist/project-management.js +1 -2
  142. package/dist/secrets/provider.js +1 -13
  143. package/dist/sms.js +1 -2
  144. package/dist/storage.js +1 -2
  145. package/dist/vector-store.js +1 -2
  146. package/dist/voice.js +1 -2
  147. package/package.json +16 -16
@@ -1,198 +1,2 @@
1
1
  // @bun
2
- var __require = import.meta.require;
3
-
4
- // src/impls/powens-client.ts
5
- import { URL } from "url";
6
- var POWENS_BASE_URL = {
7
- sandbox: "https://api-sandbox.powens.com/v2",
8
- production: "https://api.powens.com/v2"
9
- };
10
-
11
- class PowensClientError extends Error {
12
- status;
13
- code;
14
- requestId;
15
- response;
16
- constructor(message, status, code, requestId, response) {
17
- super(message);
18
- this.name = "PowensClientError";
19
- this.status = status;
20
- this.code = code;
21
- this.requestId = requestId;
22
- this.response = response;
23
- }
24
- }
25
-
26
- class PowensClient {
27
- clientId;
28
- clientSecret;
29
- apiKey;
30
- fetchImpl;
31
- logger;
32
- defaultTimeoutMs;
33
- token;
34
- baseUrl;
35
- constructor(options) {
36
- this.clientId = options.clientId;
37
- this.clientSecret = options.clientSecret;
38
- this.apiKey = options.apiKey;
39
- this.fetchImpl = options.fetchImpl ?? fetch;
40
- this.logger = options.logger;
41
- this.defaultTimeoutMs = options.defaultTimeoutMs ?? 15000;
42
- this.baseUrl = options.baseUrl ?? POWENS_BASE_URL[options.environment] ?? POWENS_BASE_URL.production;
43
- }
44
- async listAccounts(params) {
45
- const searchParams = {
46
- cursor: params.cursor,
47
- limit: params.limit,
48
- include_balances: params.includeBalances,
49
- institution_uuid: params.institutionUuid
50
- };
51
- const response = await this.request({
52
- method: "GET",
53
- path: `/users/${encodeURIComponent(params.userUuid)}/accounts`,
54
- searchParams
55
- });
56
- return response;
57
- }
58
- async getAccount(accountUuid) {
59
- return this.request({
60
- method: "GET",
61
- path: `/accounts/${encodeURIComponent(accountUuid)}`
62
- });
63
- }
64
- async listTransactions(params) {
65
- const searchParams = {
66
- cursor: params.cursor,
67
- limit: params.limit,
68
- from: params.from,
69
- to: params.to,
70
- include_pending: params.includePending
71
- };
72
- return this.request({
73
- method: "GET",
74
- path: `/accounts/${encodeURIComponent(params.accountUuid)}/transactions`,
75
- searchParams
76
- });
77
- }
78
- async getBalances(accountUuid) {
79
- return this.request({
80
- method: "GET",
81
- path: `/accounts/${encodeURIComponent(accountUuid)}/balances`
82
- });
83
- }
84
- async getConnectionStatus(connectionUuid) {
85
- return this.request({
86
- method: "GET",
87
- path: `/connections/${encodeURIComponent(connectionUuid)}`
88
- });
89
- }
90
- async request(options) {
91
- const url = new URL(options.path, this.baseUrl);
92
- if (options.searchParams) {
93
- for (const [key, value] of Object.entries(options.searchParams)) {
94
- if (value === undefined || value === null)
95
- continue;
96
- url.searchParams.set(key, String(value));
97
- }
98
- }
99
- const headers = {
100
- Accept: "application/json",
101
- "Content-Type": "application/json",
102
- ...options.headers
103
- };
104
- if (this.apiKey) {
105
- headers["x-api-key"] = this.apiKey;
106
- }
107
- if (!options.skipAuth) {
108
- const token = await this.ensureAccessToken();
109
- headers.Authorization = `Bearer ${token}`;
110
- }
111
- const controller = new AbortController;
112
- const timeout = setTimeout(() => controller.abort(), options.timeoutMs ?? this.defaultTimeoutMs);
113
- try {
114
- const response = await this.fetchImpl(url, {
115
- method: options.method,
116
- headers,
117
- body: options.body ? JSON.stringify(options.body) : undefined,
118
- signal: controller.signal
119
- });
120
- const requestId = response.headers.get("x-request-id") ?? undefined;
121
- if (!response.ok) {
122
- let errorBody;
123
- try {
124
- errorBody = await response.json();
125
- } catch {}
126
- const errorObject = typeof errorBody === "object" && errorBody !== null ? errorBody : undefined;
127
- const message = typeof errorObject?.message === "string" ? errorObject.message : `Powens API request failed with status ${response.status}`;
128
- const code = typeof errorObject?.code === "string" ? errorObject.code : undefined;
129
- throw new PowensClientError(message, response.status, code, requestId, errorBody);
130
- }
131
- if (response.status === 204) {
132
- return;
133
- }
134
- try {
135
- return await response.json();
136
- } catch (error) {
137
- this.logger?.error?.("[PowensClient] Failed to parse JSON response", error);
138
- throw new PowensClientError("Failed to parse Powens response payload as JSON", response.status, undefined, requestId);
139
- }
140
- } catch (error) {
141
- if (error instanceof PowensClientError) {
142
- throw error;
143
- }
144
- if (error.name === "AbortError") {
145
- throw new PowensClientError(`Powens API request timed out after ${options.timeoutMs ?? this.defaultTimeoutMs}ms`, 408);
146
- }
147
- this.logger?.error?.("[PowensClient] Request failed", error);
148
- throw new PowensClientError(error.message ?? "Powens API request failed", 500);
149
- } finally {
150
- clearTimeout(timeout);
151
- }
152
- }
153
- async ensureAccessToken() {
154
- if (this.token && Date.now() < this.token.expiresAt - 5000) {
155
- return this.token.accessToken;
156
- }
157
- this.token = await this.fetchAccessToken();
158
- return this.token.accessToken;
159
- }
160
- async fetchAccessToken() {
161
- const url = new URL("/oauth/token", this.baseUrl);
162
- const basicAuth = Buffer.from(`${this.clientId}:${this.clientSecret}`, "utf-8").toString("base64");
163
- const response = await this.fetchImpl(url, {
164
- method: "POST",
165
- headers: {
166
- Authorization: `Basic ${basicAuth}`,
167
- "Content-Type": "application/x-www-form-urlencoded",
168
- Accept: "application/json"
169
- },
170
- body: new URLSearchParams({
171
- grant_type: "client_credentials"
172
- }).toString()
173
- });
174
- if (!response.ok) {
175
- let errorBody;
176
- try {
177
- errorBody = await response.json();
178
- } catch {}
179
- const errorObject = typeof errorBody === "object" && errorBody !== null ? errorBody : undefined;
180
- const message = typeof errorObject?.error_description === "string" ? errorObject.error_description : "Failed to obtain Powens access token";
181
- throw new PowensClientError(message, response.status, undefined, undefined, errorBody);
182
- }
183
- const payload = await response.json();
184
- const expiresAt = Date.now() + payload.expires_in * 1000;
185
- this.logger?.debug?.("[PowensClient] Received access token", {
186
- expiresIn: payload.expires_in
187
- });
188
- return {
189
- accessToken: payload.access_token,
190
- expiresAt,
191
- scope: payload.scope
192
- };
193
- }
194
- }
195
- export {
196
- PowensClientError,
197
- PowensClient
198
- };
2
+ var m=import.meta.require;import{URL as d}from"url";var g={sandbox:"https://api-sandbox.powens.com/v2",production:"https://api.powens.com/v2"};class a extends Error{status;code;requestId;response;constructor(e,s,t,r,c){super(e);this.name="PowensClientError",this.status=s,this.code=t,this.requestId=r,this.response=c}}class h{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??15000,this.baseUrl=e.baseUrl??g[e.environment]??g.production}async listAccounts(e){let s={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:s})}async getAccount(e){return this.request({method:"GET",path:`/accounts/${encodeURIComponent(e)}`})}async listTransactions(e){let s={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:s})}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(e){let s=new d(e.path,this.baseUrl);if(e.searchParams)for(let[n,o]of Object.entries(e.searchParams)){if(o===void 0||o===null)continue;s.searchParams.set(n,String(o))}let t={Accept:"application/json","Content-Type":"application/json",...e.headers};if(this.apiKey)t["x-api-key"]=this.apiKey;if(!e.skipAuth){let n=await this.ensureAccessToken();t.Authorization=`Bearer ${n}`}let r=new AbortController,c=setTimeout(()=>r.abort(),e.timeoutMs??this.defaultTimeoutMs);try{let n=await this.fetchImpl(s,{method:e.method,headers:t,body:e.body?JSON.stringify(e.body):void 0,signal:r.signal}),o=n.headers.get("x-request-id")??void 0;if(!n.ok){let i;try{i=await n.json()}catch{}let u=typeof i==="object"&&i!==null?i:void 0,l=typeof u?.message==="string"?u.message:`Powens API request failed with status ${n.status}`,p=typeof u?.code==="string"?u.code:void 0;throw new a(l,n.status,p,o,i)}if(n.status===204)return;try{return await n.json()}catch(i){throw this.logger?.error?.("[PowensClient] Failed to parse JSON response",i),new a("Failed to parse Powens response payload as JSON",n.status,void 0,o)}}catch(n){if(n instanceof a)throw n;if(n.name==="AbortError")throw new a(`Powens API request timed out after ${e.timeoutMs??this.defaultTimeoutMs}ms`,408);throw this.logger?.error?.("[PowensClient] Request failed",n),new a(n.message??"Powens API request failed",500)}finally{clearTimeout(c)}}async ensureAccessToken(){if(this.token&&Date.now()<this.token.expiresAt-5000)return this.token.accessToken;return this.token=await this.fetchAccessToken(),this.token.accessToken}async fetchAccessToken(){let e=new d("/oauth/token",this.baseUrl),s=Buffer.from(`${this.clientId}:${this.clientSecret}`,"utf-8").toString("base64"),t=await this.fetchImpl(e,{method:"POST",headers:{Authorization:`Basic ${s}`,"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"},body:new URLSearchParams({grant_type:"client_credentials"}).toString()});if(!t.ok){let n;try{n=await t.json()}catch{}let o=typeof n==="object"&&n!==null?n:void 0,i=typeof o?.error_description==="string"?o.error_description:"Failed to obtain Powens access token";throw new a(i,t.status,void 0,void 0,n)}let r=await t.json(),c=Date.now()+r.expires_in*1000;return this.logger?.debug?.("[PowensClient] Received access token",{expiresIn:r.expires_in}),{accessToken:r.access_token,expiresAt:c,scope:r.scope}}}export{a as PowensClientError,h as PowensClient};
@@ -1,429 +1,2 @@
1
1
  // @bun
2
- var __require = import.meta.require;
3
-
4
- // src/impls/powens-client.ts
5
- import { URL } from "url";
6
- var POWENS_BASE_URL = {
7
- sandbox: "https://api-sandbox.powens.com/v2",
8
- production: "https://api.powens.com/v2"
9
- };
10
-
11
- class PowensClientError extends Error {
12
- status;
13
- code;
14
- requestId;
15
- response;
16
- constructor(message, status, code, requestId, response) {
17
- super(message);
18
- this.name = "PowensClientError";
19
- this.status = status;
20
- this.code = code;
21
- this.requestId = requestId;
22
- this.response = response;
23
- }
24
- }
25
-
26
- class PowensClient {
27
- clientId;
28
- clientSecret;
29
- apiKey;
30
- fetchImpl;
31
- logger;
32
- defaultTimeoutMs;
33
- token;
34
- baseUrl;
35
- constructor(options) {
36
- this.clientId = options.clientId;
37
- this.clientSecret = options.clientSecret;
38
- this.apiKey = options.apiKey;
39
- this.fetchImpl = options.fetchImpl ?? fetch;
40
- this.logger = options.logger;
41
- this.defaultTimeoutMs = options.defaultTimeoutMs ?? 15000;
42
- this.baseUrl = options.baseUrl ?? POWENS_BASE_URL[options.environment] ?? POWENS_BASE_URL.production;
43
- }
44
- async listAccounts(params) {
45
- const searchParams = {
46
- cursor: params.cursor,
47
- limit: params.limit,
48
- include_balances: params.includeBalances,
49
- institution_uuid: params.institutionUuid
50
- };
51
- const response = await this.request({
52
- method: "GET",
53
- path: `/users/${encodeURIComponent(params.userUuid)}/accounts`,
54
- searchParams
55
- });
56
- return response;
57
- }
58
- async getAccount(accountUuid) {
59
- return this.request({
60
- method: "GET",
61
- path: `/accounts/${encodeURIComponent(accountUuid)}`
62
- });
63
- }
64
- async listTransactions(params) {
65
- const searchParams = {
66
- cursor: params.cursor,
67
- limit: params.limit,
68
- from: params.from,
69
- to: params.to,
70
- include_pending: params.includePending
71
- };
72
- return this.request({
73
- method: "GET",
74
- path: `/accounts/${encodeURIComponent(params.accountUuid)}/transactions`,
75
- searchParams
76
- });
77
- }
78
- async getBalances(accountUuid) {
79
- return this.request({
80
- method: "GET",
81
- path: `/accounts/${encodeURIComponent(accountUuid)}/balances`
82
- });
83
- }
84
- async getConnectionStatus(connectionUuid) {
85
- return this.request({
86
- method: "GET",
87
- path: `/connections/${encodeURIComponent(connectionUuid)}`
88
- });
89
- }
90
- async request(options) {
91
- const url = new URL(options.path, this.baseUrl);
92
- if (options.searchParams) {
93
- for (const [key, value] of Object.entries(options.searchParams)) {
94
- if (value === undefined || value === null)
95
- continue;
96
- url.searchParams.set(key, String(value));
97
- }
98
- }
99
- const headers = {
100
- Accept: "application/json",
101
- "Content-Type": "application/json",
102
- ...options.headers
103
- };
104
- if (this.apiKey) {
105
- headers["x-api-key"] = this.apiKey;
106
- }
107
- if (!options.skipAuth) {
108
- const token = await this.ensureAccessToken();
109
- headers.Authorization = `Bearer ${token}`;
110
- }
111
- const controller = new AbortController;
112
- const timeout = setTimeout(() => controller.abort(), options.timeoutMs ?? this.defaultTimeoutMs);
113
- try {
114
- const response = await this.fetchImpl(url, {
115
- method: options.method,
116
- headers,
117
- body: options.body ? JSON.stringify(options.body) : undefined,
118
- signal: controller.signal
119
- });
120
- const requestId = response.headers.get("x-request-id") ?? undefined;
121
- if (!response.ok) {
122
- let errorBody;
123
- try {
124
- errorBody = await response.json();
125
- } catch {}
126
- const errorObject = typeof errorBody === "object" && errorBody !== null ? errorBody : undefined;
127
- const message = typeof errorObject?.message === "string" ? errorObject.message : `Powens API request failed with status ${response.status}`;
128
- const code = typeof errorObject?.code === "string" ? errorObject.code : undefined;
129
- throw new PowensClientError(message, response.status, code, requestId, errorBody);
130
- }
131
- if (response.status === 204) {
132
- return;
133
- }
134
- try {
135
- return await response.json();
136
- } catch (error) {
137
- this.logger?.error?.("[PowensClient] Failed to parse JSON response", error);
138
- throw new PowensClientError("Failed to parse Powens response payload as JSON", response.status, undefined, requestId);
139
- }
140
- } catch (error) {
141
- if (error instanceof PowensClientError) {
142
- throw error;
143
- }
144
- if (error.name === "AbortError") {
145
- throw new PowensClientError(`Powens API request timed out after ${options.timeoutMs ?? this.defaultTimeoutMs}ms`, 408);
146
- }
147
- this.logger?.error?.("[PowensClient] Request failed", error);
148
- throw new PowensClientError(error.message ?? "Powens API request failed", 500);
149
- } finally {
150
- clearTimeout(timeout);
151
- }
152
- }
153
- async ensureAccessToken() {
154
- if (this.token && Date.now() < this.token.expiresAt - 5000) {
155
- return this.token.accessToken;
156
- }
157
- this.token = await this.fetchAccessToken();
158
- return this.token.accessToken;
159
- }
160
- async fetchAccessToken() {
161
- const url = new URL("/oauth/token", this.baseUrl);
162
- const basicAuth = Buffer.from(`${this.clientId}:${this.clientSecret}`, "utf-8").toString("base64");
163
- const response = await this.fetchImpl(url, {
164
- method: "POST",
165
- headers: {
166
- Authorization: `Basic ${basicAuth}`,
167
- "Content-Type": "application/x-www-form-urlencoded",
168
- Accept: "application/json"
169
- },
170
- body: new URLSearchParams({
171
- grant_type: "client_credentials"
172
- }).toString()
173
- });
174
- if (!response.ok) {
175
- let errorBody;
176
- try {
177
- errorBody = await response.json();
178
- } catch {}
179
- const errorObject = typeof errorBody === "object" && errorBody !== null ? errorBody : undefined;
180
- const message = typeof errorObject?.error_description === "string" ? errorObject.error_description : "Failed to obtain Powens access token";
181
- throw new PowensClientError(message, response.status, undefined, undefined, errorBody);
182
- }
183
- const payload = await response.json();
184
- const expiresAt = Date.now() + payload.expires_in * 1000;
185
- this.logger?.debug?.("[PowensClient] Received access token", {
186
- expiresIn: payload.expires_in
187
- });
188
- return {
189
- accessToken: payload.access_token,
190
- expiresAt,
191
- scope: payload.scope
192
- };
193
- }
194
- }
195
-
196
- // src/impls/powens-openbanking.ts
197
- class PowensOpenBankingProvider {
198
- client;
199
- logger;
200
- constructor(options) {
201
- this.client = new PowensClient(options);
202
- this.logger = options.logger;
203
- }
204
- async listAccounts(params) {
205
- if (!params.userId) {
206
- throw new PowensClientError("Powens account listing requires the upstream userId mapped to Powens user UUID.", 400);
207
- }
208
- const context = this.toContext(params.tenantId, params.connectionId);
209
- try {
210
- const response = await this.client.listAccounts({
211
- userUuid: params.userId,
212
- cursor: params.cursor,
213
- limit: params.pageSize,
214
- includeBalances: params.includeBalances,
215
- institutionUuid: params.institutionId
216
- });
217
- return {
218
- accounts: response.accounts.map((account) => this.mapAccount(account, context)),
219
- nextCursor: response.pagination?.nextCursor,
220
- hasMore: response.pagination?.hasMore
221
- };
222
- } catch (error) {
223
- this.handleError("listAccounts", error);
224
- }
225
- }
226
- async getAccountDetails(params) {
227
- const context = this.toContext(params.tenantId, params.connectionId);
228
- try {
229
- const account = await this.client.getAccount(params.accountId);
230
- return this.mapAccountDetails(account, context);
231
- } catch (error) {
232
- this.handleError("getAccountDetails", error);
233
- }
234
- }
235
- async listTransactions(params) {
236
- const context = this.toContext(params.tenantId, params.connectionId);
237
- try {
238
- const response = await this.client.listTransactions({
239
- accountUuid: params.accountId,
240
- cursor: params.cursor,
241
- limit: params.pageSize,
242
- from: params.from,
243
- to: params.to,
244
- includePending: params.includePending
245
- });
246
- return {
247
- transactions: response.transactions.map((transaction) => this.mapTransaction(transaction, context)),
248
- nextCursor: response.pagination?.nextCursor,
249
- hasMore: response.pagination?.hasMore
250
- };
251
- } catch (error) {
252
- this.handleError("listTransactions", error);
253
- }
254
- }
255
- async getBalances(params) {
256
- const context = this.toContext(params.tenantId, params.connectionId);
257
- try {
258
- const balances = await this.client.getBalances(params.accountId);
259
- return balances.filter((balance) => params.balanceTypes?.length ? params.balanceTypes.includes(String(balance.type)) : true).map((balance) => this.mapBalance(balance, context));
260
- } catch (error) {
261
- this.handleError("getBalances", error);
262
- }
263
- }
264
- async getConnectionStatus(params) {
265
- try {
266
- const status = await this.client.getConnectionStatus(params.connectionId);
267
- return {
268
- connectionId: params.connectionId,
269
- tenantId: params.tenantId,
270
- status: this.mapConnectionStatus(status.status),
271
- lastCheckedAt: status.lastAttemptAt,
272
- errorCode: status.errorCode,
273
- errorMessage: status.errorMessage,
274
- details: status.metadata
275
- };
276
- } catch (error) {
277
- this.handleError("getConnectionStatus", error);
278
- }
279
- }
280
- mapAccount(account, context) {
281
- return {
282
- id: account.uuid,
283
- externalId: account.reference ?? account.uuid,
284
- tenantId: context.tenantId,
285
- connectionId: context.connectionId,
286
- userId: account.userUuid,
287
- displayName: account.name,
288
- institutionId: account.institution.id,
289
- institutionName: account.institution.name,
290
- institutionLogoUrl: account.institution.logoUrl,
291
- accountType: account.type ?? "unknown",
292
- iban: account.iban,
293
- bic: account.bic,
294
- currency: account.currency ?? "EUR",
295
- accountNumberMasked: account.metadata?.account_number_masked,
296
- ownership: this.mapOwnership(account.metadata?.ownership),
297
- status: this.mapAccountStatus(account.status),
298
- lastSyncedAt: account.metadata?.last_sync_at,
299
- metadata: account.metadata
300
- };
301
- }
302
- mapAccountDetails(account, context) {
303
- return {
304
- ...this.mapAccount(account, context),
305
- productCode: account.metadata?.product_code,
306
- openedAt: account.metadata?.opened_at,
307
- closedAt: account.metadata?.closed_at,
308
- availableBalance: account.availableBalance ?? undefined,
309
- currentBalance: account.balance ?? undefined,
310
- creditLimit: account.metadata?.credit_limit,
311
- customFields: account.metadata
312
- };
313
- }
314
- mapTransaction(transaction, context) {
315
- return {
316
- id: transaction.uuid,
317
- externalId: transaction.uuid,
318
- tenantId: context.tenantId,
319
- accountId: transaction.accountUuid,
320
- connectionId: context.connectionId,
321
- amount: transaction.amount,
322
- currency: transaction.currency,
323
- direction: transaction.direction === "credit" ? "credit" : "debit",
324
- description: transaction.description ?? transaction.rawLabel,
325
- bookingDate: transaction.bookingDate,
326
- valueDate: transaction.valueDate,
327
- postedAt: transaction.bookingDate,
328
- category: transaction.category,
329
- rawCategory: transaction.rawLabel,
330
- merchantName: transaction.merchantName,
331
- merchantCategoryCode: transaction.merchantCategoryCode,
332
- counterpartyName: transaction.counterpartyName,
333
- counterpartyAccount: transaction.counterpartyAccount,
334
- reference: transaction.metadata?.reference,
335
- status: this.mapTransactionStatus(transaction.status),
336
- metadata: transaction.metadata
337
- };
338
- }
339
- mapBalance(balance, context) {
340
- return {
341
- accountId: balance.accountUuid,
342
- connectionId: context.connectionId,
343
- tenantId: context.tenantId,
344
- type: balance.type ?? "current",
345
- currency: balance.currency ?? "EUR",
346
- amount: balance.amount,
347
- lastUpdatedAt: balance.updatedAt,
348
- metadata: balance.metadata
349
- };
350
- }
351
- toContext(tenantId, connectionId) {
352
- return { tenantId, connectionId };
353
- }
354
- mapOwnership(value) {
355
- switch (value?.toLowerCase()) {
356
- case "individual":
357
- case "personal":
358
- return "individual";
359
- case "joint":
360
- return "joint";
361
- case "business":
362
- case "corporate":
363
- return "business";
364
- default:
365
- return "unknown";
366
- }
367
- }
368
- mapAccountStatus(status) {
369
- switch (status?.toLowerCase()) {
370
- case "active":
371
- case "enabled":
372
- return "active";
373
- case "disabled":
374
- case "inactive":
375
- return "inactive";
376
- case "closed":
377
- return "closed";
378
- case "suspended":
379
- return "suspended";
380
- default:
381
- return "active";
382
- }
383
- }
384
- mapTransactionStatus(status) {
385
- switch (status?.toLowerCase()) {
386
- case "pending":
387
- case "authorised":
388
- return "pending";
389
- case "booked":
390
- case "posted":
391
- return "booked";
392
- case "cancelled":
393
- case "rejected":
394
- return "cancelled";
395
- default:
396
- return "booked";
397
- }
398
- }
399
- mapConnectionStatus(status) {
400
- switch (status) {
401
- case "healthy":
402
- return "healthy";
403
- case "pending":
404
- return "degraded";
405
- case "error":
406
- return "error";
407
- case "revoked":
408
- return "disconnected";
409
- default:
410
- return "degraded";
411
- }
412
- }
413
- handleError(operation, error) {
414
- if (error instanceof PowensClientError) {
415
- this.logger?.error?.(`[PowensOpenBankingProvider] ${operation} failed`, {
416
- status: error.status,
417
- code: error.code,
418
- requestId: error.requestId,
419
- message: error.message
420
- });
421
- throw error;
422
- }
423
- this.logger?.error?.(`[PowensOpenBankingProvider] ${operation} failed with unexpected error`, error);
424
- throw error instanceof Error ? error : new Error(`Powens operation "${operation}" failed`);
425
- }
426
- }
427
- export {
428
- PowensOpenBankingProvider
429
- };
2
+ var w=import.meta.require;import{URL as l}from"url";var g={sandbox:"https://api-sandbox.powens.com/v2",production:"https://api.powens.com/v2"};class i extends Error{status;code;requestId;response;constructor(e,n,t,r,c){super(e);this.name="PowensClientError",this.status=n,this.code=t,this.requestId=r,this.response=c}}class d{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??15000,this.baseUrl=e.baseUrl??g[e.environment]??g.production}async listAccounts(e){let n={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:n})}async getAccount(e){return this.request({method:"GET",path:`/accounts/${encodeURIComponent(e)}`})}async listTransactions(e){let n={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:n})}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(e){let n=new l(e.path,this.baseUrl);if(e.searchParams)for(let[s,o]of Object.entries(e.searchParams)){if(o===void 0||o===null)continue;n.searchParams.set(s,String(o))}let t={Accept:"application/json","Content-Type":"application/json",...e.headers};if(this.apiKey)t["x-api-key"]=this.apiKey;if(!e.skipAuth){let s=await this.ensureAccessToken();t.Authorization=`Bearer ${s}`}let r=new AbortController,c=setTimeout(()=>r.abort(),e.timeoutMs??this.defaultTimeoutMs);try{let s=await this.fetchImpl(n,{method:e.method,headers:t,body:e.body?JSON.stringify(e.body):void 0,signal:r.signal}),o=s.headers.get("x-request-id")??void 0;if(!s.ok){let a;try{a=await s.json()}catch{}let u=typeof a==="object"&&a!==null?a:void 0,p=typeof u?.message==="string"?u.message:`Powens API request failed with status ${s.status}`,h=typeof u?.code==="string"?u.code:void 0;throw new i(p,s.status,h,o,a)}if(s.status===204)return;try{return await s.json()}catch(a){throw this.logger?.error?.("[PowensClient] Failed to parse JSON response",a),new i("Failed to parse Powens response payload as JSON",s.status,void 0,o)}}catch(s){if(s instanceof i)throw s;if(s.name==="AbortError")throw new i(`Powens API request timed out after ${e.timeoutMs??this.defaultTimeoutMs}ms`,408);throw this.logger?.error?.("[PowensClient] Request failed",s),new i(s.message??"Powens API request failed",500)}finally{clearTimeout(c)}}async ensureAccessToken(){if(this.token&&Date.now()<this.token.expiresAt-5000)return this.token.accessToken;return this.token=await this.fetchAccessToken(),this.token.accessToken}async fetchAccessToken(){let e=new l("/oauth/token",this.baseUrl),n=Buffer.from(`${this.clientId}:${this.clientSecret}`,"utf-8").toString("base64"),t=await this.fetchImpl(e,{method:"POST",headers:{Authorization:`Basic ${n}`,"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"},body:new URLSearchParams({grant_type:"client_credentials"}).toString()});if(!t.ok){let s;try{s=await t.json()}catch{}let o=typeof s==="object"&&s!==null?s:void 0,a=typeof o?.error_description==="string"?o.error_description:"Failed to obtain Powens access token";throw new i(a,t.status,void 0,void 0,s)}let r=await t.json(),c=Date.now()+r.expires_in*1000;return this.logger?.debug?.("[PowensClient] Received access token",{expiresIn:r.expires_in}),{accessToken:r.access_token,expiresAt:c,scope:r.scope}}}class m{client;logger;constructor(e){this.client=new d(e),this.logger=e.logger}async listAccounts(e){if(!e.userId)throw new i("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((r)=>this.mapAccount(r,n)),nextCursor:t.pagination?.nextCursor,hasMore:t.pagination?.hasMore}}catch(t){this.handleError("listAccounts",t)}}async getAccountDetails(e){let n=this.toContext(e.tenantId,e.connectionId);try{let t=await this.client.getAccount(e.accountId);return this.mapAccountDetails(t,n)}catch(t){this.handleError("getAccountDetails",t)}}async listTransactions(e){let n=this.toContext(e.tenantId,e.connectionId);try{let t=await this.client.listTransactions({accountUuid:e.accountId,cursor:e.cursor,limit:e.pageSize,from:e.from,to:e.to,includePending:e.includePending});return{transactions:t.transactions.map((r)=>this.mapTransaction(r,n)),nextCursor:t.pagination?.nextCursor,hasMore:t.pagination?.hasMore}}catch(t){this.handleError("listTransactions",t)}}async getBalances(e){let n=this.toContext(e.tenantId,e.connectionId);try{return(await this.client.getBalances(e.accountId)).filter((r)=>e.balanceTypes?.length?e.balanceTypes.includes(String(r.type)):!0).map((r)=>this.mapBalance(r,n))}catch(t){this.handleError("getBalances",t)}}async getConnectionStatus(e){try{let n=await this.client.getConnectionStatus(e.connectionId);return{connectionId:e.connectionId,tenantId:e.tenantId,status:this.mapConnectionStatus(n.status),lastCheckedAt:n.lastAttemptAt,errorCode:n.errorCode,errorMessage:n.errorMessage,details:n.metadata}}catch(n){this.handleError("getConnectionStatus",n)}}mapAccount(e,n){return{id:e.uuid,externalId:e.reference??e.uuid,tenantId:n.tenantId,connectionId:n.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,n){return{...this.mapAccount(e,n),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,n){return{id:e.uuid,externalId:e.uuid,tenantId:n.tenantId,accountId:e.accountUuid,connectionId:n.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,n){return{accountId:e.accountUuid,connectionId:n.connectionId,tenantId:n.tenantId,type:e.type??"current",currency:e.currency??"EUR",amount:e.amount,lastUpdatedAt:e.updatedAt,metadata:e.metadata}}toContext(e,n){return{tenantId:e,connectionId:n}}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){if(n instanceof i)throw this.logger?.error?.(`[PowensOpenBankingProvider] ${e} failed`,{status:n.status,code:n.code,requestId:n.requestId,message:n.message}),n;throw this.logger?.error?.(`[PowensOpenBankingProvider] ${e} failed with unexpected error`,n),n instanceof Error?n:Error(`Powens operation "${e}" failed`)}}export{m as PowensOpenBankingProvider};