@wopr-network/platform-core 1.62.0 → 1.63.1

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.
@@ -47,5 +47,5 @@ export declare class EvmWatcher {
47
47
  poll(): Promise<void>;
48
48
  }
49
49
  /** Create an RPC caller for a given URL (plain JSON-RPC over fetch). */
50
- export declare function createRpcCaller(rpcUrl: string): RpcCall;
50
+ export declare function createRpcCaller(rpcUrl: string, extraHeaders?: Record<string, string>): RpcCall;
51
51
  export {};
@@ -133,12 +133,23 @@ export class EvmWatcher {
133
133
  }
134
134
  }
135
135
  /** Create an RPC caller for a given URL (plain JSON-RPC over fetch). */
136
- export function createRpcCaller(rpcUrl) {
136
+ export function createRpcCaller(rpcUrl, extraHeaders) {
137
137
  let id = 0;
138
+ // Extract apikey query param and pass as TRON-PRO-API-KEY header (TronGrid JSON-RPC ignores query params)
139
+ const headers = { "Content-Type": "application/json", ...extraHeaders };
140
+ try {
141
+ const url = new URL(rpcUrl);
142
+ const apiKey = url.searchParams.get("apikey");
143
+ if (apiKey)
144
+ headers["TRON-PRO-API-KEY"] = apiKey;
145
+ }
146
+ catch {
147
+ // Not a valid URL — proceed without extra headers
148
+ }
138
149
  return async (method, params) => {
139
150
  const res = await fetch(rpcUrl, {
140
151
  method: "POST",
141
- headers: { "Content-Type": "application/json" },
152
+ headers,
142
153
  body: JSON.stringify({ jsonrpc: "2.0", id: ++id, method, params }),
143
154
  });
144
155
  if (!res.ok)
@@ -48,7 +48,20 @@ export declare class EmailClient {
48
48
  /** Send a transactional email. */
49
49
  send(opts: SendTemplateEmailOpts): Promise<EmailSendResult>;
50
50
  }
51
- export declare function getEmailClient(): EmailClient;
51
+ export interface EmailClientOverrides {
52
+ /** Sender address — overrides EMAIL_FROM env var. */
53
+ from?: string;
54
+ /** Reply-to address — overrides EMAIL_REPLY_TO env var. */
55
+ replyTo?: string;
56
+ }
57
+ /**
58
+ * Create a lazily-initialized singleton EmailClient.
59
+ *
60
+ * Optional overrides (from DB-driven product config) take precedence
61
+ * over env vars. Pass them on first call; subsequent calls return the
62
+ * cached singleton.
63
+ */
64
+ export declare function getEmailClient(overrides?: EmailClientOverrides): EmailClient;
52
65
  /** Reset the singleton (for testing). */
53
66
  export declare function resetEmailClient(): void;
54
67
  /** Replace the singleton (for testing). */
@@ -117,10 +117,17 @@ class ResendTransport {
117
117
  * - RESEND_REPLY_TO → falls back if EMAIL_REPLY_TO is not set
118
118
  */
119
119
  let _client = null;
120
- export function getEmailClient() {
120
+ /**
121
+ * Create a lazily-initialized singleton EmailClient.
122
+ *
123
+ * Optional overrides (from DB-driven product config) take precedence
124
+ * over env vars. Pass them on first call; subsequent calls return the
125
+ * cached singleton.
126
+ */
127
+ export function getEmailClient(overrides) {
121
128
  if (!_client) {
122
- const from = process.env.EMAIL_FROM || process.env.RESEND_FROM || "noreply@wopr.bot";
123
- const replyTo = process.env.EMAIL_REPLY_TO || process.env.RESEND_REPLY_TO || "support@wopr.bot";
129
+ const from = overrides?.from || process.env.EMAIL_FROM || process.env.RESEND_FROM || "noreply@wopr.bot";
130
+ const replyTo = overrides?.replyTo || process.env.EMAIL_REPLY_TO || process.env.RESEND_REPLY_TO || "support@wopr.bot";
124
131
  const sesRegion = process.env.AWS_SES_REGION;
125
132
  if (sesRegion) {
126
133
  const transport = new SesTransport({
@@ -10,7 +10,7 @@
10
10
  */
11
11
  export type { BillingEmailServiceConfig, BillingEmailType } from "./billing-emails.js";
12
12
  export { BillingEmailService } from "./billing-emails.js";
13
- export type { EmailClientConfig, EmailSendResult, SendTemplateEmailOpts } from "./client.js";
13
+ export type { EmailClientConfig, EmailClientOverrides, EmailSendResult, SendTemplateEmailOpts } from "./client.js";
14
14
  export { EmailClient, getEmailClient, resetEmailClient, setEmailClient } from "./client.js";
15
15
  export { DEFAULT_TEMPLATES } from "./default-templates.js";
16
16
  export type { IBillingEmailRepository } from "./drizzle-billing-email-repository.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wopr-network/platform-core",
3
- "version": "1.62.0",
3
+ "version": "1.63.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -180,12 +180,21 @@ export class EvmWatcher {
180
180
  }
181
181
 
182
182
  /** Create an RPC caller for a given URL (plain JSON-RPC over fetch). */
183
- export function createRpcCaller(rpcUrl: string): RpcCall {
183
+ export function createRpcCaller(rpcUrl: string, extraHeaders?: Record<string, string>): RpcCall {
184
184
  let id = 0;
185
+ // Extract apikey query param and pass as TRON-PRO-API-KEY header (TronGrid JSON-RPC ignores query params)
186
+ const headers: Record<string, string> = { "Content-Type": "application/json", ...extraHeaders };
187
+ try {
188
+ const url = new URL(rpcUrl);
189
+ const apiKey = url.searchParams.get("apikey");
190
+ if (apiKey) headers["TRON-PRO-API-KEY"] = apiKey;
191
+ } catch {
192
+ // Not a valid URL — proceed without extra headers
193
+ }
185
194
  return async (method: string, params: unknown[]): Promise<unknown> => {
186
195
  const res = await fetch(rpcUrl, {
187
196
  method: "POST",
188
- headers: { "Content-Type": "application/json" },
197
+ headers,
189
198
  body: JSON.stringify({ jsonrpc: "2.0", id: ++id, method, params }),
190
199
  });
191
200
  if (!res.ok) throw new Error(`RPC ${method} failed: ${res.status}`);
@@ -158,10 +158,25 @@ class ResendTransport implements EmailTransport {
158
158
  */
159
159
  let _client: EmailClient | null = null;
160
160
 
161
- export function getEmailClient(): EmailClient {
161
+ export interface EmailClientOverrides {
162
+ /** Sender address — overrides EMAIL_FROM env var. */
163
+ from?: string;
164
+ /** Reply-to address — overrides EMAIL_REPLY_TO env var. */
165
+ replyTo?: string;
166
+ }
167
+
168
+ /**
169
+ * Create a lazily-initialized singleton EmailClient.
170
+ *
171
+ * Optional overrides (from DB-driven product config) take precedence
172
+ * over env vars. Pass them on first call; subsequent calls return the
173
+ * cached singleton.
174
+ */
175
+ export function getEmailClient(overrides?: EmailClientOverrides): EmailClient {
162
176
  if (!_client) {
163
- const from = process.env.EMAIL_FROM || process.env.RESEND_FROM || "noreply@wopr.bot";
164
- const replyTo = process.env.EMAIL_REPLY_TO || process.env.RESEND_REPLY_TO || "support@wopr.bot";
177
+ const from = overrides?.from || process.env.EMAIL_FROM || process.env.RESEND_FROM || "noreply@wopr.bot";
178
+ const replyTo =
179
+ overrides?.replyTo || process.env.EMAIL_REPLY_TO || process.env.RESEND_REPLY_TO || "support@wopr.bot";
165
180
 
166
181
  const sesRegion = process.env.AWS_SES_REGION;
167
182
  if (sesRegion) {
@@ -11,7 +11,7 @@
11
11
 
12
12
  export type { BillingEmailServiceConfig, BillingEmailType } from "./billing-emails.js";
13
13
  export { BillingEmailService } from "./billing-emails.js";
14
- export type { EmailClientConfig, EmailSendResult, SendTemplateEmailOpts } from "./client.js";
14
+ export type { EmailClientConfig, EmailClientOverrides, EmailSendResult, SendTemplateEmailOpts } from "./client.js";
15
15
  export { EmailClient, getEmailClient, resetEmailClient, setEmailClient } from "./client.js";
16
16
  export { DEFAULT_TEMPLATES } from "./default-templates.js";
17
17
  export type { IBillingEmailRepository } from "./drizzle-billing-email-repository.js";