@burdenoff/be-sdk 2026.1110.3 → 2026.1110.4
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/activity/index.d.ts +165 -0
- package/dist/activity/index.js +389 -0
- package/dist/activity/index.js.map +1 -0
- package/dist/ai-credits/index.js +1 -1
- package/dist/{ai-credits-Ca-NNcVx.js → ai-credits-xxfwGpHS.js} +2 -2
- package/dist/{ai-credits-Ca-NNcVx.js.map → ai-credits-xxfwGpHS.js.map} +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +1 -1
- package/dist/{auth-CEuBEBQN.js → auth-C5ctwSLp.js} +2 -2
- package/dist/{auth-CEuBEBQN.js.map → auth-C5ctwSLp.js.map} +1 -1
- package/dist/bootstrap/index.d.ts +74 -0
- package/dist/bootstrap/index.js +282 -0
- package/dist/bootstrap/index.js.map +1 -0
- package/dist/{client-DcZ3iGES.js → client-sAJTrb4i.js} +2 -2
- package/dist/{client-DcZ3iGES.js.map → client-sAJTrb4i.js.map} +1 -1
- package/dist/context/index.d.ts +35 -0
- package/dist/{context-CZnXf2yb.js → context/index.js} +38 -2
- package/dist/context/index.js.map +1 -0
- package/dist/database/index.js +1 -1
- package/dist/event-queue/index.d.ts +1 -1
- package/dist/explicit-activity-scope-DikJ7NAE.js +57 -0
- package/dist/explicit-activity-scope-DikJ7NAE.js.map +1 -0
- package/dist/export/index.js +1 -1
- package/dist/{export-B6fphx8a.js → export-DJXE3Osa.js} +3 -3
- package/dist/{export-B6fphx8a.js.map → export-DJXE3Osa.js.map} +1 -1
- package/dist/feature-flags/index.js +1 -1
- package/dist/{feature-flags-71oDkrUe.js → feature-flags-CP1KRgwD.js} +2 -2
- package/dist/{feature-flags-71oDkrUe.js.map → feature-flags-CP1KRgwD.js.map} +1 -1
- package/dist/files/index.js +1 -1
- package/dist/{files-DjH0099H.js → files-h5U-D2AF.js} +2 -2
- package/dist/{files-DjH0099H.js.map → files-h5U-D2AF.js.map} +1 -1
- package/dist/gateway/index.js +2 -2
- package/dist/{gateway-DBFmxWks.js → gateway-ByVo-n37.js} +2 -2
- package/dist/{gateway-DBFmxWks.js.map → gateway-ByVo-n37.js.map} +1 -1
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/index.js +1 -1
- package/dist/{graph-DDYgIryR.js → graph-CR7u4lpl.js} +2 -2
- package/dist/{graph-DDYgIryR.js.map → graph-CR7u4lpl.js.map} +1 -1
- package/dist/{graphql-DNkMkGBZ.d.ts → graphql-CUDyhibV.d.ts} +1 -1
- package/dist/{index-bZKZUvBu.d.ts → index-ADmsX0BI.d.ts} +3 -3
- package/dist/{index-BqYfCQSP.d.ts → index-B2LCaK0R.d.ts} +1 -1
- package/dist/{index-D6UeLAye.d.ts → index-CHwMhK6v.d.ts} +2 -2
- package/dist/{index-BQDsNAMR.d.ts → index-CTTwo9av.d.ts} +22 -1
- package/dist/{index-DZC-2o9R.d.ts → index-CVCyKzhB.d.ts} +2 -2
- package/dist/{index-CkT2aUr3.d.ts → index-C_GXXF32.d.ts} +2 -2
- package/dist/{index-BKwHQtHQ.d.ts → index-Cot73bdh.d.ts} +1 -1
- package/dist/{index-CnzbJZP7.d.ts → index-FRRaa6h2.d.ts} +2 -2
- package/dist/{index-N-huORcj.d.ts → index-U_tu3zUl.d.ts} +2 -2
- package/dist/index-cmR9k9ga.d.ts +26 -0
- package/dist/{index-CZTnQIRU.d.ts → index-zd_NPGJo.d.ts} +6 -141
- package/dist/index.d.ts +19 -479
- package/dist/index.js +22 -1492
- package/dist/index.js.map +1 -1
- package/dist/init/index.js +1 -1
- package/dist/{init-Dy3KhT6Y.js → init-CQPFmOOe.js} +3 -3
- package/dist/{init-Dy3KhT6Y.js.map → init-CQPFmOOe.js.map} +1 -1
- package/dist/instrumentation/index.d.ts +2 -2
- package/dist/logger/index.d.ts +1 -1
- package/dist/notifications/index.d.ts +1 -1
- package/dist/notifications/index.js +1 -1
- package/dist/{notifications-CdETrtFK.js → notifications-DY_i37WN.js} +2 -2
- package/dist/{notifications-CdETrtFK.js.map → notifications-DY_i37WN.js.map} +1 -1
- package/dist/payments/index.d.ts +144 -0
- package/dist/payments/index.js +404 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/rate-limit-CBrK_U5H.js +142 -0
- package/dist/rate-limit-CBrK_U5H.js.map +1 -0
- package/dist/rbac/index.d.ts +1 -1
- package/dist/rbac/index.js +1 -1
- package/dist/{rbac-BB9l9Xph.js → rbac-Dvz0YzEt.js} +2 -2
- package/dist/{rbac-BB9l9Xph.js.map → rbac-Dvz0YzEt.js.map} +1 -1
- package/dist/resource-caps/index.d.ts +1 -1
- package/dist/search/index.d.ts +112 -0
- package/dist/search/index.js +266 -0
- package/dist/search/index.js.map +1 -0
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.js +4 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/rate-limit/index.d.ts +2 -0
- package/dist/security/rate-limit/index.js +4 -0
- package/dist/security/rate-limit/index.js.map +1 -0
- package/dist/server/index.js +3 -2
- package/dist/server/index.js.map +1 -1
- package/dist/{stub-BqwKn4eh.js → stub-BUnfMiAS.js} +3 -56
- package/dist/stub-BUnfMiAS.js.map +1 -0
- package/dist/tags/index.js +1 -1
- package/dist/{tags-B5xpbgsk.js → tags-CbijgoqR.js} +2 -2
- package/dist/{tags-B5xpbgsk.js.map → tags-CbijgoqR.js.map} +1 -1
- package/dist/telemetry/index.d.ts +2 -2
- package/dist/tracker/index.d.ts +2 -2
- package/dist/tracker/index.js +5 -3
- package/dist/{tracker-BQVoEFUo.js → tracker-PQztSlhJ.js} +9 -390
- package/dist/tracker-PQztSlhJ.js.map +1 -0
- package/dist/translation/index.d.ts +120 -0
- package/dist/translation/index.js +573 -0
- package/dist/translation/index.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/{types-Cj2RWXbz.js → types/index.js} +3 -3
- package/dist/types/index.js.map +1 -0
- package/dist/usage/index.d.ts +1 -1
- package/dist/usage/index.js +1 -1
- package/dist/{usage-BKFZiWQn.js → usage-BRqVP3CJ.js} +4 -4
- package/dist/{usage-BKFZiWQn.js.map → usage-BRqVP3CJ.js.map} +1 -1
- package/package.json +1 -1
- package/dist/context-CZnXf2yb.js.map +0 -1
- package/dist/stub-BqwKn4eh.js.map +0 -1
- package/dist/tracker-BQVoEFUo.js.map +0 -1
- package/dist/types-Cj2RWXbz.js.map +0 -1
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { ValidationError } from "../types/index.js";
|
|
2
|
+
import { a as logger } from "../logger-B6rCpb7D.js";
|
|
3
|
+
|
|
4
|
+
// src/payments/index.ts
|
|
5
|
+
let PaymentStatus = /* @__PURE__ */ function(PaymentStatus) {
|
|
6
|
+
PaymentStatus["PENDING"] = "pending";
|
|
7
|
+
PaymentStatus["PROCESSING"] = "processing";
|
|
8
|
+
PaymentStatus["SUCCEEDED"] = "succeeded";
|
|
9
|
+
PaymentStatus["FAILED"] = "failed";
|
|
10
|
+
PaymentStatus["CANCELLED"] = "cancelled";
|
|
11
|
+
PaymentStatus["REFUNDED"] = "refunded";
|
|
12
|
+
return PaymentStatus;
|
|
13
|
+
}({});
|
|
14
|
+
let PaymentMethod = /* @__PURE__ */ function(PaymentMethod) {
|
|
15
|
+
PaymentMethod["CREDIT_CARD"] = "credit_card";
|
|
16
|
+
PaymentMethod["DEBIT_CARD"] = "debit_card";
|
|
17
|
+
PaymentMethod["BANK_TRANSFER"] = "bank_transfer";
|
|
18
|
+
PaymentMethod["UPI"] = "upi";
|
|
19
|
+
PaymentMethod["WALLET"] = "wallet";
|
|
20
|
+
PaymentMethod["PAYPAL"] = "paypal";
|
|
21
|
+
PaymentMethod["STRIPE"] = "stripe";
|
|
22
|
+
return PaymentMethod;
|
|
23
|
+
}({});
|
|
24
|
+
let SubscriptionStatus = /* @__PURE__ */ function(SubscriptionStatus) {
|
|
25
|
+
SubscriptionStatus["ACTIVE"] = "active";
|
|
26
|
+
SubscriptionStatus["INACTIVE"] = "inactive";
|
|
27
|
+
SubscriptionStatus["CANCELLED"] = "cancelled";
|
|
28
|
+
SubscriptionStatus["EXPIRED"] = "expired";
|
|
29
|
+
SubscriptionStatus["PAST_DUE"] = "past_due";
|
|
30
|
+
SubscriptionStatus["TRIALING"] = "trialing";
|
|
31
|
+
return SubscriptionStatus;
|
|
32
|
+
}({});
|
|
33
|
+
/**
|
|
34
|
+
* Payments Module
|
|
35
|
+
*/
|
|
36
|
+
var PaymentsModule = class {
|
|
37
|
+
client;
|
|
38
|
+
context;
|
|
39
|
+
constructor(client, context) {
|
|
40
|
+
this.client = client;
|
|
41
|
+
this.context = context;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create payment
|
|
45
|
+
*/
|
|
46
|
+
async createPayment(options) {
|
|
47
|
+
if (typeof options.amount !== "number" || options.amount <= 0) throw new ValidationError("Amount must be a positive number");
|
|
48
|
+
if (!options.currency) throw new ValidationError("Currency is required");
|
|
49
|
+
if (!options.paymentMethod) throw new ValidationError("Payment method is required");
|
|
50
|
+
if (!options.customerId) throw new ValidationError("Customer ID is required");
|
|
51
|
+
logger.debug("[Payments] Creating payment", {
|
|
52
|
+
amount: options.amount,
|
|
53
|
+
currency: options.currency,
|
|
54
|
+
customerId: options.customerId
|
|
55
|
+
});
|
|
56
|
+
const mutation = `
|
|
57
|
+
mutation CreatePayment($input: CreatePaymentInput!) {
|
|
58
|
+
createPayment(input: $input) {
|
|
59
|
+
id
|
|
60
|
+
amount
|
|
61
|
+
currency
|
|
62
|
+
status
|
|
63
|
+
paymentMethod
|
|
64
|
+
customerId
|
|
65
|
+
description
|
|
66
|
+
metadata
|
|
67
|
+
workspaceId
|
|
68
|
+
organizationId
|
|
69
|
+
transactionId
|
|
70
|
+
failureReason
|
|
71
|
+
createdAt
|
|
72
|
+
updatedAt
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
`;
|
|
76
|
+
const variables = { input: {
|
|
77
|
+
amount: options.amount,
|
|
78
|
+
currency: options.currency,
|
|
79
|
+
paymentMethod: options.paymentMethod,
|
|
80
|
+
customerId: options.customerId,
|
|
81
|
+
description: options.description,
|
|
82
|
+
metadata: options.metadata,
|
|
83
|
+
workspaceId: options.workspaceId || this.context.workspaceId,
|
|
84
|
+
organizationId: options.organizationId
|
|
85
|
+
} };
|
|
86
|
+
const response = await this.client.query(mutation, variables, this.context);
|
|
87
|
+
logger.info("[Payments] Payment created", { paymentId: response.createPayment.id });
|
|
88
|
+
return response.createPayment;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get payment by ID
|
|
92
|
+
*/
|
|
93
|
+
async getPayment(paymentId) {
|
|
94
|
+
logger.debug("[Payments] Getting payment", { paymentId });
|
|
95
|
+
return (await this.client.query(`
|
|
96
|
+
query GetPayment($paymentId: ID!) {
|
|
97
|
+
getPayment(paymentId: $paymentId) {
|
|
98
|
+
id
|
|
99
|
+
amount
|
|
100
|
+
currency
|
|
101
|
+
status
|
|
102
|
+
paymentMethod
|
|
103
|
+
customerId
|
|
104
|
+
description
|
|
105
|
+
metadata
|
|
106
|
+
workspaceId
|
|
107
|
+
organizationId
|
|
108
|
+
transactionId
|
|
109
|
+
failureReason
|
|
110
|
+
createdAt
|
|
111
|
+
updatedAt
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
`, { paymentId }, this.context)).getPayment;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get payments with filters
|
|
118
|
+
*/
|
|
119
|
+
async getPayments(options) {
|
|
120
|
+
logger.debug("[Payments] Getting payments", options);
|
|
121
|
+
const query = `
|
|
122
|
+
query GetPayments(
|
|
123
|
+
$customerId: ID
|
|
124
|
+
$status: PaymentStatus
|
|
125
|
+
$workspaceId: ID
|
|
126
|
+
$organizationId: ID
|
|
127
|
+
$startDate: DateTime
|
|
128
|
+
$endDate: DateTime
|
|
129
|
+
$limit: Int
|
|
130
|
+
$offset: Int
|
|
131
|
+
) {
|
|
132
|
+
getPayments(
|
|
133
|
+
customerId: $customerId
|
|
134
|
+
status: $status
|
|
135
|
+
workspaceId: $workspaceId
|
|
136
|
+
organizationId: $organizationId
|
|
137
|
+
startDate: $startDate
|
|
138
|
+
endDate: $endDate
|
|
139
|
+
limit: $limit
|
|
140
|
+
offset: $offset
|
|
141
|
+
) {
|
|
142
|
+
payments {
|
|
143
|
+
id
|
|
144
|
+
amount
|
|
145
|
+
currency
|
|
146
|
+
status
|
|
147
|
+
paymentMethod
|
|
148
|
+
customerId
|
|
149
|
+
description
|
|
150
|
+
transactionId
|
|
151
|
+
createdAt
|
|
152
|
+
updatedAt
|
|
153
|
+
}
|
|
154
|
+
total
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
`;
|
|
158
|
+
const variables = {
|
|
159
|
+
customerId: options.customerId,
|
|
160
|
+
status: options.status,
|
|
161
|
+
workspaceId: options.workspaceId || this.context.workspaceId,
|
|
162
|
+
organizationId: options.organizationId,
|
|
163
|
+
startDate: options.startDate,
|
|
164
|
+
endDate: options.endDate,
|
|
165
|
+
limit: options.limit || 50,
|
|
166
|
+
offset: options.offset || 0
|
|
167
|
+
};
|
|
168
|
+
return (await this.client.query(query, variables, this.context)).getPayments;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Refund payment
|
|
172
|
+
*/
|
|
173
|
+
async refundPayment(paymentId, amount, reason) {
|
|
174
|
+
logger.debug("[Payments] Refunding payment", {
|
|
175
|
+
paymentId,
|
|
176
|
+
amount
|
|
177
|
+
});
|
|
178
|
+
const response = await this.client.query(`
|
|
179
|
+
mutation RefundPayment($paymentId: ID!, $amount: Int, $reason: String) {
|
|
180
|
+
refundPayment(paymentId: $paymentId, amount: $amount, reason: $reason) {
|
|
181
|
+
id
|
|
182
|
+
amount
|
|
183
|
+
currency
|
|
184
|
+
status
|
|
185
|
+
paymentMethod
|
|
186
|
+
customerId
|
|
187
|
+
failureReason
|
|
188
|
+
updatedAt
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
`, {
|
|
192
|
+
paymentId,
|
|
193
|
+
amount,
|
|
194
|
+
reason
|
|
195
|
+
}, this.context);
|
|
196
|
+
logger.info("[Payments] Payment refunded", { paymentId });
|
|
197
|
+
return response.refundPayment;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Verify payment
|
|
201
|
+
*/
|
|
202
|
+
async verifyPayment(paymentId, verificationData) {
|
|
203
|
+
logger.debug("[Payments] Verifying payment", { paymentId });
|
|
204
|
+
const response = await this.client.query(`
|
|
205
|
+
mutation VerifyPayment($paymentId: ID!, $verificationData: JSON!) {
|
|
206
|
+
verifyPayment(paymentId: $paymentId, verificationData: $verificationData) {
|
|
207
|
+
verified
|
|
208
|
+
status
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
`, {
|
|
212
|
+
paymentId,
|
|
213
|
+
verificationData
|
|
214
|
+
}, this.context);
|
|
215
|
+
logger.info("[Payments] Payment verified", {
|
|
216
|
+
paymentId,
|
|
217
|
+
verified: response.verifyPayment.verified
|
|
218
|
+
});
|
|
219
|
+
return response.verifyPayment;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Create subscription
|
|
223
|
+
*/
|
|
224
|
+
async createSubscription(options) {
|
|
225
|
+
if (!options.customerId) throw new ValidationError("Customer ID is required");
|
|
226
|
+
if (!options.planId) throw new ValidationError("Plan ID is required");
|
|
227
|
+
if (!options.paymentMethod) throw new ValidationError("Payment method is required");
|
|
228
|
+
logger.debug("[Payments] Creating subscription", {
|
|
229
|
+
customerId: options.customerId,
|
|
230
|
+
planId: options.planId
|
|
231
|
+
});
|
|
232
|
+
const mutation = `
|
|
233
|
+
mutation CreateSubscription($input: CreateSubscriptionInput!) {
|
|
234
|
+
createSubscription(input: $input) {
|
|
235
|
+
id
|
|
236
|
+
customerId
|
|
237
|
+
planId
|
|
238
|
+
status
|
|
239
|
+
currentPeriodStart
|
|
240
|
+
currentPeriodEnd
|
|
241
|
+
trialEnd
|
|
242
|
+
cancelledAt
|
|
243
|
+
endedAt
|
|
244
|
+
metadata
|
|
245
|
+
workspaceId
|
|
246
|
+
organizationId
|
|
247
|
+
createdAt
|
|
248
|
+
updatedAt
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
`;
|
|
252
|
+
const variables = { input: {
|
|
253
|
+
customerId: options.customerId,
|
|
254
|
+
planId: options.planId,
|
|
255
|
+
paymentMethod: options.paymentMethod,
|
|
256
|
+
trialDays: options.trialDays,
|
|
257
|
+
metadata: options.metadata,
|
|
258
|
+
workspaceId: options.workspaceId || this.context.workspaceId,
|
|
259
|
+
organizationId: options.organizationId
|
|
260
|
+
} };
|
|
261
|
+
const response = await this.client.query(mutation, variables, this.context);
|
|
262
|
+
logger.info("[Payments] Subscription created", { subscriptionId: response.createSubscription.id });
|
|
263
|
+
return response.createSubscription;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get subscription
|
|
267
|
+
*/
|
|
268
|
+
async getSubscription(subscriptionId) {
|
|
269
|
+
logger.debug("[Payments] Getting subscription", { subscriptionId });
|
|
270
|
+
return (await this.client.query(`
|
|
271
|
+
query GetSubscription($subscriptionId: ID!) {
|
|
272
|
+
getSubscription(subscriptionId: $subscriptionId) {
|
|
273
|
+
id
|
|
274
|
+
customerId
|
|
275
|
+
planId
|
|
276
|
+
status
|
|
277
|
+
currentPeriodStart
|
|
278
|
+
currentPeriodEnd
|
|
279
|
+
trialEnd
|
|
280
|
+
cancelledAt
|
|
281
|
+
endedAt
|
|
282
|
+
metadata
|
|
283
|
+
workspaceId
|
|
284
|
+
organizationId
|
|
285
|
+
createdAt
|
|
286
|
+
updatedAt
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
`, { subscriptionId }, this.context)).getSubscription;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Cancel subscription
|
|
293
|
+
*/
|
|
294
|
+
async cancelSubscription(subscriptionId, cancelAtPeriodEnd = false) {
|
|
295
|
+
logger.debug("[Payments] Cancelling subscription", {
|
|
296
|
+
subscriptionId,
|
|
297
|
+
cancelAtPeriodEnd
|
|
298
|
+
});
|
|
299
|
+
const response = await this.client.query(`
|
|
300
|
+
mutation CancelSubscription($subscriptionId: ID!, $cancelAtPeriodEnd: Boolean!) {
|
|
301
|
+
cancelSubscription(subscriptionId: $subscriptionId, cancelAtPeriodEnd: $cancelAtPeriodEnd) {
|
|
302
|
+
id
|
|
303
|
+
status
|
|
304
|
+
cancelledAt
|
|
305
|
+
endedAt
|
|
306
|
+
updatedAt
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
`, {
|
|
310
|
+
subscriptionId,
|
|
311
|
+
cancelAtPeriodEnd
|
|
312
|
+
}, this.context);
|
|
313
|
+
logger.info("[Payments] Subscription cancelled", { subscriptionId });
|
|
314
|
+
return response.cancelSubscription;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Get customer subscriptions
|
|
318
|
+
*/
|
|
319
|
+
async getCustomerSubscriptions(customerId) {
|
|
320
|
+
logger.debug("[Payments] Getting customer subscriptions", { customerId });
|
|
321
|
+
return (await this.client.query(`
|
|
322
|
+
query GetCustomerSubscriptions($customerId: ID!) {
|
|
323
|
+
getCustomerSubscriptions(customerId: $customerId) {
|
|
324
|
+
id
|
|
325
|
+
customerId
|
|
326
|
+
planId
|
|
327
|
+
status
|
|
328
|
+
currentPeriodStart
|
|
329
|
+
currentPeriodEnd
|
|
330
|
+
trialEnd
|
|
331
|
+
cancelledAt
|
|
332
|
+
createdAt
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
`, { customerId }, this.context)).getCustomerSubscriptions;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Get plans
|
|
339
|
+
*/
|
|
340
|
+
async getPlans(activeOnly = true) {
|
|
341
|
+
logger.debug("[Payments] Getting plans", { activeOnly });
|
|
342
|
+
return (await this.client.query(`
|
|
343
|
+
query GetPlans($activeOnly: Boolean!) {
|
|
344
|
+
getPlans(activeOnly: $activeOnly) {
|
|
345
|
+
id
|
|
346
|
+
name
|
|
347
|
+
description
|
|
348
|
+
amount
|
|
349
|
+
currency
|
|
350
|
+
interval
|
|
351
|
+
intervalCount
|
|
352
|
+
features
|
|
353
|
+
metadata
|
|
354
|
+
active
|
|
355
|
+
createdAt
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
`, { activeOnly }, this.context)).getPlans;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Create payment intent
|
|
362
|
+
*/
|
|
363
|
+
async createPaymentIntent(options) {
|
|
364
|
+
logger.debug("[Payments] Creating payment intent", {
|
|
365
|
+
amount: options.amount,
|
|
366
|
+
currency: options.currency
|
|
367
|
+
});
|
|
368
|
+
const response = await this.client.query(`
|
|
369
|
+
mutation CreatePaymentIntent($input: CreatePaymentIntentInput!) {
|
|
370
|
+
createPaymentIntent(input: $input) {
|
|
371
|
+
clientSecret
|
|
372
|
+
paymentIntentId
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
`, { input: options }, this.context);
|
|
376
|
+
logger.info("[Payments] Payment intent created", { paymentIntentId: response.createPaymentIntent.paymentIntentId });
|
|
377
|
+
return response.createPaymentIntent;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Get payment statistics
|
|
381
|
+
*/
|
|
382
|
+
async getPaymentStats(options) {
|
|
383
|
+
logger.debug("[Payments] Getting payment statistics", options);
|
|
384
|
+
return (await this.client.query(`
|
|
385
|
+
query GetPaymentStats($startDate: DateTime, $endDate: DateTime, $workspaceId: ID) {
|
|
386
|
+
getPaymentStats(startDate: $startDate, endDate: $endDate, workspaceId: $workspaceId) {
|
|
387
|
+
totalRevenue
|
|
388
|
+
totalPayments
|
|
389
|
+
successfulPayments
|
|
390
|
+
failedPayments
|
|
391
|
+
refundedAmount
|
|
392
|
+
averagePaymentAmount
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
`, {
|
|
396
|
+
startDate: options?.startDate,
|
|
397
|
+
endDate: options?.endDate,
|
|
398
|
+
workspaceId: options?.workspaceId || this.context.workspaceId
|
|
399
|
+
}, this.context)).getPaymentStats;
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
export { PaymentMethod, PaymentStatus, PaymentsModule, SubscriptionStatus };
|
|
404
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/payments/index.ts"],"sourcesContent":["/**\n * Payments Module\n * Helpers for managing payments, subscriptions, and verification\n */\n\nimport type { BurdenoffGraphQLClient } from '../client/graphql.js';\nimport type { SDKContext } from '../types/index.js';\nimport { ValidationError } from '../types/index.js';\nimport { logger } from '../logger/index.js';\n\nexport enum PaymentStatus {\n PENDING = 'pending',\n PROCESSING = 'processing',\n SUCCEEDED = 'succeeded',\n FAILED = 'failed',\n CANCELLED = 'cancelled',\n REFUNDED = 'refunded',\n}\n\nexport enum PaymentMethod {\n CREDIT_CARD = 'credit_card',\n DEBIT_CARD = 'debit_card',\n BANK_TRANSFER = 'bank_transfer',\n UPI = 'upi',\n WALLET = 'wallet',\n PAYPAL = 'paypal',\n STRIPE = 'stripe',\n}\n\nexport enum SubscriptionStatus {\n ACTIVE = 'active',\n INACTIVE = 'inactive',\n CANCELLED = 'cancelled',\n EXPIRED = 'expired',\n PAST_DUE = 'past_due',\n TRIALING = 'trialing',\n}\n\nexport interface CreatePaymentOptions {\n /** Amount in smallest currency unit (e.g., cents) */\n amount: number;\n /** Currency code (e.g., USD, EUR, INR) */\n currency: string;\n /** Payment method */\n paymentMethod: PaymentMethod;\n /** Customer ID */\n customerId: string;\n /** Description */\n description?: string;\n /** Metadata */\n metadata?: Record<string, unknown>;\n /** Workspace context */\n workspaceId?: string;\n /** Organization context */\n organizationId?: string;\n}\n\nexport interface Payment {\n id: string;\n amount: number;\n currency: string;\n status: PaymentStatus;\n paymentMethod: PaymentMethod;\n customerId: string;\n description?: string;\n metadata?: Record<string, unknown>;\n workspaceId?: string;\n organizationId?: string;\n transactionId?: string;\n failureReason?: string;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface CreateSubscriptionOptions {\n /** Customer ID */\n customerId: string;\n /** Plan ID */\n planId: string;\n /** Payment method */\n paymentMethod: PaymentMethod;\n /** Trial period in days */\n trialDays?: number;\n /** Metadata */\n metadata?: Record<string, unknown>;\n /** Workspace context */\n workspaceId?: string;\n /** Organization context */\n organizationId?: string;\n}\n\nexport interface Subscription {\n id: string;\n customerId: string;\n planId: string;\n status: SubscriptionStatus;\n currentPeriodStart: string;\n currentPeriodEnd: string;\n trialEnd?: string;\n cancelledAt?: string;\n endedAt?: string;\n metadata?: Record<string, unknown>;\n workspaceId?: string;\n organizationId?: string;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface Plan {\n id: string;\n name: string;\n description?: string;\n amount: number;\n currency: string;\n interval: 'day' | 'week' | 'month' | 'year';\n intervalCount: number;\n features?: string[];\n metadata?: Record<string, unknown>;\n active: boolean;\n createdAt: string;\n}\n\nexport interface GetPaymentsOptions {\n customerId?: string;\n status?: PaymentStatus;\n workspaceId?: string;\n organizationId?: string;\n startDate?: string;\n endDate?: string;\n limit?: number;\n offset?: number;\n}\n\n/**\n * Payments Module\n */\nexport class PaymentsModule {\n constructor(\n private client: BurdenoffGraphQLClient,\n private context: SDKContext\n ) {}\n\n /**\n * Create payment\n */\n public async createPayment(options: CreatePaymentOptions): Promise<Payment> {\n // Validate inputs\n if (typeof options.amount !== 'number' || options.amount <= 0) {\n throw new ValidationError('Amount must be a positive number');\n }\n\n if (!options.currency) {\n throw new ValidationError('Currency is required');\n }\n\n if (!options.paymentMethod) {\n throw new ValidationError('Payment method is required');\n }\n\n if (!options.customerId) {\n throw new ValidationError('Customer ID is required');\n }\n\n logger.debug('[Payments] Creating payment', {\n amount: options.amount,\n currency: options.currency,\n customerId: options.customerId,\n });\n\n const mutation = `\n mutation CreatePayment($input: CreatePaymentInput!) {\n createPayment(input: $input) {\n id\n amount\n currency\n status\n paymentMethod\n customerId\n description\n metadata\n workspaceId\n organizationId\n transactionId\n failureReason\n createdAt\n updatedAt\n }\n }\n `;\n\n const variables = {\n input: {\n amount: options.amount,\n currency: options.currency,\n paymentMethod: options.paymentMethod,\n customerId: options.customerId,\n description: options.description,\n metadata: options.metadata,\n workspaceId: options.workspaceId || this.context.workspaceId,\n organizationId: options.organizationId,\n },\n };\n\n const response = await this.client.query<{ createPayment: Payment }>(mutation, variables, this.context);\n\n logger.info('[Payments] Payment created', { paymentId: response.createPayment.id });\n\n return response.createPayment;\n }\n\n /**\n * Get payment by ID\n */\n public async getPayment(paymentId: string): Promise<Payment> {\n logger.debug('[Payments] Getting payment', { paymentId });\n\n const query = `\n query GetPayment($paymentId: ID!) {\n getPayment(paymentId: $paymentId) {\n id\n amount\n currency\n status\n paymentMethod\n customerId\n description\n metadata\n workspaceId\n organizationId\n transactionId\n failureReason\n createdAt\n updatedAt\n }\n }\n `;\n\n const response = await this.client.query<{ getPayment: Payment }>(query, { paymentId }, this.context);\n\n return response.getPayment;\n }\n\n /**\n * Get payments with filters\n */\n public async getPayments(options: GetPaymentsOptions): Promise<{\n payments: Payment[];\n total: number;\n }> {\n logger.debug('[Payments] Getting payments', options);\n\n const query = `\n query GetPayments(\n $customerId: ID\n $status: PaymentStatus\n $workspaceId: ID\n $organizationId: ID\n $startDate: DateTime\n $endDate: DateTime\n $limit: Int\n $offset: Int\n ) {\n getPayments(\n customerId: $customerId\n status: $status\n workspaceId: $workspaceId\n organizationId: $organizationId\n startDate: $startDate\n endDate: $endDate\n limit: $limit\n offset: $offset\n ) {\n payments {\n id\n amount\n currency\n status\n paymentMethod\n customerId\n description\n transactionId\n createdAt\n updatedAt\n }\n total\n }\n }\n `;\n\n const variables = {\n customerId: options.customerId,\n status: options.status,\n workspaceId: options.workspaceId || this.context.workspaceId,\n organizationId: options.organizationId,\n startDate: options.startDate,\n endDate: options.endDate,\n limit: options.limit || 50,\n offset: options.offset || 0,\n };\n\n const response = await this.client.query<{\n getPayments: {\n payments: Payment[];\n total: number;\n };\n }>(query, variables, this.context);\n\n return response.getPayments;\n }\n\n /**\n * Refund payment\n */\n public async refundPayment(paymentId: string, amount?: number, reason?: string): Promise<Payment> {\n logger.debug('[Payments] Refunding payment', { paymentId, amount });\n\n const mutation = `\n mutation RefundPayment($paymentId: ID!, $amount: Int, $reason: String) {\n refundPayment(paymentId: $paymentId, amount: $amount, reason: $reason) {\n id\n amount\n currency\n status\n paymentMethod\n customerId\n failureReason\n updatedAt\n }\n }\n `;\n\n const response = await this.client.query<{ refundPayment: Payment }>(\n mutation,\n { paymentId, amount, reason },\n this.context\n );\n\n logger.info('[Payments] Payment refunded', { paymentId });\n\n return response.refundPayment;\n }\n\n /**\n * Verify payment\n */\n public async verifyPayment(\n paymentId: string,\n verificationData: Record<string, unknown>\n ): Promise<{\n verified: boolean;\n status: PaymentStatus;\n }> {\n logger.debug('[Payments] Verifying payment', { paymentId });\n\n const mutation = `\n mutation VerifyPayment($paymentId: ID!, $verificationData: JSON!) {\n verifyPayment(paymentId: $paymentId, verificationData: $verificationData) {\n verified\n status\n }\n }\n `;\n\n const response = await this.client.query<{\n verifyPayment: {\n verified: boolean;\n status: PaymentStatus;\n };\n }>(mutation, { paymentId, verificationData }, this.context);\n\n logger.info('[Payments] Payment verified', {\n paymentId,\n verified: response.verifyPayment.verified,\n });\n\n return response.verifyPayment;\n }\n\n /**\n * Create subscription\n */\n public async createSubscription(options: CreateSubscriptionOptions): Promise<Subscription> {\n if (!options.customerId) {\n throw new ValidationError('Customer ID is required');\n }\n\n if (!options.planId) {\n throw new ValidationError('Plan ID is required');\n }\n\n if (!options.paymentMethod) {\n throw new ValidationError('Payment method is required');\n }\n\n logger.debug('[Payments] Creating subscription', {\n customerId: options.customerId,\n planId: options.planId,\n });\n\n const mutation = `\n mutation CreateSubscription($input: CreateSubscriptionInput!) {\n createSubscription(input: $input) {\n id\n customerId\n planId\n status\n currentPeriodStart\n currentPeriodEnd\n trialEnd\n cancelledAt\n endedAt\n metadata\n workspaceId\n organizationId\n createdAt\n updatedAt\n }\n }\n `;\n\n const variables = {\n input: {\n customerId: options.customerId,\n planId: options.planId,\n paymentMethod: options.paymentMethod,\n trialDays: options.trialDays,\n metadata: options.metadata,\n workspaceId: options.workspaceId || this.context.workspaceId,\n organizationId: options.organizationId,\n },\n };\n\n const response = await this.client.query<{ createSubscription: Subscription }>(mutation, variables, this.context);\n\n logger.info('[Payments] Subscription created', { subscriptionId: response.createSubscription.id });\n\n return response.createSubscription;\n }\n\n /**\n * Get subscription\n */\n public async getSubscription(subscriptionId: string): Promise<Subscription> {\n logger.debug('[Payments] Getting subscription', { subscriptionId });\n\n const query = `\n query GetSubscription($subscriptionId: ID!) {\n getSubscription(subscriptionId: $subscriptionId) {\n id\n customerId\n planId\n status\n currentPeriodStart\n currentPeriodEnd\n trialEnd\n cancelledAt\n endedAt\n metadata\n workspaceId\n organizationId\n createdAt\n updatedAt\n }\n }\n `;\n\n const response = await this.client.query<{ getSubscription: Subscription }>(\n query,\n { subscriptionId },\n this.context\n );\n\n return response.getSubscription;\n }\n\n /**\n * Cancel subscription\n */\n public async cancelSubscription(subscriptionId: string, cancelAtPeriodEnd = false): Promise<Subscription> {\n logger.debug('[Payments] Cancelling subscription', {\n subscriptionId,\n cancelAtPeriodEnd,\n });\n\n const mutation = `\n mutation CancelSubscription($subscriptionId: ID!, $cancelAtPeriodEnd: Boolean!) {\n cancelSubscription(subscriptionId: $subscriptionId, cancelAtPeriodEnd: $cancelAtPeriodEnd) {\n id\n status\n cancelledAt\n endedAt\n updatedAt\n }\n }\n `;\n\n const response = await this.client.query<{ cancelSubscription: Subscription }>(\n mutation,\n { subscriptionId, cancelAtPeriodEnd },\n this.context\n );\n\n logger.info('[Payments] Subscription cancelled', { subscriptionId });\n\n return response.cancelSubscription;\n }\n\n /**\n * Get customer subscriptions\n */\n public async getCustomerSubscriptions(customerId: string): Promise<Subscription[]> {\n logger.debug('[Payments] Getting customer subscriptions', { customerId });\n\n const query = `\n query GetCustomerSubscriptions($customerId: ID!) {\n getCustomerSubscriptions(customerId: $customerId) {\n id\n customerId\n planId\n status\n currentPeriodStart\n currentPeriodEnd\n trialEnd\n cancelledAt\n createdAt\n }\n }\n `;\n\n const response = await this.client.query<{ getCustomerSubscriptions: Subscription[] }>(\n query,\n { customerId },\n this.context\n );\n\n return response.getCustomerSubscriptions;\n }\n\n /**\n * Get plans\n */\n public async getPlans(activeOnly = true): Promise<Plan[]> {\n logger.debug('[Payments] Getting plans', { activeOnly });\n\n const query = `\n query GetPlans($activeOnly: Boolean!) {\n getPlans(activeOnly: $activeOnly) {\n id\n name\n description\n amount\n currency\n interval\n intervalCount\n features\n metadata\n active\n createdAt\n }\n }\n `;\n\n const response = await this.client.query<{ getPlans: Plan[] }>(query, { activeOnly }, this.context);\n\n return response.getPlans;\n }\n\n /**\n * Create payment intent\n */\n public async createPaymentIntent(options: {\n amount: number;\n currency: string;\n customerId: string;\n paymentMethod?: PaymentMethod;\n metadata?: Record<string, unknown>;\n }): Promise<{\n clientSecret: string;\n paymentIntentId: string;\n }> {\n logger.debug('[Payments] Creating payment intent', {\n amount: options.amount,\n currency: options.currency,\n });\n\n const mutation = `\n mutation CreatePaymentIntent($input: CreatePaymentIntentInput!) {\n createPaymentIntent(input: $input) {\n clientSecret\n paymentIntentId\n }\n }\n `;\n\n const response = await this.client.query<{\n createPaymentIntent: {\n clientSecret: string;\n paymentIntentId: string;\n };\n }>(mutation, { input: options }, this.context);\n\n logger.info('[Payments] Payment intent created', {\n paymentIntentId: response.createPaymentIntent.paymentIntentId,\n });\n\n return response.createPaymentIntent;\n }\n\n /**\n * Get payment statistics\n */\n public async getPaymentStats(options?: { startDate?: string; endDate?: string; workspaceId?: string }): Promise<{\n totalRevenue: number;\n totalPayments: number;\n successfulPayments: number;\n failedPayments: number;\n refundedAmount: number;\n averagePaymentAmount: number;\n }> {\n logger.debug('[Payments] Getting payment statistics', options);\n\n const query = `\n query GetPaymentStats($startDate: DateTime, $endDate: DateTime, $workspaceId: ID) {\n getPaymentStats(startDate: $startDate, endDate: $endDate, workspaceId: $workspaceId) {\n totalRevenue\n totalPayments\n successfulPayments\n failedPayments\n refundedAmount\n averagePaymentAmount\n }\n }\n `;\n\n const response = await this.client.query<{\n getPaymentStats: {\n totalRevenue: number;\n totalPayments: number;\n successfulPayments: number;\n failedPayments: number;\n refundedAmount: number;\n averagePaymentAmount: number;\n };\n }>(\n query,\n {\n startDate: options?.startDate,\n endDate: options?.endDate,\n workspaceId: options?.workspaceId || this.context.workspaceId,\n },\n this.context\n );\n\n return response.getPaymentStats;\n }\n}\n"],"mappings":";;;;AAUA,IAAY,gBAAL;CACL;CACA;CACA;CACA;CACA;CACA;;AACF;AAEA,IAAY,gBAAL;CACL;CACA;CACA;CACA;CACA;CACA;CACA;;AACF;AAEA,IAAY,qBAAL;CACL;CACA;CACA;CACA;CACA;CACA;;AACF;;;;AAoGA,IAAa,iBAAb,MAA4B;CAEhB;CACA;CAFV,YACE,AAAQ,QACR,AAAQ,SACR;EAFQ;EACA;CACP;;;;CAKH,MAAa,cAAc,SAAiD;EAE1E,IAAI,OAAO,QAAQ,WAAW,YAAY,QAAQ,UAAU,GAC1D,MAAM,IAAI,gBAAgB,kCAAkC;EAG9D,IAAI,CAAC,QAAQ,UACX,MAAM,IAAI,gBAAgB,sBAAsB;EAGlD,IAAI,CAAC,QAAQ,eACX,MAAM,IAAI,gBAAgB,4BAA4B;EAGxD,IAAI,CAAC,QAAQ,YACX,MAAM,IAAI,gBAAgB,yBAAyB;EAGrD,OAAO,MAAM,+BAA+B;GAC1C,QAAQ,QAAQ;GAChB,UAAU,QAAQ;GAClB,YAAY,QAAQ;EACtB,CAAC;EAED,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;EAqBjB,MAAM,YAAY,EAChB,OAAO;GACL,QAAQ,QAAQ;GAChB,UAAU,QAAQ;GAClB,eAAe,QAAQ;GACv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AE;GAAgB;EAAkB,GACpC,KAAK,OACP;EAEA,OAAO,KAAK,qCAAqC,EAAE,eAAe,CAAC;EAEnE,OAAO,SAAS;CAClB;;;;CAKA,MAAa,yBAAyB,YAA6C;EACjF,OAAO,MAAM,6CAA6C,EAAE,WAAW,CAAC;EAwBxE,QAAO,MANgB,KAAK,OAAO,MACjC;;;;;;;;;;;;;;OACA,EAAE,WAAW,GACb,KAAK,OACP,EAEe,CAAC;CAClB;;;;CAKA,MAAa,SAAS,aAAa,MAAuB;EACxD,OAAO,MAAM,4BAA4B,EAAE,WAAW,CAAC;EAsBvD,QAAO,MAFgB,KAAK,OAAO,MAA4B;;;;;;;;;;;;;;;;OAAO,EAAE,WAAW,GAAG,KAAK,OAAO,EAEnF,CAAC;CAClB;;;;CAKA,MAAa,oBAAoB,SAS9B;EACD,OAAO,MAAM,sCAAsC;GACjD,QAAQ,QAAQ;GAChB,UAAU,QAAQ;EACpB,CAAC;EAWD,MAAM,WAAW,MAAM,KAAK,OAAO,MAKhC;;;;;;;OAAU,EAAE,OAAO,QAAQ,GAAG,KAAK,OAAO;EAE7C,OAAO,KAAK,qCAAqC,EAC/C,iBAAiB,SAAS,oBAAoB,gBAChD,CAAC;EAED,OAAO,SAAS;CAClB;;;;CAKA,MAAa,gBAAgB,SAO1B;EACD,OAAO,MAAM,yCAAyC,OAAO;EAkC7D,QAAO,MAnBgB,KAAK,OAAO,MAUjC;;;;;;;;;;;OACA;GACE,WAAW,SAAS;GACpB,SAAS,SAAS;GAClB,aAAa,SAAS,eAAe,KAAK,QAAQ;EACpD,GACA,KAAK,OACP,EAEe,CAAC;CAClB;AACF"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-ad2WFvuA.js";
|
|
2
|
+
import { a as logger } from "./logger-B6rCpb7D.js";
|
|
3
|
+
import { GraphQLError } from "graphql";
|
|
4
|
+
|
|
5
|
+
// src/security/rate-limit/keyspace.ts
|
|
6
|
+
/**
|
|
7
|
+
* Rate-Limit Keyspace
|
|
8
|
+
*
|
|
9
|
+
* Canonical cache key builder so auth-svc, wspace-auth-svc, and gateway
|
|
10
|
+
* plugins never collide. Format: `ratelimit:{svc}:{resource}:{identifier}`.
|
|
11
|
+
*
|
|
12
|
+
* `svc` is the short service name (e.g., 'global-auth', 'wspace-auth',
|
|
13
|
+
* 'wspace-public-gateway'). `resource` is the RATE_LIMITS map key. `identifier`
|
|
14
|
+
* is whatever the limit is keyed by (email, userId, ip, etc).
|
|
15
|
+
*
|
|
16
|
+
* @module security/rate-limit/keyspace
|
|
17
|
+
* @category Security
|
|
18
|
+
*/
|
|
19
|
+
const buildRateLimitKey = (svc, resource, identifier) => `ratelimit:${svc}:${resource}:${identifier}`;
|
|
20
|
+
|
|
21
|
+
// src/security/rate-limit/rate-limit.ts
|
|
22
|
+
/**
|
|
23
|
+
* Shared Sliding-Window Rate Limiter
|
|
24
|
+
*
|
|
25
|
+
* Valkey-backed sliding window implemented via `INCR + EXPIRE` on the first
|
|
26
|
+
* event of a window (same approach as the global-auth-svc service today but
|
|
27
|
+
* lifted into `@burdenoff/be-sdk` so wspace-auth-svc and future consumers
|
|
28
|
+
* can share it).
|
|
29
|
+
*
|
|
30
|
+
* Honors `RateLimitMode`:
|
|
31
|
+
* - `enforce` — throws GraphQLError('RATE_LIMITED') on breach
|
|
32
|
+
* - `soft` — counts + logs, returns `allowed: false` but never throws
|
|
33
|
+
* - `off` — short-circuits to `{allowed: true}`
|
|
34
|
+
*
|
|
35
|
+
* Honors `failureMode`:
|
|
36
|
+
* - `open` — Valkey outage: allow + log warning (default for read paths)
|
|
37
|
+
* - `closed` — Valkey outage: reject (auth-critical ops like login/reset)
|
|
38
|
+
*
|
|
39
|
+
* @module security/rate-limit/rate-limit
|
|
40
|
+
* @category Security
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* Low-level: check a rate limit and return the result. Never throws unless
|
|
44
|
+
* `failureMode: 'closed'` and the cache is unreachable — and even then it
|
|
45
|
+
* returns a non-throwing `{ allowed: false }` so callers stay in control.
|
|
46
|
+
*/
|
|
47
|
+
const checkRateLimit = async (deps, identifier, resource, config) => {
|
|
48
|
+
const resetAt = new Date(Date.now() + config.windowMs);
|
|
49
|
+
if (deps.mode === "off") return {
|
|
50
|
+
allowed: true,
|
|
51
|
+
remaining: Number.MAX_SAFE_INTEGER,
|
|
52
|
+
resetAt,
|
|
53
|
+
limit: config.maxRequests
|
|
54
|
+
};
|
|
55
|
+
const key = buildRateLimitKey(deps.service, resource, identifier);
|
|
56
|
+
try {
|
|
57
|
+
const current = await deps.cache.get(key);
|
|
58
|
+
const count = current ? parseInt(current, 10) || 0 : 0;
|
|
59
|
+
if (count >= config.maxRequests) return {
|
|
60
|
+
allowed: false,
|
|
61
|
+
remaining: 0,
|
|
62
|
+
resetAt,
|
|
63
|
+
limit: config.maxRequests
|
|
64
|
+
};
|
|
65
|
+
const ttlSeconds = Math.ceil(config.windowMs / 1e3);
|
|
66
|
+
await deps.cache.set(key, String(count + 1), { ttl: ttlSeconds });
|
|
67
|
+
return {
|
|
68
|
+
allowed: true,
|
|
69
|
+
remaining: Math.max(0, config.maxRequests - count - 1),
|
|
70
|
+
resetAt,
|
|
71
|
+
limit: config.maxRequests
|
|
72
|
+
};
|
|
73
|
+
} catch (err) {
|
|
74
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
75
|
+
const failureMode = config.failureMode ?? "open";
|
|
76
|
+
logger.warn("[security/rate-limit] cache error — applying failure mode", {
|
|
77
|
+
service: deps.service,
|
|
78
|
+
resource,
|
|
79
|
+
identifier,
|
|
80
|
+
failureMode,
|
|
81
|
+
error: e.message
|
|
82
|
+
});
|
|
83
|
+
if (failureMode === "closed") return {
|
|
84
|
+
allowed: false,
|
|
85
|
+
remaining: 0,
|
|
86
|
+
resetAt,
|
|
87
|
+
limit: config.maxRequests
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
allowed: true,
|
|
91
|
+
remaining: config.maxRequests,
|
|
92
|
+
resetAt,
|
|
93
|
+
limit: config.maxRequests
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* High-level: check a rate limit and throw `GraphQLError(RATE_LIMITED)` on
|
|
99
|
+
* breach. Honors `mode`:
|
|
100
|
+
* - `enforce` throws on breach
|
|
101
|
+
* - `soft` logs the breach but does not throw
|
|
102
|
+
* - `off` short-circuits to allowed
|
|
103
|
+
*/
|
|
104
|
+
const enforceRateLimit = async (deps, identifier, resource, config) => {
|
|
105
|
+
const result = await checkRateLimit(deps, identifier, resource, config);
|
|
106
|
+
if (result.allowed) return result;
|
|
107
|
+
if (deps.mode === "soft") {
|
|
108
|
+
logger.warn("[security/rate-limit] soft-limit breach (not thrown)", {
|
|
109
|
+
service: deps.service,
|
|
110
|
+
resource,
|
|
111
|
+
identifier,
|
|
112
|
+
limit: result.limit
|
|
113
|
+
});
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
if (deps.mode === "enforce") throw new GraphQLError("Rate limit exceeded", { extensions: {
|
|
117
|
+
code: "RATE_LIMITED",
|
|
118
|
+
resetAt: result.resetAt.toISOString(),
|
|
119
|
+
limit: result.limit
|
|
120
|
+
} });
|
|
121
|
+
return result;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Helper: parse `RATE_LIMIT_MODE` env into a typed value.
|
|
125
|
+
* Prod defaults to `enforce`, non-prod to `soft`.
|
|
126
|
+
*/
|
|
127
|
+
const resolveRateLimitModeFromEnv = () => {
|
|
128
|
+
const raw = process.env["RATE_LIMIT_MODE"];
|
|
129
|
+
if (raw === "enforce" || raw === "soft" || raw === "off") return raw;
|
|
130
|
+
return process.env["NODE_ENV"] === "production" ? "enforce" : "soft";
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// src/security/rate-limit/index.ts
|
|
134
|
+
var rate_limit_exports = /* @__PURE__ */ __exportAll({
|
|
135
|
+
buildRateLimitKey: () => buildRateLimitKey,
|
|
136
|
+
checkRateLimit: () => checkRateLimit,
|
|
137
|
+
enforceRateLimit: () => enforceRateLimit,
|
|
138
|
+
resolveRateLimitModeFromEnv: () => resolveRateLimitModeFromEnv
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
export { buildRateLimitKey as a, resolveRateLimitModeFromEnv as i, checkRateLimit as n, enforceRateLimit as r, rate_limit_exports as t };
|
|
142
|
+
//# sourceMappingURL=rate-limit-CBrK_U5H.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit-CBrK_U5H.js","names":[],"sources":["../src/security/rate-limit/keyspace.ts","../src/security/rate-limit/rate-limit.ts","../src/security/rate-limit/index.ts"],"sourcesContent":["/**\n * Rate-Limit Keyspace\n *\n * Canonical cache key builder so auth-svc, wspace-auth-svc, and gateway\n * plugins never collide. Format: `ratelimit:{svc}:{resource}:{identifier}`.\n *\n * `svc` is the short service name (e.g., 'global-auth', 'wspace-auth',\n * 'wspace-public-gateway'). `resource` is the RATE_LIMITS map key. `identifier`\n * is whatever the limit is keyed by (email, userId, ip, etc).\n *\n * @module security/rate-limit/keyspace\n * @category Security\n */\n\nexport const buildRateLimitKey = (svc: string, resource: string, identifier: string): string =>\n `ratelimit:${svc}:${resource}:${identifier}`;\n","/**\n * Shared Sliding-Window Rate Limiter\n *\n * Valkey-backed sliding window implemented via `INCR + EXPIRE` on the first\n * event of a window (same approach as the global-auth-svc service today but\n * lifted into `@burdenoff/be-sdk` so wspace-auth-svc and future consumers\n * can share it).\n *\n * Honors `RateLimitMode`:\n * - `enforce` — throws GraphQLError('RATE_LIMITED') on breach\n * - `soft` — counts + logs, returns `allowed: false` but never throws\n * - `off` — short-circuits to `{allowed: true}`\n *\n * Honors `failureMode`:\n * - `open` — Valkey outage: allow + log warning (default for read paths)\n * - `closed` — Valkey outage: reject (auth-critical ops like login/reset)\n *\n * @module security/rate-limit/rate-limit\n * @category Security\n */\n\nimport { GraphQLError } from 'graphql';\n\nimport type { ICacheProvider } from '../../cache/index.js';\nimport { logger } from '../../logger/index.js';\nimport { buildRateLimitKey } from './keyspace.js';\nimport type { RateLimitConfig, RateLimitMode, RateLimitResult } from './types.js';\n\nexport interface RateLimiterDeps {\n cache: Pick<ICacheProvider, 'get' | 'set' | 'ttl'>;\n /** Short service name (e.g., 'global-auth'). */\n service: string;\n /** Operational mode. */\n mode: RateLimitMode;\n}\n\n/**\n * Low-level: check a rate limit and return the result. Never throws unless\n * `failureMode: 'closed'` and the cache is unreachable — and even then it\n * returns a non-throwing `{ allowed: false }` so callers stay in control.\n */\nexport const checkRateLimit = async (\n deps: RateLimiterDeps,\n identifier: string,\n resource: string,\n config: RateLimitConfig\n): Promise<RateLimitResult> => {\n const resetAt = new Date(Date.now() + config.windowMs);\n\n if (deps.mode === 'off') {\n return { allowed: true, remaining: Number.MAX_SAFE_INTEGER, resetAt, limit: config.maxRequests };\n }\n\n const key = buildRateLimitKey(deps.service, resource, identifier);\n\n try {\n const current = await deps.cache.get<string>(key);\n const count = current ? parseInt(current, 10) || 0 : 0;\n\n if (count >= config.maxRequests) {\n return { allowed: false, remaining: 0, resetAt, limit: config.maxRequests };\n }\n\n const ttlSeconds = Math.ceil(config.windowMs / 1000);\n await deps.cache.set(key, String(count + 1), { ttl: ttlSeconds });\n\n return {\n allowed: true,\n remaining: Math.max(0, config.maxRequests - count - 1),\n resetAt,\n limit: config.maxRequests,\n };\n } catch (err) {\n const e = err instanceof Error ? err : new Error(String(err));\n const failureMode = config.failureMode ?? 'open';\n logger.warn('[security/rate-limit] cache error — applying failure mode', {\n service: deps.service,\n resource,\n identifier,\n failureMode,\n error: e.message,\n });\n if (failureMode === 'closed') {\n return { allowed: false, remaining: 0, resetAt, limit: config.maxRequests };\n }\n return {\n allowed: true,\n remaining: config.maxRequests,\n resetAt,\n limit: config.maxRequests,\n };\n }\n};\n\n/**\n * High-level: check a rate limit and throw `GraphQLError(RATE_LIMITED)` on\n * breach. Honors `mode`:\n * - `enforce` throws on breach\n * - `soft` logs the breach but does not throw\n * - `off` short-circuits to allowed\n */\nexport const enforceRateLimit = async (\n deps: RateLimiterDeps,\n identifier: string,\n resource: string,\n config: RateLimitConfig\n): Promise<RateLimitResult> => {\n const result = await checkRateLimit(deps, identifier, resource, config);\n\n if (result.allowed) return result;\n\n if (deps.mode === 'soft') {\n logger.warn('[security/rate-limit] soft-limit breach (not thrown)', {\n service: deps.service,\n resource,\n identifier,\n limit: result.limit,\n });\n return result;\n }\n\n if (deps.mode === 'enforce') {\n throw new GraphQLError('Rate limit exceeded', {\n extensions: {\n code: 'RATE_LIMITED',\n resetAt: result.resetAt.toISOString(),\n limit: result.limit,\n },\n });\n }\n\n return result;\n};\n\n/**\n * Helper: parse `RATE_LIMIT_MODE` env into a typed value.\n * Prod defaults to `enforce`, non-prod to `soft`.\n */\nexport const resolveRateLimitModeFromEnv = (): RateLimitMode => {\n const raw = process.env['RATE_LIMIT_MODE'];\n if (raw === 'enforce' || raw === 'soft' || raw === 'off') return raw;\n return process.env['NODE_ENV'] === 'production' ? 'enforce' : 'soft';\n};\n","/**\n * Shared Rate-Limit — public API\n *\n * Consumed by:\n * - `global-auth-svc` (replaces the local rate-limit service)\n * - `wspace-auth-svc` (new — parity)\n * - Any future service that needs Valkey-backed sliding-window limits\n *\n * For the gateway plugin, use `@burdenoff/be-sdk/gateway/security` instead —\n * it is a different shape (per-request Yoga plugin, token bucket).\n *\n * @module security/rate-limit\n * @category Security\n */\n\nexport { buildRateLimitKey } from './keyspace.js';\nexport { checkRateLimit, enforceRateLimit, resolveRateLimitModeFromEnv, type RateLimiterDeps } from './rate-limit.js';\nexport type { RateLimitConfig, RateLimitMode, RateLimitResult } from './types.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAcA,MAAa,qBAAqB,KAAa,UAAkB,eAC/D,aAAa,IAAI,GAAG,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC0BlC,MAAa,iBAAiB,OAC5B,MACA,Y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AAK,wDAAwD;GAClE,SAAS,KAAK;GACd;GACA;GACA,OAAO,OAAO;EAChB,CAAC;EACD,OAAO;CACT;CAEA,IAAI,KAAK,SAAS,WAChB,MAAM,IAAI,aAAa,uBAAuB,EAC5C,YAAY;EACV,MAAM;EACN,SAAS,OAAO,QAAQ,YAAY;EACpC,OAAO,OAAO;CAChB,EACF,CAAC;CAGH,OAAO;AACT;;;;;AAMA,MAAa,oCAAmD;CAC9D,MAAM,MAAM,QAAQ,IAAI;CACxB,IAAI,QAAQ,aAAa,QAAQ,UAAU,QAAQ,OAAO,OAAO;CACjE,OAAO,QAAQ,IAAI,gBAAgB,eAAe,YAAY;AAChE"}
|
package/dist/rbac/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as Permission, c as RoleDefaultPermission, d as RBACClient, f as RBACDirectiveConfig, h as createRBACDirectiveFromEnv, i as PBACPermissionLevel, l as createRBACClientFromEnv, m as createRBACDirectiveForLayer, n as EffectivePermissionEntry, o as RBACModule, p as createRBACDirective, r as PBACActorType, s as Role, t as CheckPermissionOptions, u as LayerAwareRBACConfig } from "../index-
|
|
1
|
+
import { a as Permission, c as RoleDefaultPermission, d as RBACClient, f as RBACDirectiveConfig, h as createRBACDirectiveFromEnv, i as PBACPermissionLevel, l as createRBACClientFromEnv, m as createRBACDirectiveForLayer, n as EffectivePermissionEntry, o as RBACModule, p as createRBACDirective, r as PBACActorType, s as Role, t as CheckPermissionOptions, u as LayerAwareRBACConfig } from "../index-C_GXXF32.js";
|
|
2
2
|
export { CheckPermissionOptions, EffectivePermissionEntry, type LayerAwareRBACConfig, PBACActorType, PBACPermissionLevel, Permission, RBACClient, type RBACDirectiveConfig, RBACModule, Role, RoleDefaultPermission, createRBACClientFromEnv, createRBACDirective, createRBACDirectiveForLayer, createRBACDirectiveFromEnv };
|
package/dist/rbac/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as createRBACDirectiveForLayer, i as createRBACDirective, n as createRBACClientFromEnv, o as createRBACDirectiveFromEnv, r as RBACClient, t as RBACModule } from "../rbac-
|
|
1
|
+
import { a as createRBACDirectiveForLayer, i as createRBACDirective, n as createRBACClientFromEnv, o as createRBACDirectiveFromEnv, r as RBACClient, t as RBACModule } from "../rbac-Dvz0YzEt.js";
|
|
2
2
|
|
|
3
3
|
export { RBACClient, RBACModule, createRBACClientFromEnv, createRBACDirective, createRBACDirectiveForLayer, createRBACDirectiveFromEnv };
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PermissionDeniedError, ValidationError } from "./types/index.js";
|
|
2
2
|
import { a as logger } from "./logger-B6rCpb7D.js";
|
|
3
3
|
import { i as DEFAULT_LAYER_RESOURCES, r as DEFAULT_GATEWAY_ROUTING } from "./layer-Bcix-WCl.js";
|
|
4
4
|
import { GraphQLClient } from "graphql-request";
|
|
@@ -1483,4 +1483,4 @@ var RBACModule = class {
|
|
|
1483
1483
|
};
|
|
1484
1484
|
|
|
1485
1485
|
export { createRBACDirectiveForLayer as a, createRBACDirective as i, createRBACClientFromEnv as n, createRBACDirectiveFromEnv as o, RBACClient as r, RBACModule as t };
|
|
1486
|
-
//# sourceMappingURL=rbac-
|
|
1486
|
+
//# sourceMappingURL=rbac-Dvz0YzEt.js.map
|