@vulog/aima-mobility-plans 1.1.59

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/.eslintrc.js ADDED
@@ -0,0 +1,112 @@
1
+ module.exports = {
2
+ parser: '@typescript-eslint/parser',
3
+ parserOptions: {
4
+ // Indicates the location of the TypeScript configuration file
5
+ project: 'tsconfig.json',
6
+ // Sets the root directory for the TypeScript configuration
7
+ tsconfigRootDir: __dirname,
8
+ // Specifies the version of ECMAScript syntax to be used
9
+ ecmaVersion: 'latest',
10
+ // Indicates the type of source code (script or module)
11
+ sourceType: 'module',
12
+ },
13
+ plugins: ['@typescript-eslint', 'prettier', 'import'],
14
+ extends: [
15
+ 'airbnb-base',
16
+ 'airbnb-typescript/base',
17
+ 'plugin:@typescript-eslint/recommended',
18
+ 'prettier',
19
+ 'plugin:prettier/recommended',
20
+ ],
21
+ root: true,
22
+ env: {
23
+ es6: true,
24
+ node: true,
25
+ },
26
+ ignorePatterns: [
27
+ '/dist/**/*', // Ignore built files.
28
+ '.eslintrc.js',
29
+ '**/*.test.ts',
30
+ ],
31
+ rules: {
32
+ // Configures the Prettier integration with ESLint
33
+ 'prettier/prettier': ['error', { endOfLine: 'auto' }],
34
+ // Disables the rule requiring an 'I' prefix for interfaces
35
+ '@typescript-eslint/interface-name-prefix': 'off',
36
+ // Configures the naming conventions for various code constructs
37
+ '@typescript-eslint/naming-convention': [
38
+ // ... various naming convention configurations ...
39
+ 'error',
40
+ // Allows any naming format for destructured variables
41
+ {
42
+ selector: 'variable',
43
+ modifiers: ['destructured'],
44
+ format: null,
45
+ },
46
+ // Requires strict camelCase for function names
47
+ {
48
+ selector: 'function',
49
+ format: ['strictCamelCase'],
50
+ },
51
+ // Requires boolean variables to have one of the specified prefixes
52
+ {
53
+ selector: 'variable',
54
+ format: null,
55
+ types: ['boolean'],
56
+ prefix: ['is', 'should', 'has', 'can', 'did', 'will'],
57
+ },
58
+ // Requires enum names to have a strict PascalCase format
59
+ {
60
+ selector: 'enum',
61
+ format: ['StrictPascalCase'],
62
+ },
63
+ ],
64
+ 'import/extensions': 'off',
65
+ // Disables the rule requiring explicit return types for functions
66
+ '@typescript-eslint/explicit-function-return-type': 'off',
67
+ // Disables the rule requiring explicit boundary types for modules
68
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
69
+ // Disables the rule prohibiting the use of 'any' type
70
+ '@typescript-eslint/no-explicit-any': 'off',
71
+ // Disables the rule detecting unused variables
72
+ 'no-unused-vars': 0,
73
+ // Disables the rule disallowing named exports used as a default export
74
+ 'import/no-named-as-default': 0,
75
+ // Configures the order and formatting of import statements
76
+ 'import/order': [
77
+ // ... import order configuration ...
78
+ 'error',
79
+ {
80
+ // Configure the alphabetization settings
81
+ alphabetize: {
82
+ // Enforce ascending alphabetical order
83
+ order: 'asc',
84
+ // Do not ignore the case while sorting
85
+ caseInsensitive: false,
86
+ },
87
+ // Enforce newlines between different groups and inside groups of imports
88
+ 'newlines-between': 'always-and-inside-groups',
89
+ // Warn when there is an import statement that is not part of any group
90
+ warnOnUnassignedImports: true,
91
+ },
92
+ ],
93
+ // Configures the rule detecting extraneous dependencies
94
+ 'import/no-extraneous-dependencies': [
95
+ // ... extraneous dependencies configuration ...
96
+ 'error',
97
+ {
98
+ // Specify the file patterns where devDependencies imports are allowed
99
+ devDependencies: [
100
+ // Allow devDependencies imports in test and spec files
101
+ '**/*.test.{ts,js}',
102
+ '**/*.spec.{ts,js}',
103
+ // Allow devDependencies imports in the 'test' folder
104
+ './test/**.{ts,js}',
105
+ // Allow devDependencies imports in the 'scripts' folder
106
+ './scripts/**/*.{ts,js}',
107
+ ],
108
+ },
109
+ ],
110
+ 'import/prefer-default-export': 'off',
111
+ },
112
+ };
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @vulog/aima-product
@@ -0,0 +1,54 @@
1
+ import { Client } from '@vulog/aima-client';
2
+
3
+ type Status = 'ACTIVE' | 'INACTIVE';
4
+ type Plan = {
5
+ id: string;
6
+ name: string;
7
+ fleetId: string;
8
+ period: 'WEEK' | 'MONTH' | 'YEAR';
9
+ productId: string;
10
+ systemCreditIncluded: number;
11
+ price: number;
12
+ cities: {
13
+ cityId: string;
14
+ serviceIds: string[];
15
+ }[];
16
+ status: Status;
17
+ periodicTimeWallet: {
18
+ freeMinutes: number;
19
+ freeMinutesFrequency: 'DAILY' | 'WEEKLY' | 'MONTHLY';
20
+ };
21
+ services: string[];
22
+ };
23
+ type Subscription = [
24
+ {
25
+ id: string;
26
+ profileId: string;
27
+ plan: Plan;
28
+ fleetId: string;
29
+ expiryDate: Date | null;
30
+ unsubscribeDate: Date | null;
31
+ activationDate: Date | null;
32
+ invoiceIds: string[];
33
+ status: 'ACTIVE' | 'PAYMENT_PENDING' | 'ACTIVATION_PENDING';
34
+ }
35
+ ];
36
+
37
+ declare const getPlans: (client: Client, status: Status) => Promise<Plan[]>;
38
+
39
+ declare const getUserPlans: (client: Client, entityId: string) => Promise<Subscription[]>;
40
+
41
+ type UnsubscribeResponse = {
42
+ id: string;
43
+ profileId: string;
44
+ plan: Plan;
45
+ fleetId: string;
46
+ expiryDate: string;
47
+ unsubscribeDate: string;
48
+ activationDate: string;
49
+ invoiceIds: string[];
50
+ status: 'ACTIVE' | 'PAYMENT_PENDING' | 'ACTIVATION_PENDING';
51
+ };
52
+ declare const unsubscribe: (client: Client, entityId: string, profileId: string) => Promise<UnsubscribeResponse>;
53
+
54
+ export { type Plan, type Status, type Subscription, getPlans, getUserPlans, unsubscribe };
@@ -0,0 +1,54 @@
1
+ import { Client } from '@vulog/aima-client';
2
+
3
+ type Status = 'ACTIVE' | 'INACTIVE';
4
+ type Plan = {
5
+ id: string;
6
+ name: string;
7
+ fleetId: string;
8
+ period: 'WEEK' | 'MONTH' | 'YEAR';
9
+ productId: string;
10
+ systemCreditIncluded: number;
11
+ price: number;
12
+ cities: {
13
+ cityId: string;
14
+ serviceIds: string[];
15
+ }[];
16
+ status: Status;
17
+ periodicTimeWallet: {
18
+ freeMinutes: number;
19
+ freeMinutesFrequency: 'DAILY' | 'WEEKLY' | 'MONTHLY';
20
+ };
21
+ services: string[];
22
+ };
23
+ type Subscription = [
24
+ {
25
+ id: string;
26
+ profileId: string;
27
+ plan: Plan;
28
+ fleetId: string;
29
+ expiryDate: Date | null;
30
+ unsubscribeDate: Date | null;
31
+ activationDate: Date | null;
32
+ invoiceIds: string[];
33
+ status: 'ACTIVE' | 'PAYMENT_PENDING' | 'ACTIVATION_PENDING';
34
+ }
35
+ ];
36
+
37
+ declare const getPlans: (client: Client, status: Status) => Promise<Plan[]>;
38
+
39
+ declare const getUserPlans: (client: Client, entityId: string) => Promise<Subscription[]>;
40
+
41
+ type UnsubscribeResponse = {
42
+ id: string;
43
+ profileId: string;
44
+ plan: Plan;
45
+ fleetId: string;
46
+ expiryDate: string;
47
+ unsubscribeDate: string;
48
+ activationDate: string;
49
+ invoiceIds: string[];
50
+ status: 'ACTIVE' | 'PAYMENT_PENDING' | 'ACTIVATION_PENDING';
51
+ };
52
+ declare const unsubscribe: (client: Client, entityId: string, profileId: string) => Promise<UnsubscribeResponse>;
53
+
54
+ export { type Plan, type Status, type Subscription, getPlans, getUserPlans, unsubscribe };
package/dist/index.js ADDED
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ getPlans: () => getPlans,
24
+ getUserPlans: () => getUserPlans,
25
+ unsubscribe: () => unsubscribe
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/getPlans.ts
30
+ var import_zod = require("zod");
31
+ var schema = import_zod.z.object({
32
+ status: import_zod.z.enum(["ACTIVE", "INACTIVE"])
33
+ });
34
+ var getPlans = async (client, status) => {
35
+ const result = schema.safeParse({ status });
36
+ if (!result.success) {
37
+ throw new TypeError("Invalid args", {
38
+ cause: result.error.issues
39
+ });
40
+ }
41
+ return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/plans?size=1000&status=${status}`).then(({ data }) => data);
42
+ };
43
+
44
+ // src/getUserPlans.ts
45
+ var import_zod2 = require("zod");
46
+ var schema2 = import_zod2.z.object({
47
+ entityId: import_zod2.z.string().uuid()
48
+ });
49
+ var getUserPlans = async (client, entityId) => {
50
+ const result = schema2.safeParse({ entityId });
51
+ if (!result.success) {
52
+ throw new TypeError("Invalid args", {
53
+ cause: result.error.issues
54
+ });
55
+ }
56
+ return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/subscriptions?entityId=${entityId}&status=ACTIVE,PAYMENT_PENDING,ACTIVATION_PENDING`).then(({ data }) => data);
57
+ };
58
+
59
+ // src/unsubscribe.ts
60
+ var import_zod3 = require("zod");
61
+ var schema3 = import_zod3.z.object({
62
+ entityId: import_zod3.z.string().uuid(),
63
+ profileId: import_zod3.z.string().uuid()
64
+ });
65
+ var unsubscribe = async (client, entityId, profileId) => {
66
+ const result = schema3.safeParse({ entityId, profileId });
67
+ if (!result.success) {
68
+ throw new TypeError("Invalid args", {
69
+ cause: result.error.issues
70
+ });
71
+ }
72
+ return client.post(
73
+ `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/subscriptions/${entityId}/unsubscribe`,
74
+ {
75
+ profileId
76
+ }
77
+ ).then(({ data }) => data);
78
+ };
79
+ // Annotate the CommonJS export names for ESM import in node:
80
+ 0 && (module.exports = {
81
+ getPlans,
82
+ getUserPlans,
83
+ unsubscribe
84
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,55 @@
1
+ // src/getPlans.ts
2
+ import { z } from "zod";
3
+ var schema = z.object({
4
+ status: z.enum(["ACTIVE", "INACTIVE"])
5
+ });
6
+ var getPlans = async (client, status) => {
7
+ const result = schema.safeParse({ status });
8
+ if (!result.success) {
9
+ throw new TypeError("Invalid args", {
10
+ cause: result.error.issues
11
+ });
12
+ }
13
+ return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/plans?size=1000&status=${status}`).then(({ data }) => data);
14
+ };
15
+
16
+ // src/getUserPlans.ts
17
+ import { z as z2 } from "zod";
18
+ var schema2 = z2.object({
19
+ entityId: z2.string().uuid()
20
+ });
21
+ var getUserPlans = async (client, entityId) => {
22
+ const result = schema2.safeParse({ entityId });
23
+ if (!result.success) {
24
+ throw new TypeError("Invalid args", {
25
+ cause: result.error.issues
26
+ });
27
+ }
28
+ return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/subscriptions?entityId=${entityId}&status=ACTIVE,PAYMENT_PENDING,ACTIVATION_PENDING`).then(({ data }) => data);
29
+ };
30
+
31
+ // src/unsubscribe.ts
32
+ import { z as z3 } from "zod";
33
+ var schema3 = z3.object({
34
+ entityId: z3.string().uuid(),
35
+ profileId: z3.string().uuid()
36
+ });
37
+ var unsubscribe = async (client, entityId, profileId) => {
38
+ const result = schema3.safeParse({ entityId, profileId });
39
+ if (!result.success) {
40
+ throw new TypeError("Invalid args", {
41
+ cause: result.error.issues
42
+ });
43
+ }
44
+ return client.post(
45
+ `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/subscriptions/${entityId}/unsubscribe`,
46
+ {
47
+ profileId
48
+ }
49
+ ).then(({ data }) => data);
50
+ };
51
+ export {
52
+ getPlans,
53
+ getUserPlans,
54
+ unsubscribe
55
+ };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@vulog/aima-mobility-plans",
3
+ "version": "1.1.59",
4
+ "main": "dist/index.js",
5
+ "module": "dist/index.mjs",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsup",
9
+ "dev": "tsup --watch",
10
+ "test": "vitest run",
11
+ "test:watch": "vitest",
12
+ "lint": "eslint src/**/* --ext .ts"
13
+ },
14
+ "keywords": [
15
+ "AIMA",
16
+ "VULOG",
17
+ "MOBILITY",
18
+ "PLANS"
19
+ ],
20
+ "author": "Vulog",
21
+ "license": "ISC",
22
+ "dependencies": {
23
+ "@vulog/aima-client": "1.1.59",
24
+ "@vulog/aima-core": "1.1.59"
25
+ },
26
+ "peerDependencies": {
27
+ "zod": "^3.24.2"
28
+ },
29
+ "description": ""
30
+ }
@@ -0,0 +1,79 @@
1
+ import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { Client } from '@vulog/aima-client';
3
+ import { getPlans } from './getPlans';
4
+
5
+ describe('getPlans', () => {
6
+ const FLEET_ID = 'FLEET_ID';
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
+ beforeEach(() => {
16
+ getMock.mockReset();
17
+ vi.useFakeTimers({ now: new Date('2025-01-12T13:35:50.123Z') });
18
+ });
19
+
20
+ afterEach(() => {
21
+ vi.useRealTimers();
22
+ });
23
+
24
+ test('call OK', async () => {
25
+ const data = [
26
+ {
27
+ id: 'plan1',
28
+ name: 'Plan 1',
29
+ fleetId: FLEET_ID,
30
+ period: 'MONTH',
31
+ productId: 'product1',
32
+ systemCreditIncluded: 100,
33
+ cities: [
34
+ {
35
+ cityId: 'city1',
36
+ serviceIds: ['service1', 'service2'],
37
+ },
38
+ ],
39
+ periodicTimeWallet: {
40
+ freeMinutes: 30,
41
+ freeMinutesFrequency: 'DAILY',
42
+ },
43
+ services: ['service1', 'service2'],
44
+ status: 'ACTIVE',
45
+ price: 10,
46
+ },
47
+ {
48
+ id: 'plan2',
49
+ name: 'Plan 2',
50
+ fleetId: FLEET_ID,
51
+ period: 'YEAR',
52
+ productId: 'product2',
53
+ systemCreditIncluded: 200,
54
+ cities: [
55
+ {
56
+ cityId: 'city2',
57
+ serviceIds: ['service3'],
58
+ },
59
+ ],
60
+ periodicTimeWallet: {
61
+ freeMinutes: 60,
62
+ freeMinutesFrequency: 'WEEKLY',
63
+ },
64
+ services: ['service3'],
65
+ status: 'ACTIVE',
66
+ price: 100,
67
+ },
68
+ ];
69
+ getMock.mockResolvedValueOnce({ data });
70
+
71
+ const result = await getPlans(client, 'ACTIVE');
72
+ expect(result).toEqual(data);
73
+ expect(getMock).toHaveBeenCalledWith(`/boapi/proxy/user/fleets/${FLEET_ID}/plans?size=1000&status=ACTIVE`);
74
+ });
75
+
76
+ test('call with invalid status', async () => {
77
+ await expect(getPlans(client, 'INVALID' as any)).rejects.toThrow(TypeError);
78
+ });
79
+ });
@@ -0,0 +1,20 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
3
+
4
+ import { Plan, Status } from './types';
5
+
6
+ const schema = z.object({
7
+ status: z.enum(['ACTIVE', 'INACTIVE']),
8
+ });
9
+
10
+ export const getPlans = async (client: Client, status: Status): Promise<Plan[]> => {
11
+ const result = schema.safeParse({ status });
12
+ if (!result.success) {
13
+ throw new TypeError('Invalid args', {
14
+ cause: result.error.issues,
15
+ });
16
+ }
17
+ return client
18
+ .get<Plan[]>(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/plans?size=1000&status=${status}`)
19
+ .then(({ data }) => data);
20
+ };
@@ -0,0 +1,64 @@
1
+ import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { Client } from '@vulog/aima-client';
3
+ import { getUserPlans } from './getUserPlans';
4
+
5
+ describe('getUserPlans', () => {
6
+ const FLEET_ID = 'FLEET_ID';
7
+ const ENTITY_ID = '018ab2b6-71b2-4c76-90bd-6e8d3f268618';
8
+ const getMock = vi.fn();
9
+ const client = {
10
+ get: getMock,
11
+ clientOptions: {
12
+ fleetId: FLEET_ID,
13
+ },
14
+ } as unknown as Client;
15
+
16
+ beforeEach(() => {
17
+ getMock.mockReset();
18
+ vi.useFakeTimers({ now: new Date('2025-01-12T13:35:50.123Z') });
19
+ });
20
+
21
+ afterEach(() => {
22
+ vi.useRealTimers();
23
+ });
24
+
25
+ test('call OK', async () => {
26
+ const data = [
27
+ {
28
+ id: 'plan1',
29
+ name: 'Plan 1',
30
+ fleetId: FLEET_ID,
31
+ period: 'MONTH',
32
+ productId: 'product1',
33
+ systemCreditIncluded: 100,
34
+ cities: [
35
+ {
36
+ cityId: 'city1',
37
+ serviceIds: ['service1', 'service2'],
38
+ },
39
+ ],
40
+ periodicTimeWallet: {
41
+ freeMinutes: 30,
42
+ freeMinutesFrequency: 'DAILY',
43
+ },
44
+ services: ['service1', 'service2'],
45
+ status: 'ACTIVE',
46
+ price: 10,
47
+ },
48
+ ];
49
+
50
+ getMock.mockResolvedValue({ data });
51
+
52
+ const result = await getUserPlans(client, ENTITY_ID);
53
+ expect(result).toEqual(data);
54
+ expect(getMock).toHaveBeenCalledWith(
55
+ `/boapi/proxy/user/fleets/${FLEET_ID}/subscriptions?entityId=${ENTITY_ID}&status=ACTIVE,PAYMENT_PENDING,ACTIVATION_PENDING`
56
+ );
57
+ expect(getMock).toHaveBeenCalledTimes(1);
58
+ });
59
+
60
+ test('invalid entityId', async () => {
61
+ await expect(getUserPlans(client, 'invalid-entity-id' as any)).rejects.toThrow(TypeError);
62
+ expect(getMock).not.toHaveBeenCalled();
63
+ });
64
+ });
@@ -0,0 +1,22 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
3
+
4
+ import { Subscription } from './types';
5
+
6
+ const schema = z.object({
7
+ entityId: z.string().uuid(),
8
+ });
9
+
10
+ export const getUserPlans = async (client: Client, entityId: string): Promise<Subscription[]> => {
11
+ const result = schema.safeParse({ entityId });
12
+ if (!result.success) {
13
+ throw new TypeError('Invalid args', {
14
+ cause: result.error.issues,
15
+ });
16
+ }
17
+ return client
18
+ .get<
19
+ Subscription[]
20
+ >(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/subscriptions?entityId=${entityId}&status=ACTIVE,PAYMENT_PENDING,ACTIVATION_PENDING`)
21
+ .then(({ data }) => data);
22
+ };
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { getPlans } from './getPlans';
2
+ export { getUserPlans } from './getUserPlans';
3
+ export { unsubscribe } from './unsubscribe';
4
+ export type { Plan, Status, Subscription } from './types';
package/src/types.ts ADDED
@@ -0,0 +1,35 @@
1
+ export type Status = 'ACTIVE' | 'INACTIVE';
2
+
3
+ export type Plan = {
4
+ id: string;
5
+ name: string;
6
+ fleetId: string;
7
+ period: 'WEEK' | 'MONTH' | 'YEAR';
8
+ productId: string;
9
+ systemCreditIncluded: number;
10
+ price: number;
11
+ cities: {
12
+ cityId: string;
13
+ serviceIds: string[];
14
+ }[];
15
+ status: Status;
16
+ periodicTimeWallet: {
17
+ freeMinutes: number;
18
+ freeMinutesFrequency: 'DAILY' | 'WEEKLY' | 'MONTHLY';
19
+ };
20
+ services: string[];
21
+ };
22
+
23
+ export type Subscription = [
24
+ {
25
+ id: string;
26
+ profileId: string;
27
+ plan: Plan;
28
+ fleetId: string;
29
+ expiryDate: Date | null;
30
+ unsubscribeDate: Date | null;
31
+ activationDate: Date | null;
32
+ invoiceIds: string[];
33
+ status: 'ACTIVE' | 'PAYMENT_PENDING' | 'ACTIVATION_PENDING';
34
+ },
35
+ ];
@@ -0,0 +1,43 @@
1
+ import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { Client } from '@vulog/aima-client';
3
+ import { unsubscribe } from './unsubscribe';
4
+
5
+ describe('unsubscribe', () => {
6
+ const FLEET_ID = 'FLEET_ID';
7
+ const ENTITY_ID = '018ab2b6-71b2-4c76-90bd-6e8d3f268618';
8
+ const PROFILE_ID = '61bdc58e-a6d0-4f6a-b9bd-727b17ead122';
9
+ const postMock = vi.fn();
10
+ const client = {
11
+ post: postMock,
12
+ clientOptions: {
13
+ fleetId: FLEET_ID,
14
+ },
15
+ } as unknown as Client;
16
+
17
+ beforeEach(() => {
18
+ postMock.mockReset();
19
+ vi.useFakeTimers({ now: new Date('2025-01-12T13:35:50.123Z') });
20
+ });
21
+
22
+ afterEach(() => {
23
+ vi.useRealTimers();
24
+ });
25
+
26
+ test('call OK', async () => {
27
+ const data = { success: true };
28
+ postMock.mockResolvedValue({ data });
29
+
30
+ const result = await unsubscribe(client, ENTITY_ID, PROFILE_ID);
31
+ expect(result).toEqual(data);
32
+ expect(postMock).toHaveBeenCalledWith(
33
+ `/boapi/proxy/user/fleets/${FLEET_ID}/subscriptions/${ENTITY_ID}/unsubscribe`,
34
+ { profileId: PROFILE_ID }
35
+ );
36
+ expect(postMock).toHaveBeenCalledTimes(1);
37
+ });
38
+
39
+ test('invalid entityId', async () => {
40
+ await expect(unsubscribe(client, '', '')).rejects.toThrow('Invalid args');
41
+ expect(postMock).not.toHaveBeenCalled();
42
+ });
43
+ });
@@ -0,0 +1,43 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
3
+
4
+ import { Plan } from './types';
5
+
6
+ const schema = z.object({
7
+ entityId: z.string().uuid(),
8
+ profileId: z.string().uuid(),
9
+ });
10
+
11
+ type UnsubscribeResponse = {
12
+ id: string;
13
+ profileId: string;
14
+ plan: Plan;
15
+ fleetId: string;
16
+ expiryDate: string;
17
+ unsubscribeDate: string;
18
+ activationDate: string;
19
+ invoiceIds: string[];
20
+ status: 'ACTIVE' | 'PAYMENT_PENDING' | 'ACTIVATION_PENDING';
21
+ };
22
+
23
+ export const unsubscribe = async (
24
+ client: Client,
25
+ entityId: string,
26
+ profileId: string
27
+ ): Promise<UnsubscribeResponse> => {
28
+ const result = schema.safeParse({ entityId, profileId });
29
+ if (!result.success) {
30
+ throw new TypeError('Invalid args', {
31
+ cause: result.error.issues,
32
+ });
33
+ }
34
+ // https://java-sta.vulog.com/boapi/proxy/user/fleets/LEO-CAMTR/subscriptions/c360b6d9-659f-4547-8840-58e39a753b0a/unsubscribe
35
+ return client
36
+ .post<UnsubscribeResponse>(
37
+ `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/subscriptions/${entityId}/unsubscribe`,
38
+ {
39
+ profileId,
40
+ }
41
+ )
42
+ .then(({ data }) => data);
43
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "include": ["src"],
3
+ "exclude": ["**/*.test.ts"],
4
+ "compilerOptions": {
5
+ "module": "esnext",
6
+ "target": "esnext",
7
+ "lib": ["esnext"],
8
+ "declaration": true,
9
+ "strict": true,
10
+ "moduleResolution": "node",
11
+ "skipLibCheck": true,
12
+ "esModuleInterop": true,
13
+ "outDir": "dist",
14
+ "rootDir": "src"
15
+ }
16
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ entry: ['src/index.ts'],
5
+ clean: true,
6
+ format: ['cjs', 'esm'],
7
+ dts: true,
8
+ });
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: 'node',
7
+ },
8
+ });