@vulog/aima-mobility-plans 1.1.60 → 1.1.61

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.d.mts CHANGED
@@ -51,4 +51,17 @@ type UnsubscribeResponse = {
51
51
  };
52
52
  declare const unsubscribe: (client: Client, entityId: string, profileId: string) => Promise<UnsubscribeResponse>;
53
53
 
54
- export { type Plan, type Status, type Subscription, getPlans, getUserPlans, unsubscribe };
54
+ type SubscribeResponse = {
55
+ id: string;
56
+ profileId: string;
57
+ plan: Plan;
58
+ fleetId: string;
59
+ expiryDate: string | null;
60
+ unsubscribeDate: string | null;
61
+ activationDate: string | null;
62
+ invoiceIds: string[];
63
+ status: 'ACTIVE' | 'PAYMENT_PENDING' | 'ACTIVATION_PENDING';
64
+ };
65
+ declare const subscribe: (client: Client, planId: string, profileId: string) => Promise<SubscribeResponse>;
66
+
67
+ export { type Plan, type Status, type Subscription, getPlans, getUserPlans, subscribe, unsubscribe };
package/dist/index.d.ts CHANGED
@@ -51,4 +51,17 @@ type UnsubscribeResponse = {
51
51
  };
52
52
  declare const unsubscribe: (client: Client, entityId: string, profileId: string) => Promise<UnsubscribeResponse>;
53
53
 
54
- export { type Plan, type Status, type Subscription, getPlans, getUserPlans, unsubscribe };
54
+ type SubscribeResponse = {
55
+ id: string;
56
+ profileId: string;
57
+ plan: Plan;
58
+ fleetId: string;
59
+ expiryDate: string | null;
60
+ unsubscribeDate: string | null;
61
+ activationDate: string | null;
62
+ invoiceIds: string[];
63
+ status: 'ACTIVE' | 'PAYMENT_PENDING' | 'ACTIVATION_PENDING';
64
+ };
65
+ declare const subscribe: (client: Client, planId: string, profileId: string) => Promise<SubscribeResponse>;
66
+
67
+ export { type Plan, type Status, type Subscription, getPlans, getUserPlans, subscribe, unsubscribe };
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  getPlans: () => getPlans,
24
24
  getUserPlans: () => getUserPlans,
25
+ subscribe: () => subscribe,
25
26
  unsubscribe: () => unsubscribe
26
27
  });
27
28
  module.exports = __toCommonJS(index_exports);
@@ -76,9 +77,29 @@ var unsubscribe = async (client, entityId, profileId) => {
76
77
  }
77
78
  ).then(({ data }) => data);
78
79
  };
80
+
81
+ // src/subscribe.ts
82
+ var import_zod4 = require("zod");
83
+ var schema4 = import_zod4.z.object({
84
+ planId: import_zod4.z.string().uuid(),
85
+ profileId: import_zod4.z.string().uuid()
86
+ });
87
+ var subscribe = async (client, planId, profileId) => {
88
+ const result = schema4.safeParse({ planId, profileId });
89
+ if (!result.success) {
90
+ throw new TypeError("Invalid args", {
91
+ cause: result.error.issues
92
+ });
93
+ }
94
+ return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/subscriptions`, {
95
+ planId,
96
+ profileId
97
+ }).then(({ data }) => data);
98
+ };
79
99
  // Annotate the CommonJS export names for ESM import in node:
80
100
  0 && (module.exports = {
81
101
  getPlans,
82
102
  getUserPlans,
103
+ subscribe,
83
104
  unsubscribe
84
105
  });
package/dist/index.mjs CHANGED
@@ -48,8 +48,28 @@ var unsubscribe = async (client, entityId, profileId) => {
48
48
  }
49
49
  ).then(({ data }) => data);
50
50
  };
51
+
52
+ // src/subscribe.ts
53
+ import { z as z4 } from "zod";
54
+ var schema4 = z4.object({
55
+ planId: z4.string().uuid(),
56
+ profileId: z4.string().uuid()
57
+ });
58
+ var subscribe = async (client, planId, profileId) => {
59
+ const result = schema4.safeParse({ planId, profileId });
60
+ if (!result.success) {
61
+ throw new TypeError("Invalid args", {
62
+ cause: result.error.issues
63
+ });
64
+ }
65
+ return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/subscriptions`, {
66
+ planId,
67
+ profileId
68
+ }).then(({ data }) => data);
69
+ };
51
70
  export {
52
71
  getPlans,
53
72
  getUserPlans,
73
+ subscribe,
54
74
  unsubscribe
55
75
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-mobility-plans",
3
- "version": "1.1.60",
3
+ "version": "1.1.61",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -20,8 +20,8 @@
20
20
  "author": "Vulog",
21
21
  "license": "ISC",
22
22
  "dependencies": {
23
- "@vulog/aima-client": "1.1.60",
24
- "@vulog/aima-core": "1.1.60"
23
+ "@vulog/aima-client": "1.1.61",
24
+ "@vulog/aima-core": "1.1.61"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "zod": "^3.24.2"
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { getPlans } from './getPlans';
2
2
  export { getUserPlans } from './getUserPlans';
3
3
  export { unsubscribe } from './unsubscribe';
4
+ export { subscribe } from './subscribe';
4
5
  export type { Plan, Status, Subscription } from './types';
@@ -0,0 +1,43 @@
1
+ import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { Client } from '@vulog/aima-client';
3
+ import { subscribe } from './subscribe';
4
+
5
+ describe('subscribe', () => {
6
+ const FLEET_ID = 'FLEET_ID';
7
+ const PLAN_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 subscribe(client, PLAN_ID, PROFILE_ID);
31
+ expect(result).toEqual(data);
32
+ expect(postMock).toHaveBeenCalledWith(`/boapi/proxy/user/fleets/${FLEET_ID}/subscriptions`, {
33
+ planId: PLAN_ID,
34
+ profileId: PROFILE_ID,
35
+ });
36
+ expect(postMock).toHaveBeenCalledTimes(1);
37
+ });
38
+
39
+ test('invalid planId or profileId', async () => {
40
+ await expect(subscribe(client, '', '')).rejects.toThrow('Invalid args');
41
+ expect(postMock).not.toHaveBeenCalled();
42
+ });
43
+ });
@@ -0,0 +1,36 @@
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
+ planId: z.string().uuid(),
8
+ profileId: z.string().uuid(),
9
+ });
10
+
11
+ type SubscribeResponse = {
12
+ id: string;
13
+ profileId: string;
14
+ plan: Plan;
15
+ fleetId: string;
16
+ expiryDate: string | null;
17
+ unsubscribeDate: string | null;
18
+ activationDate: string | null;
19
+ invoiceIds: string[];
20
+ status: 'ACTIVE' | 'PAYMENT_PENDING' | 'ACTIVATION_PENDING';
21
+ };
22
+
23
+ export const subscribe = async (client: Client, planId: string, profileId: string): Promise<SubscribeResponse> => {
24
+ const result = schema.safeParse({ planId, profileId });
25
+ if (!result.success) {
26
+ throw new TypeError('Invalid args', {
27
+ cause: result.error.issues,
28
+ });
29
+ }
30
+ return client
31
+ .post<SubscribeResponse>(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/subscriptions`, {
32
+ planId,
33
+ profileId,
34
+ })
35
+ .then(({ data }) => data);
36
+ };