codebuff 1.0.218 → 1.0.220
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/checkpoints/checkpoint-manager.d.ts +1 -1
- package/dist/checkpoints/checkpoint-manager.js +8 -6
- package/dist/checkpoints/checkpoint-manager.js.map +1 -1
- package/dist/cli-handlers/api-key.d.ts +25 -0
- package/dist/cli-handlers/api-key.js +66 -0
- package/dist/cli-handlers/api-key.js.map +1 -0
- package/dist/cli-handlers/checkpoint.d.ts +18 -0
- package/dist/cli-handlers/checkpoint.js +195 -0
- package/dist/cli-handlers/checkpoint.js.map +1 -0
- package/dist/cli-handlers/diff.d.ts +2 -0
- package/dist/cli-handlers/diff.js +31 -0
- package/dist/cli-handlers/diff.js.map +1 -0
- package/dist/cli-handlers/easter-egg.d.ts +1 -0
- package/dist/cli-handlers/easter-egg.js +126 -0
- package/dist/cli-handlers/easter-egg.js.map +1 -0
- package/dist/cli.d.ts +0 -18
- package/dist/cli.js +70 -397
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +11 -11
- package/dist/client.js +123 -45
- package/dist/client.js.map +1 -1
- package/dist/code-map/tsconfig.tsbuildinfo +1 -1
- package/dist/common/actions.d.ts +288 -264
- package/dist/common/actions.js +10 -4
- package/dist/common/actions.js.map +1 -1
- package/dist/common/advanced-analyzer.d.ts +19 -0
- package/dist/common/advanced-analyzer.js +140 -0
- package/dist/common/advanced-analyzer.js.map +1 -0
- package/dist/common/billing/auto-topup.d.ts +8 -0
- package/dist/common/billing/auto-topup.js +192 -0
- package/dist/common/billing/auto-topup.js.map +1 -0
- package/dist/common/billing/balance-calculator.d.ts +55 -0
- package/dist/common/billing/balance-calculator.js +207 -0
- package/dist/common/billing/balance-calculator.js.map +1 -0
- package/dist/common/billing/check-auto-topup.d.ts +12 -0
- package/dist/common/billing/check-auto-topup.js +50 -0
- package/dist/common/billing/check-auto-topup.js.map +1 -0
- package/dist/common/billing/conversion.d.ts +9 -0
- package/dist/common/billing/conversion.js +20 -0
- package/dist/common/billing/conversion.js.map +1 -0
- package/dist/common/billing/credit-check.d.ts +8 -0
- package/dist/common/billing/credit-check.js +45 -0
- package/dist/common/billing/credit-check.js.map +1 -0
- package/dist/common/billing/credit-conversion.d.ts +24 -0
- package/dist/common/billing/credit-conversion.js +48 -0
- package/dist/common/billing/credit-conversion.js.map +1 -0
- package/dist/common/billing/grant-credits.d.ts +28 -0
- package/dist/common/billing/grant-credits.js +201 -0
- package/dist/common/billing/grant-credits.js.map +1 -0
- package/dist/common/billing/plans.d.ts +13 -0
- package/dist/common/billing/plans.js +44 -0
- package/dist/common/billing/plans.js.map +1 -0
- package/dist/common/billing/rollover-logic.d.ts +13 -0
- package/dist/common/billing/rollover-logic.js +174 -0
- package/dist/common/billing/rollover-logic.js.map +1 -0
- package/dist/common/billing/stripe-api.d.ts +31 -0
- package/dist/common/billing/stripe-api.js +104 -0
- package/dist/common/billing/stripe-api.js.map +1 -0
- package/dist/common/browser-actions.d.ts +62 -62
- package/dist/common/browser-actions.js +3 -3
- package/dist/common/browser-actions.js.map +1 -1
- package/dist/common/constants/grant-priorities.d.ts +2 -0
- package/dist/common/constants/grant-priorities.js +10 -0
- package/dist/common/constants/grant-priorities.js.map +1 -0
- package/dist/common/constants/tools.d.ts +1 -1
- package/dist/common/constants/tools.js +1 -1
- package/dist/common/constants/tools.js.map +1 -1
- package/dist/common/constants.d.ts +28 -1
- package/dist/common/constants.js +36 -7
- package/dist/common/constants.js.map +1 -1
- package/dist/common/db/schema.d.ts +323 -86
- package/dist/common/db/schema.js +55 -13
- package/dist/common/db/schema.js.map +1 -1
- package/dist/common/env.mjs +4 -1
- package/dist/common/env.mjs.map +1 -1
- package/dist/common/message-image-handling.d.ts +41 -0
- package/dist/common/message-image-handling.js +57 -0
- package/dist/common/message-image-handling.js.map +1 -0
- package/dist/common/types/agent-state.d.ts +8 -8
- package/dist/common/types/grant.d.ts +2 -0
- package/dist/common/types/grant.js +10 -0
- package/dist/common/types/grant.js.map +1 -0
- package/dist/common/types/usage.d.ts +37 -18
- package/dist/common/types/usage.js +9 -6
- package/dist/common/types/usage.js.map +1 -1
- package/dist/common/util/__tests__/saxy.test.d.ts +1 -0
- package/dist/common/util/__tests__/saxy.test.js +262 -0
- package/dist/common/util/__tests__/saxy.test.js.map +1 -0
- package/dist/common/util/credentials.d.ts +2 -2
- package/dist/common/util/dates.d.ts +10 -1
- package/dist/common/util/dates.js +11 -2
- package/dist/common/util/dates.js.map +1 -1
- package/dist/common/util/logger.js +32 -14
- package/dist/common/util/logger.js.map +1 -1
- package/dist/common/util/process-stream.d.ts +8 -0
- package/dist/common/util/process-stream.js +102 -0
- package/dist/common/util/process-stream.js.map +1 -0
- package/dist/common/util/promise.d.ts +1 -1
- package/dist/common/util/promise.js +2 -2
- package/dist/common/util/promise.js.map +1 -1
- package/dist/common/util/referral-credits.d.ts +1 -0
- package/dist/common/util/referral-credits.js +48 -0
- package/dist/common/util/referral-credits.js.map +1 -0
- package/dist/common/util/saxy.d.ts +8 -0
- package/dist/common/util/saxy.js +35 -12
- package/dist/common/util/saxy.js.map +1 -1
- package/dist/common/util/sync-failure.d.ts +1 -0
- package/dist/common/util/sync-failure.js +57 -0
- package/dist/common/util/sync-failure.js.map +1 -0
- package/dist/common/websockets/websocket-schema.d.ts +530 -480
- package/dist/index.js +1 -1
- package/dist/menu.js +5 -0
- package/dist/menu.js.map +1 -1
- package/dist/tool-handlers.js +1 -1
- package/dist/tool-handlers.js.map +1 -1
- package/dist/utils/__tests__/xml-stream-parser.test.js +6 -10
- package/dist/utils/__tests__/xml-stream-parser.test.js.map +1 -1
- package/dist/utils/tool-renderers.js +1 -1
- package/dist/utils/tool-renderers.js.map +1 -1
- package/package.json +1 -1
- package/dist/common/logger.d.ts +0 -1
- package/dist/common/logger.js +0 -7
- package/dist/common/logger.js.map +0 -1
- package/dist/common/util/constants.d.ts +0 -1
- package/dist/common/util/constants.js +0 -7
- package/dist/common/util/constants.js.map +0 -1
- package/dist/common/util/helpers.d.ts +0 -1
- package/dist/common/util/helpers.js +0 -6
- package/dist/common/util/helpers.js.map +0 -1
- package/dist/common/util/token-counter.d.ts +0 -3
- package/dist/common/util/token-counter.js +0 -27
- package/dist/common/util/token-counter.js.map +0 -1
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bun_test_1 = require("bun:test");
|
|
4
|
+
const saxy_1 = require("../saxy");
|
|
5
|
+
(0, bun_test_1.describe)('Saxy XML Parser', () => {
|
|
6
|
+
// Helper function to process XML and get events
|
|
7
|
+
const processXML = (xml, schema) => {
|
|
8
|
+
const events = [];
|
|
9
|
+
const parser = new saxy_1.Saxy(schema);
|
|
10
|
+
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
11
|
+
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
12
|
+
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
13
|
+
parser.write(xml);
|
|
14
|
+
parser.end();
|
|
15
|
+
return events;
|
|
16
|
+
};
|
|
17
|
+
(0, bun_test_1.describe)('Schema Validation with Text Conversion', () => {
|
|
18
|
+
(0, bun_test_1.it)('should convert invalid top-level tags to text nodes', () => {
|
|
19
|
+
const schema = { root: ['child'] };
|
|
20
|
+
const xml = '<invalid>content</invalid>';
|
|
21
|
+
const events = processXML(xml, schema);
|
|
22
|
+
(0, bun_test_1.expect)(events).toEqual([
|
|
23
|
+
{
|
|
24
|
+
type: 'text',
|
|
25
|
+
data: { contents: '<invalid>' },
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: 'text',
|
|
29
|
+
data: { contents: 'content' },
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type: 'text',
|
|
33
|
+
data: { contents: '</invalid>' },
|
|
34
|
+
},
|
|
35
|
+
]);
|
|
36
|
+
});
|
|
37
|
+
(0, bun_test_1.it)('should convert invalid nested tags to text nodes', () => {
|
|
38
|
+
const schema = { root: ['child'] };
|
|
39
|
+
const xml = '<other><invalid>content</invalid></other>';
|
|
40
|
+
const events = processXML(xml, schema);
|
|
41
|
+
(0, bun_test_1.expect)(events).toEqual([
|
|
42
|
+
{
|
|
43
|
+
type: 'text',
|
|
44
|
+
data: { contents: '<other>' },
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 'text',
|
|
48
|
+
data: { contents: '<invalid>' },
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: 'text',
|
|
52
|
+
data: { contents: 'content' },
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: 'text',
|
|
56
|
+
data: { contents: '</invalid>' },
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: 'text',
|
|
60
|
+
data: { contents: '</other>' },
|
|
61
|
+
},
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
64
|
+
(0, bun_test_1.it)('should handle valid nested tags according to schema', () => {
|
|
65
|
+
const schema = { root: ['child'] };
|
|
66
|
+
const xml = '<root><child>content</child></root>';
|
|
67
|
+
const events = processXML(xml, schema);
|
|
68
|
+
(0, bun_test_1.expect)(events).toEqual([
|
|
69
|
+
{
|
|
70
|
+
type: 'tagopen',
|
|
71
|
+
data: {
|
|
72
|
+
attrs: '',
|
|
73
|
+
isSelfClosing: false,
|
|
74
|
+
name: 'root',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: 'tagopen',
|
|
79
|
+
data: {
|
|
80
|
+
attrs: '',
|
|
81
|
+
isSelfClosing: false,
|
|
82
|
+
name: 'child',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: 'text',
|
|
87
|
+
data: { contents: 'content' },
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
type: 'tagclose',
|
|
91
|
+
data: { name: 'child' },
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
type: 'tagclose',
|
|
95
|
+
data: { name: 'root' },
|
|
96
|
+
},
|
|
97
|
+
]);
|
|
98
|
+
});
|
|
99
|
+
(0, bun_test_1.it)('should convert closing tags to text when parent is invalid', () => {
|
|
100
|
+
const schema = { root: ['child'] };
|
|
101
|
+
const xml = '<root><invalid>content</invalid><child/></root>';
|
|
102
|
+
const events = processXML(xml, schema);
|
|
103
|
+
(0, bun_test_1.expect)(events[1]).toEqual({
|
|
104
|
+
type: 'text',
|
|
105
|
+
data: { contents: '<invalid>' },
|
|
106
|
+
});
|
|
107
|
+
(0, bun_test_1.expect)(events[2]).toEqual({
|
|
108
|
+
type: 'text',
|
|
109
|
+
data: { contents: 'content' },
|
|
110
|
+
});
|
|
111
|
+
(0, bun_test_1.expect)(events[3]).toEqual({
|
|
112
|
+
type: 'text',
|
|
113
|
+
data: { contents: '</invalid>' },
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
(0, bun_test_1.it)('should handle tags starting with whitespace as text', () => {
|
|
117
|
+
const schema = { root: ['child'] };
|
|
118
|
+
const xml = '<root>< invalid>content</invalid></root>';
|
|
119
|
+
const events = processXML(xml, schema);
|
|
120
|
+
(0, bun_test_1.expect)(events[1]).toEqual({
|
|
121
|
+
type: 'text',
|
|
122
|
+
data: { contents: '< invalid>content' },
|
|
123
|
+
});
|
|
124
|
+
(0, bun_test_1.expect)(events[2]).toEqual({
|
|
125
|
+
type: 'text',
|
|
126
|
+
data: { contents: '</invalid>' },
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
(0, bun_test_1.describe)('Edge Cases', () => {
|
|
131
|
+
(0, bun_test_1.it)('should handle self-closing invalid tags', () => {
|
|
132
|
+
const schema = { root: ['child'] };
|
|
133
|
+
const xml = '<root><invalid/></root>';
|
|
134
|
+
const events = processXML(xml, schema);
|
|
135
|
+
(0, bun_test_1.expect)(events[1]).toEqual({
|
|
136
|
+
type: 'text',
|
|
137
|
+
data: { contents: '<invalid/>' },
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
(0, bun_test_1.it)('should handle nested invalid tags', () => {
|
|
141
|
+
const schema = { root: ['child'] };
|
|
142
|
+
const xml = '<root><invalid><alsoinvalid/></invalid></root>';
|
|
143
|
+
const events = processXML(xml, schema);
|
|
144
|
+
(0, bun_test_1.expect)(events[1]).toEqual({
|
|
145
|
+
type: 'text',
|
|
146
|
+
data: { contents: '<invalid>' },
|
|
147
|
+
});
|
|
148
|
+
(0, bun_test_1.expect)(events[2]).toEqual({
|
|
149
|
+
type: 'text',
|
|
150
|
+
data: { contents: '<alsoinvalid/>' },
|
|
151
|
+
});
|
|
152
|
+
(0, bun_test_1.expect)(events[3]).toEqual({
|
|
153
|
+
type: 'text',
|
|
154
|
+
data: { contents: '</invalid>' },
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
(0, bun_test_1.it)('should preserve attributes in converted text nodes', () => {
|
|
158
|
+
const schema = { root: ['child'] };
|
|
159
|
+
const xml = '<root><invalid attr="value">content</invalid></root>';
|
|
160
|
+
const events = processXML(xml, schema);
|
|
161
|
+
(0, bun_test_1.expect)(events[1]).toEqual({
|
|
162
|
+
type: 'text',
|
|
163
|
+
data: { contents: '<invalid attr="value">' },
|
|
164
|
+
});
|
|
165
|
+
(0, bun_test_1.expect)(events[2]).toEqual({
|
|
166
|
+
type: 'text',
|
|
167
|
+
data: { contents: 'content' },
|
|
168
|
+
});
|
|
169
|
+
(0, bun_test_1.expect)(events[3]).toEqual({
|
|
170
|
+
type: 'text',
|
|
171
|
+
data: { contents: '</invalid>' },
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
(0, bun_test_1.it)('should handle text that looks like invalid XML tags', () => {
|
|
176
|
+
const parser = new saxy_1.Saxy();
|
|
177
|
+
const events = [];
|
|
178
|
+
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
179
|
+
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
180
|
+
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
181
|
+
parser.write('This is < not a tag> and < another not a tag> but <valid>this is</valid>');
|
|
182
|
+
parser.end();
|
|
183
|
+
(0, bun_test_1.expect)(events).toEqual([
|
|
184
|
+
{
|
|
185
|
+
type: 'text',
|
|
186
|
+
data: {
|
|
187
|
+
contents: 'This is < not a tag> and < another not a tag> but ',
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
type: 'tagopen',
|
|
192
|
+
data: { name: 'valid', isSelfClosing: false, attrs: '' },
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
type: 'text',
|
|
196
|
+
data: { contents: 'this is' },
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
type: 'tagclose',
|
|
200
|
+
data: { name: 'valid' },
|
|
201
|
+
},
|
|
202
|
+
]);
|
|
203
|
+
});
|
|
204
|
+
(0, bun_test_1.it)('should handle text with angle brackets but no valid tag names', () => {
|
|
205
|
+
const parser = new saxy_1.Saxy();
|
|
206
|
+
const events = [];
|
|
207
|
+
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
208
|
+
parser.write('Math expressions: 2 < 3 and 5 > 4');
|
|
209
|
+
parser.end();
|
|
210
|
+
(0, bun_test_1.expect)(events).toEqual([
|
|
211
|
+
{
|
|
212
|
+
type: 'text',
|
|
213
|
+
data: { contents: 'Math expressions: 2 < 3 and 5 > 4' },
|
|
214
|
+
},
|
|
215
|
+
]);
|
|
216
|
+
});
|
|
217
|
+
(0, bun_test_1.it)('should correctly parse mixed valid and invalid XML-like content', () => {
|
|
218
|
+
const parser = new saxy_1.Saxy();
|
|
219
|
+
const events = [];
|
|
220
|
+
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
221
|
+
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
222
|
+
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
223
|
+
parser.write('Text with < brackets> and <valid-tag>real XML</valid-tag> mixed together');
|
|
224
|
+
parser.end();
|
|
225
|
+
(0, bun_test_1.expect)(events).toEqual([
|
|
226
|
+
{
|
|
227
|
+
type: 'text',
|
|
228
|
+
data: { contents: 'Text with < brackets> and ' },
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
type: 'tagopen',
|
|
232
|
+
data: { name: 'valid-tag', isSelfClosing: false, attrs: '' },
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
type: 'text',
|
|
236
|
+
data: { contents: 'real XML' },
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
type: 'tagclose',
|
|
240
|
+
data: { name: 'valid-tag' },
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
type: 'text',
|
|
244
|
+
data: { contents: ' mixed together' },
|
|
245
|
+
},
|
|
246
|
+
]);
|
|
247
|
+
});
|
|
248
|
+
(0, bun_test_1.it)('should handle edge cases with special characters after <', () => {
|
|
249
|
+
const parser = new saxy_1.Saxy();
|
|
250
|
+
const events = [];
|
|
251
|
+
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
252
|
+
parser.write('Text with <1>, <@invalid>, and <!not-a-tag>');
|
|
253
|
+
parser.end();
|
|
254
|
+
(0, bun_test_1.expect)(events).toEqual([
|
|
255
|
+
{
|
|
256
|
+
type: 'text',
|
|
257
|
+
data: { contents: 'Text with <1>, <@invalid>, and <!not-a-tag>' },
|
|
258
|
+
},
|
|
259
|
+
]);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
//# sourceMappingURL=saxy.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saxy.test.js","sourceRoot":"","sources":["../../../src/util/__tests__/saxy.test.ts"],"names":[],"mappings":";;AAAA,uCAA+C;AAE/C,kCAA8B;AAE9B,IAAA,mBAAQ,EAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,gDAAgD;IAChD,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,MAAi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AAE,EAAE,QAAQ,EAAE,6CAA6C,EAAE;aAClE;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -8,17 +8,17 @@ export declare const userSchema: z.ZodObject<{
|
|
|
8
8
|
fingerprintHash: z.ZodString;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
10
|
name: string | null;
|
|
11
|
+
email: string;
|
|
11
12
|
id: string;
|
|
12
13
|
fingerprintId: string;
|
|
13
14
|
authToken: string;
|
|
14
|
-
email: string;
|
|
15
15
|
fingerprintHash: string;
|
|
16
16
|
}, {
|
|
17
17
|
name: string | null;
|
|
18
|
+
email: string;
|
|
18
19
|
id: string;
|
|
19
20
|
fingerprintId: string;
|
|
20
21
|
authToken: string;
|
|
21
|
-
email: string;
|
|
22
22
|
fingerprintHash: string;
|
|
23
23
|
}>;
|
|
24
24
|
export type User = z.infer<typeof userSchema>;
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the next quota reset date.
|
|
3
|
+
* If the current reset date is in the past or null, it calculates the next
|
|
4
|
+
* reset date based on the current date. Otherwise, it ensures the next
|
|
5
|
+
* reset date is in the future relative to the provided date.
|
|
6
|
+
*
|
|
7
|
+
* @param referenceDate The user's current `next_quota_reset` date, or the date the cycle ended.
|
|
8
|
+
* @returns The Date object representing the next reset time.
|
|
9
|
+
*/
|
|
10
|
+
export declare const getNextQuotaReset: (referenceDate: Date | null) => Date;
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getNextQuotaReset = void 0;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Calculates the next quota reset date.
|
|
6
|
+
* If the current reset date is in the past or null, it calculates the next
|
|
7
|
+
* reset date based on the current date. Otherwise, it ensures the next
|
|
8
|
+
* reset date is in the future relative to the provided date.
|
|
9
|
+
*
|
|
10
|
+
* @param referenceDate The user's current `next_quota_reset` date, or the date the cycle ended.
|
|
11
|
+
* @returns The Date object representing the next reset time.
|
|
12
|
+
*/
|
|
13
|
+
const getNextQuotaReset = (referenceDate) => {
|
|
5
14
|
const now = new Date();
|
|
6
|
-
let nextMonth = new Date(
|
|
15
|
+
let nextMonth = new Date(referenceDate ?? now);
|
|
7
16
|
while (nextMonth <= now) {
|
|
8
17
|
nextMonth.setMonth(nextMonth.getMonth() + 1);
|
|
9
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dates.js","sourceRoot":"","sources":["../../src/util/dates.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"dates.js","sourceRoot":"","sources":["../../src/util/dates.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACI,MAAM,iBAAiB,GAAG,CAAC,aAA0B,EAAQ,EAAE;IACpE,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;IACtB,IAAI,SAAS,GAAG,IAAI,IAAI,CAAC,aAAa,IAAI,GAAG,CAAC,CAAA;IAC9C,OAAO,SAAS,IAAI,GAAG,EAAE,CAAC;QACxB,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAA;IAC9C,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAPY,QAAA,iBAAiB,qBAO7B"}
|
|
@@ -6,29 +6,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.logger = exports.withLoggerContext = void 0;
|
|
7
7
|
const pino_1 = __importDefault(require("pino"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const async_hooks_1 = require("async_hooks");
|
|
10
9
|
const env_mjs_1 = require("../env.mjs");
|
|
11
|
-
|
|
10
|
+
let AsyncLocalStorageImpl;
|
|
11
|
+
try {
|
|
12
|
+
// Load AsyncLocalStorage via require
|
|
13
|
+
AsyncLocalStorageImpl = require('async_hooks').AsyncLocalStorage;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
AsyncLocalStorageImpl = null;
|
|
17
|
+
}
|
|
18
|
+
// Create a no‑op shim when AsyncLocalStorage isn't present
|
|
19
|
+
const loggerAsyncStorage = AsyncLocalStorageImpl !== null
|
|
20
|
+
? new AsyncLocalStorageImpl()
|
|
21
|
+
: {
|
|
22
|
+
// run() just executes fn without context tracking
|
|
23
|
+
run: (_, fn, ...args) => fn(...args),
|
|
24
|
+
getStore: () => undefined,
|
|
25
|
+
};
|
|
12
26
|
const withLoggerContext = (additionalContext, fn) => {
|
|
13
|
-
const store = loggerAsyncStorage.getStore() ?? {};
|
|
27
|
+
const store = (loggerAsyncStorage.getStore?.() ?? {});
|
|
28
|
+
// Cast to Node's AsyncLocalStorage to resolve overload mismatch
|
|
14
29
|
return loggerAsyncStorage.run({ ...store, ...additionalContext }, fn);
|
|
15
30
|
};
|
|
16
31
|
exports.withLoggerContext = withLoggerContext;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
32
|
+
// Only use file transport when not running in Edge/browser‑like env
|
|
33
|
+
const runningInEdge = process.env.NEXT_RUNTIME === 'edge';
|
|
34
|
+
const fileTransport = !runningInEdge && env_mjs_1.env.ENVIRONMENT !== 'production'
|
|
35
|
+
? pino_1.default.transport({
|
|
36
|
+
target: 'pino/file',
|
|
37
|
+
options: { destination: path_1.default.join(__dirname, '..', 'debug.log') },
|
|
38
|
+
level: 'debug',
|
|
39
|
+
})
|
|
40
|
+
: undefined;
|
|
22
41
|
exports.logger = (0, pino_1.default)({
|
|
23
42
|
level: 'debug',
|
|
24
43
|
mixin() {
|
|
25
|
-
|
|
44
|
+
// If AsyncLocalStorage isn't available, return undefined
|
|
45
|
+
return { logTrace: loggerAsyncStorage.getStore?.() };
|
|
26
46
|
},
|
|
27
47
|
formatters: {
|
|
28
|
-
level: (label) => {
|
|
29
|
-
return { level: label.toUpperCase() };
|
|
30
|
-
},
|
|
48
|
+
level: (label) => ({ level: label.toUpperCase() }),
|
|
31
49
|
},
|
|
32
|
-
timestamp: () => `,"timestamp":"${new Date(
|
|
33
|
-
},
|
|
50
|
+
timestamp: () => `,"timestamp":"${new Date().toISOString()}"`,
|
|
51
|
+
}, fileTransport);
|
|
34
52
|
//# sourceMappingURL=logger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,gDAAuB;AACvB,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,gDAAuB;AACvB,wCAAgC;AAGhC,IAAI,qBAA4E,CAAA;AAChF,IAAI,CAAC;IACH,qCAAqC;IACrC,qBAAqB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,iBAAiB,CAAA;AAClE,CAAC;AAAC,MAAM,CAAC;IACP,qBAAqB,GAAG,IAAI,CAAA;AAC9B,CAAC;AAED,2DAA2D;AAC3D,MAAM,kBAAkB,GACtB,qBAAqB,KAAK,IAAI;IAC5B,CAAC,CAAC,IAAI,qBAAqB,EAAiB;IAC5C,CAAC,CAAC;QACE,kDAAkD;QAClD,GAAG,EAAE,CAAqB,CAAM,EAAE,EAAqB,EAAE,GAAG,IAAO,EAAE,EAAE,CACrE,EAAE,CAAC,GAAG,IAAI,CAAC;QACb,QAAQ,EAAE,GAAG,EAAE,CAAC,SAAS;KAC1B,CAAA;AASA,MAAM,iBAAiB,GAAG,CAC/B,iBAAyC,EACzC,EAAoB,EACpB,EAAE;IACF,MAAM,KAAK,GAAG,CAAC,kBAAkB,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAkB,CAAA;IACtE,gEAAgE;IAChE,OAAQ,kBAA2D,CAAC,GAAG,CACrE,EAAE,GAAG,KAAK,EAAE,GAAG,iBAAiB,EAAE,EAClC,EAAE,CACH,CAAA;AACH,CAAC,CAAA;AAVY,QAAA,iBAAiB,qBAU7B;AAED,oEAAoE;AACpE,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,MAAM,CAAA;AACzD,MAAM,aAAa,GACjB,CAAC,aAAa,IAAI,aAAG,CAAC,WAAW,KAAK,YAAY;IAChD,CAAC,CAAC,cAAI,CAAC,SAAS,CAAC;QACb,MAAM,EAAE,WAAW;QACnB,OAAO,EAAE,EAAE,WAAW,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,EAAE;QACjE,KAAK,EAAE,OAAO;KACf,CAAC;IACJ,CAAC,CAAC,SAAS,CAAA;AAEF,QAAA,MAAM,GAAG,IAAA,cAAI,EACxB;IACE,KAAK,EAAE,OAAO;IACd,KAAK;QACH,yDAAyD;QACzD,OAAO,EAAE,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAA;IACtD,CAAC;IACD,UAAU,EAAE;QACV,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;KACnD;IACD,SAAS,EAAE,GAAG,EAAE,CAAC,iBAAiB,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,GAAG;CAC9D,EACD,aAAa,CACd,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function processStreamWithTags<T extends string>(stream: AsyncGenerator<T> | ReadableStream<T>, tags: {
|
|
2
|
+
[tagName: string]: {
|
|
3
|
+
attributeNames: string[];
|
|
4
|
+
onTagStart: (attributes: Record<string, string>) => void;
|
|
5
|
+
onTagEnd: (content: string, attributes: Record<string, string>) => boolean;
|
|
6
|
+
};
|
|
7
|
+
}): AsyncGenerator<string, void, unknown>;
|
|
8
|
+
export declare function parseAttributes(attributesString: string, attributeNames: string[]): Record<string, string>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processStreamWithTags = processStreamWithTags;
|
|
4
|
+
exports.parseAttributes = parseAttributes;
|
|
5
|
+
async function* processStreamWithTags(stream, tags) {
|
|
6
|
+
let buffer = '';
|
|
7
|
+
let insideTag = null;
|
|
8
|
+
let currentAttributes = {};
|
|
9
|
+
let streamCompleted = false;
|
|
10
|
+
const escapeRegExp = (string) => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
11
|
+
const tagNames = Object.keys(tags);
|
|
12
|
+
const openTagRegex = new RegExp(`<(${tagNames.map(escapeRegExp).join('|')})\\s*([^>]*)>`);
|
|
13
|
+
const closeTagRegex = new RegExp(`</(${tagNames.map(escapeRegExp).join('|')})>`);
|
|
14
|
+
function* parseBuffer(chunk) {
|
|
15
|
+
const isEOF = chunk === undefined;
|
|
16
|
+
if (chunk) {
|
|
17
|
+
yield chunk;
|
|
18
|
+
}
|
|
19
|
+
let didParse = true;
|
|
20
|
+
while (!streamCompleted && didParse) {
|
|
21
|
+
didParse = false;
|
|
22
|
+
if (insideTag === null) {
|
|
23
|
+
// Outside a tag: try to find the next opening tag
|
|
24
|
+
const openMatch = buffer.match(openTagRegex);
|
|
25
|
+
if (openMatch && openMatch.index !== undefined) {
|
|
26
|
+
const [fullMatch, openTag, attributesString] = openMatch;
|
|
27
|
+
const beforeTag = buffer.slice(0, openMatch.index);
|
|
28
|
+
const afterMatchIndex = openMatch.index + fullMatch.length;
|
|
29
|
+
// Move buffer forward
|
|
30
|
+
buffer = buffer.slice(afterMatchIndex);
|
|
31
|
+
// We are now inside this tag
|
|
32
|
+
insideTag = openTag;
|
|
33
|
+
currentAttributes = parseAttributes(attributesString, tags[openTag].attributeNames);
|
|
34
|
+
// Call onTagStart
|
|
35
|
+
tags[openTag].onTagStart(currentAttributes);
|
|
36
|
+
didParse = true;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// No opening tag found. If it's EOF, yield remaining text.
|
|
40
|
+
if (isEOF && buffer.length > 0) {
|
|
41
|
+
buffer = '';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// Inside a tag: try to find the closing tag
|
|
47
|
+
const closeMatch = buffer.match(closeTagRegex);
|
|
48
|
+
if (closeMatch && closeMatch.index !== undefined) {
|
|
49
|
+
const [fullMatch, closeTag] = closeMatch;
|
|
50
|
+
const content = buffer.slice(0, closeMatch.index);
|
|
51
|
+
// Move buffer forward
|
|
52
|
+
buffer = buffer.slice(closeMatch.index + fullMatch.length);
|
|
53
|
+
// Close the tag
|
|
54
|
+
const complete = tags[insideTag].onTagEnd(content, currentAttributes);
|
|
55
|
+
insideTag = null;
|
|
56
|
+
currentAttributes = {};
|
|
57
|
+
if (complete) {
|
|
58
|
+
// If onTagEnd signals completion, set streamCompleted and return
|
|
59
|
+
streamCompleted = true;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
didParse = true;
|
|
63
|
+
}
|
|
64
|
+
else if (isEOF) {
|
|
65
|
+
// We reached EOF without finding a closing tag
|
|
66
|
+
// Treat remaining buffer as content and close the tag
|
|
67
|
+
if (buffer.length > 0) {
|
|
68
|
+
const complete = tags[insideTag].onTagEnd(buffer, currentAttributes);
|
|
69
|
+
yield '</' + insideTag + '>';
|
|
70
|
+
buffer = '';
|
|
71
|
+
insideTag = null;
|
|
72
|
+
currentAttributes = {};
|
|
73
|
+
if (complete) {
|
|
74
|
+
streamCompleted = true;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
for await (const chunk of stream) {
|
|
83
|
+
if (streamCompleted)
|
|
84
|
+
continue;
|
|
85
|
+
buffer += chunk;
|
|
86
|
+
yield* parseBuffer(chunk);
|
|
87
|
+
}
|
|
88
|
+
if (!streamCompleted) {
|
|
89
|
+
// After the stream ends, try parsing one last time in case there's leftover text
|
|
90
|
+
yield* parseBuffer(undefined);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function parseAttributes(attributesString, attributeNames) {
|
|
94
|
+
const attributes = {};
|
|
95
|
+
const regex = new RegExp(`(${attributeNames.join('|')})="([^"]*)"`, 'g');
|
|
96
|
+
let match;
|
|
97
|
+
while ((match = regex.exec(attributesString)) !== null) {
|
|
98
|
+
attributes[match[1]] = match[2];
|
|
99
|
+
}
|
|
100
|
+
return attributes;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=process-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-stream.js","sourceRoot":"","sources":["../../src/util/process-stream.ts"],"names":[],"mappings":";;AAAA,sDAoHC;AAED,0CAWC;AAjIM,KAAK,SAAS,CAAC,CAAC,qBAAqB,CAC1C,MAA6C,EAC7C,IAMC;IAED,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,IAAI,SAAS,GAAkB,IAAI,CAAA;IACnC,IAAI,iBAAiB,GAA2B,EAAE,CAAA;IAClD,IAAI,eAAe,GAAG,KAAK,CAAA;IAE3B,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,EAAE,CACtC,MAAM,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAA;IAC/C,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAClC,MAAM,YAAY,GAAG,IAAI,MAAM,CAC7B,KAAK,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,CACzD,CAAA;IACD,MAAM,aAAa,GAAG,IAAI,MAAM,CAC9B,MAAM,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAC/C,CAAA;IA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ACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACjC,IAAI,eAAe;YAAE,SAAQ;QAC7B,MAAM,IAAI,KAAK,CAAA;QACf,KAAK,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;IAED,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,iFAAiF;QACjF,KAAK,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,CAAA;IAC/B,CAAC;AACH,CAAC;AAED,SAAgB,eAAe,CAC7B,gBAAwB,EACxB,cAAwB;IAExB,MAAM,UAAU,GAA2B,EAAE,CAAA;IAC7C,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,CAAA;IACxE,IAAI,KAAK,CAAA;IACT,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACvD,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;IACjC,CAAC;IACD,OAAO,UAAU,CAAA;AACnB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const INITIAL_RETRY_DELAY = 1000;
|
|
2
2
|
export declare function withRetry<T>(operation: () => Promise<T>, options?: {
|
|
3
3
|
maxRetries?: number;
|
|
4
|
-
|
|
4
|
+
retryIf?: (error: any) => boolean;
|
|
5
5
|
onRetry?: (error: any, attempt: number) => void;
|
|
6
6
|
retryDelayMs?: number;
|
|
7
7
|
}): Promise<T>;
|
|
@@ -5,7 +5,7 @@ exports.withRetry = withRetry;
|
|
|
5
5
|
exports.withTimeout = withTimeout;
|
|
6
6
|
exports.INITIAL_RETRY_DELAY = 1000; // 1 second
|
|
7
7
|
async function withRetry(operation, options = {}) {
|
|
8
|
-
const { maxRetries = 3,
|
|
8
|
+
const { maxRetries = 3, retryIf = (error) => error?.type === 'APIConnectionError', onRetry = () => { }, retryDelayMs = exports.INITIAL_RETRY_DELAY, } = options;
|
|
9
9
|
let lastError = null;
|
|
10
10
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
11
11
|
try {
|
|
@@ -13,7 +13,7 @@ async function withRetry(operation, options = {}) {
|
|
|
13
13
|
}
|
|
14
14
|
catch (error) {
|
|
15
15
|
lastError = error;
|
|
16
|
-
if (!
|
|
16
|
+
if (!retryIf(error) || attempt === maxRetries - 1) {
|
|
17
17
|
throw error;
|
|
18
18
|
}
|
|
19
19
|
onRetry(error, attempt + 1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/util/promise.ts"],"names":[],"mappings":";;;AAEA,8BAqCC;AA2CD,kCAoBC;AAtGY,QAAA,mBAAmB,GAAG,IAAI,CAAA,CAAC,WAAW;AAE5C,KAAK,UAAU,SAAS,CAC7B,SAA2B,EAC3B,UAKI,EAAE;IAEN,MAAM,EACJ,UAAU,GAAG,CAAC,EACd,
|
|
1
|
+
{"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/util/promise.ts"],"names":[],"mappings":";;;AAEA,8BAqCC;AA2CD,kCAoBC;AAtGY,QAAA,mBAAmB,GAAG,IAAI,CAAA,CAAC,WAAW;AAE5C,KAAK,UAAU,SAAS,CAC7B,SAA2B,EAC3B,UAKI,EAAE;IAEN,MAAM,EACJ,UAAU,GAAG,CAAC,EACd,OAAO,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,oBAAoB,EACzD,OAAO,GAAG,GAAG,EAAE,GAAE,CAAC,EAClB,YAAY,GAAG,2BAAmB,GACnC,GAAG,OAAO,CAAA;IAEX,IAAI,SAAS,GAAQ,IAAI,CAAA;IAEzB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,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ReferralCreditsForCustomer(userId: string): Promise<number>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getTotalReferralCreditsForCustomer = getTotalReferralCreditsForCustomer;
|
|
30
|
+
const drizzle_orm_1 = require("drizzle-orm");
|
|
31
|
+
const drizzle_orm_2 = require("drizzle-orm");
|
|
32
|
+
const db_1 = __importDefault(require("../db"));
|
|
33
|
+
const schema = __importStar(require("../db/schema"));
|
|
34
|
+
async function getTotalReferralCreditsForCustomer(userId) {
|
|
35
|
+
return db_1.default
|
|
36
|
+
.select({
|
|
37
|
+
referralCredits: (0, drizzle_orm_1.sql) `SUM(COALESCE(${schema.referral.credits}, 0))`,
|
|
38
|
+
})
|
|
39
|
+
.from(schema.user)
|
|
40
|
+
.leftJoin(schema.referral, (0, drizzle_orm_2.or)((0, drizzle_orm_2.eq)(schema.referral.referrer_id, schema.user.id), (0, drizzle_orm_2.eq)(schema.referral.referred_id, schema.user.id)))
|
|
41
|
+
.where((0, drizzle_orm_2.eq)(schema.user.id, userId))
|
|
42
|
+
.limit(1)
|
|
43
|
+
.then((rows) => {
|
|
44
|
+
const firstRow = rows[0];
|
|
45
|
+
return parseInt(firstRow?.referralCredits ?? '0');
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=referral-credits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"referral-credits.js","sourceRoot":"","sources":["../../src/util/referral-credits.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,gFAqBC;AA1BD,6CAAiC;AACjC,6CAAoC;AACpC,+CAAsB;AACtB,qDAAsC;AAE/B,KAAK,UAAU,kCAAkC,CACtD,MAAc;IAEd,OAAO,YAAE;SACN,MAAM,CAAC;QACN,eAAe,EAAE,IAAA,iBAAG,EAAQ,gBAAgB,MAAM,CAAC,QAAQ,CAAC,OAAO,OAAO;KAC3E,CAAC;SACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;SACjB,QAAQ,CACP,MAAM,CAAC,QAAQ,EACf,IAAA,gBAAE,EACA,IAAA,gBAAE,EAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAC/C,IAAA,gBAAE,EAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAChD,CACF;SACA,KAAK,CAAC,IAAA,gBAAE,EAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;SACjC,KAAK,CAAC,CAAC,CAAC;SACR,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACb,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;QACxB,OAAO,QAAQ,CAAC,QAAQ,EAAE,eAAe,IAAI,GAAG,CAAC,CAAA;IACnD,CAAC,CAAC,CAAA;AACN,CAAC"}
|