payment-kit 1.13.34 → 1.13.35
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/api/src/routes/prices.ts +61 -0
- package/blocklet.yml +1 -1
- package/package.json +3 -3
package/api/src/routes/prices.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { fromTokenToUnit } from '@ocap/util';
|
|
2
2
|
import { Router } from 'express';
|
|
3
|
+
import Joi from 'joi';
|
|
3
4
|
import pick from 'lodash/pick';
|
|
5
|
+
import type { WhereOptions } from 'sequelize';
|
|
4
6
|
|
|
5
7
|
import { authenticate } from '../libs/security';
|
|
6
8
|
import { canUpsell } from '../libs/session';
|
|
@@ -213,4 +215,63 @@ router.delete('/:id', auth, async (req, res) => {
|
|
|
213
215
|
return res.json(price);
|
|
214
216
|
});
|
|
215
217
|
|
|
218
|
+
// list products and prices
|
|
219
|
+
const paginationSchema = Joi.object<{
|
|
220
|
+
page: number;
|
|
221
|
+
pageSize: number;
|
|
222
|
+
livemode?: boolean;
|
|
223
|
+
active?: boolean;
|
|
224
|
+
type?: string;
|
|
225
|
+
currency_id?: string;
|
|
226
|
+
product_id?: string;
|
|
227
|
+
lookup_key?: string;
|
|
228
|
+
}>({
|
|
229
|
+
page: Joi.number().integer().min(1).default(1),
|
|
230
|
+
pageSize: Joi.number().integer().min(1).max(100).default(20),
|
|
231
|
+
livemode: Joi.boolean().empty(''),
|
|
232
|
+
active: Joi.boolean().empty(''),
|
|
233
|
+
type: Joi.string().empty(''),
|
|
234
|
+
currency_id: Joi.string().empty(''),
|
|
235
|
+
product_id: Joi.string().empty(''),
|
|
236
|
+
lookup_key: Joi.string().empty(''),
|
|
237
|
+
});
|
|
238
|
+
router.get('/', auth, async (req, res) => {
|
|
239
|
+
const { page, pageSize, active, livemode, ...query } = await paginationSchema.validateAsync(req.query, {
|
|
240
|
+
stripUnknown: false,
|
|
241
|
+
allowUnknown: true,
|
|
242
|
+
});
|
|
243
|
+
const where: WhereOptions<Price> = {};
|
|
244
|
+
|
|
245
|
+
if (typeof active === 'boolean') {
|
|
246
|
+
where.active = active;
|
|
247
|
+
}
|
|
248
|
+
if (typeof livemode === 'boolean') {
|
|
249
|
+
where.livemode = livemode;
|
|
250
|
+
}
|
|
251
|
+
['type', 'currency_id', 'product_id', 'lookup_key'].forEach((key: string) => {
|
|
252
|
+
// @ts-ignore
|
|
253
|
+
if (query[key]) {
|
|
254
|
+
// @ts-ignore
|
|
255
|
+
where[key] = query[key].split(',').map((x: string) => x.trim()).filter(Boolean); // prettier-ignore
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
Object.keys(query)
|
|
260
|
+
.filter((x) => x.startsWith('recurring.'))
|
|
261
|
+
.forEach((key: string) => {
|
|
262
|
+
// @ts-ignore
|
|
263
|
+
where[key] = query[key];
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
const { rows, count } = await Price.findAndCountAll({
|
|
267
|
+
where,
|
|
268
|
+
attributes: ['id'],
|
|
269
|
+
order: [['created_at', 'DESC']],
|
|
270
|
+
offset: (page - 1) * pageSize,
|
|
271
|
+
limit: pageSize,
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
res.json({ count, list: await Promise.all(rows.map((x) => getExpandedPrice(x.id))) });
|
|
275
|
+
});
|
|
276
|
+
|
|
216
277
|
export default router;
|
package/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.35",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"@abtnode/types": "1.16.17-beta-952ef53d",
|
|
104
104
|
"@arcblock/eslint-config": "^0.2.4",
|
|
105
105
|
"@arcblock/eslint-config-ts": "^0.2.4",
|
|
106
|
-
"@did-pay/types": "1.13.
|
|
106
|
+
"@did-pay/types": "1.13.35",
|
|
107
107
|
"@types/cookie-parser": "^1.4.4",
|
|
108
108
|
"@types/cors": "^2.8.14",
|
|
109
109
|
"@types/dotenv-flow": "^3.3.1",
|
|
@@ -140,5 +140,5 @@
|
|
|
140
140
|
"parser": "typescript"
|
|
141
141
|
}
|
|
142
142
|
},
|
|
143
|
-
"gitHead": "
|
|
143
|
+
"gitHead": "25a3e75f4894d8aefb016605548c58645c0ca194"
|
|
144
144
|
}
|