@vulog/aima-pricing 1.0.1 → 1.1.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.
package/dist/index.js CHANGED
@@ -25,8 +25,15 @@ __export(src_exports, {
25
25
  module.exports = __toCommonJS(src_exports);
26
26
 
27
27
  // src/getPricingById.ts
28
+ var import_zod = require("zod");
28
29
  var getPricingById = async (client, id) => {
29
- return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/products/${id}`).then(({ data }) => data);
30
+ const result = import_zod.z.string().trim().min(1).uuid().safeParse(id);
31
+ if (!result.success) {
32
+ throw new TypeError("Invalid id", {
33
+ cause: result.error.issues
34
+ });
35
+ }
36
+ return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/pricing/${id}`).then(({ data }) => data);
30
37
  };
31
38
  // Annotate the CommonJS export names for ESM import in node:
32
39
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -1,6 +1,13 @@
1
1
  // src/getPricingById.ts
2
+ import { z } from "zod";
2
3
  var getPricingById = async (client, id) => {
3
- return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/products/${id}`).then(({ data }) => data);
4
+ const result = z.string().trim().min(1).uuid().safeParse(id);
5
+ if (!result.success) {
6
+ throw new TypeError("Invalid id", {
7
+ cause: result.error.issues
8
+ });
9
+ }
10
+ return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/pricing/${id}`).then(({ data }) => data);
4
11
  };
5
12
  export {
6
13
  getPricingById
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-pricing",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,8 @@
8
8
  "build": "tsup",
9
9
  "dev": "tsup --watch",
10
10
  "test": "vitest run",
11
- "test:watch": "vitest"
11
+ "test:watch": "vitest",
12
+ "lint": "eslint src/**/* --ext .ts"
12
13
  },
13
14
  "keywords": [
14
15
  "AIMA",
@@ -18,18 +19,17 @@
18
19
  "author": "Vulog",
19
20
  "license": "ISC",
20
21
  "devDependencies": {
21
- "@types/lodash": "^4.17.12",
22
- "@types/node": "^22.7.9",
22
+ "@types/node": "^22.10.1",
23
23
  "eslint-config-airbnb-base": "^15.0.0",
24
24
  "eslint-config-airbnb-typescript": "^18.0.0",
25
25
  "eslint-config-prettier": "^9.1.0",
26
26
  "eslint-plugin-import": "^2.31.0",
27
27
  "eslint-plugin-prettier": "^5.2.1",
28
28
  "eslint-plugin-unused-imports": "^4.1.4",
29
- "prettier": "^3.3.3",
30
- "tsup": "^8.3.0",
31
- "typescript": "^5.6.3",
32
- "vitest": "^2.1.3"
29
+ "prettier": "^3.4.1",
30
+ "tsup": "^8.3.5",
31
+ "typescript": "^5.7.2",
32
+ "vitest": "^2.1.8"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@vulog/aima-client": "^1.0.0",
@@ -38,4 +38,4 @@
38
38
  "zod": "^3.23.8"
39
39
  },
40
40
  "description": ""
41
- }
41
+ }
@@ -0,0 +1,27 @@
1
+ import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { Client } from '@vulog/aima-client';
3
+ import { getPricingById } from './getPricingById';
4
+ import { randomUUID } from 'crypto';
5
+
6
+ describe('getPricingById', () => {
7
+ const getMock = vi.fn();
8
+ const client = {
9
+ get: getMock,
10
+ clientOptions: {
11
+ fleetId: 'FLEET_ID',
12
+ },
13
+ } as unknown as Client;
14
+
15
+ test('Call OK', async () => {
16
+ const pricing = {
17
+ pricingId: randomUUID(),
18
+ };
19
+ getMock.mockResolvedValue({ data: pricing });
20
+
21
+ const result = await getPricingById(client, pricing.pricingId);
22
+ expect(getMock).toHaveBeenCalledWith(
23
+ `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/pricing/${pricing.pricingId}`
24
+ );
25
+ expect(result.pricingId).toEqual(pricing.pricingId);
26
+ });
27
+ });
@@ -1,9 +1,16 @@
1
1
  import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
2
3
 
3
4
  import { Pricing } from './types';
4
5
 
5
6
  export const getPricingById = async (client: Client, id: string): Promise<Pricing> => {
7
+ const result = z.string().trim().min(1).uuid().safeParse(id);
8
+ if (!result.success) {
9
+ throw new TypeError('Invalid id', {
10
+ cause: result.error.issues,
11
+ });
12
+ }
6
13
  return client
7
- .get<Pricing>(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/products/${id}`)
14
+ .get<Pricing>(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/pricing/${id}`)
8
15
  .then(({ data }) => data);
9
16
  };