bedloop 0.1.0-alpha.1 → 0.1.0-alpha.2

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 johan12361
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 johan12361
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,198 +1,198 @@
1
- # Bedloop API Client
2
-
3
- A TypeScript client for the Bedloop API with real-time messaging and booking management capabilities.
4
-
5
- ## Features
6
-
7
- - Authentication with automatic token management and retry logic
8
- - Real-time message polling from conversations
9
- - Booking management with date range queries
10
- - Auto-retry mechanism for failed requests (up to 3 attempts)
11
- - Memory-efficient cache with automatic cleanup
12
- - Automatic token refresh every 12 hours
13
- - Type-safe event system
14
- - Full TypeScript support
15
-
16
- ## Installation
17
-
18
- ```bash
19
- npm install bedloop
20
- # or
21
- pnpm add bedloop
22
- # or
23
- yarn add bedloop
24
- ```
25
-
26
- ## Quick Start
27
-
28
- ```typescript
29
- import { Client, EventType } from 'bedloop'
30
-
31
- const client = new Client(
32
- {
33
- user: 'your-username',
34
- password: 'your-password',
35
- url: 'https://your-bedloop-instance.com'
36
- },
37
- {
38
- interval: 5000,
39
- beforeDays: 7,
40
- afterDays: 30
41
- }
42
- )
43
-
44
- client.connect((events) => {
45
- events.forEach((event) => {
46
- if (event.event === EventType.NEW_MESSAGE) {
47
- console.log('New message:', event.newMessage)
48
- }
49
- })
50
- })
51
- ```
52
-
53
- ## API Reference
54
-
55
- ### Client
56
-
57
- #### Constructor
58
-
59
- ```typescript
60
- new Client(options: ClientOptions, pollingOptions?: PollingOptions)
61
- ```
62
-
63
- **ClientOptions:**
64
-
65
- - `user` (string): Username for authentication
66
- - `password` (string): Password for authentication
67
- - `url` (string): Base URL of your Bedloop instance
68
- - `debug` (boolean, optional): Enable debug logging (default: false)
69
-
70
- **PollingOptions:**
71
-
72
- - `interval` (number): Polling interval in milliseconds (default: 5000)
73
- - `beforeDays` (number): Days to look back for bookings (default: 7)
74
- - `afterDays` (number): Days to look ahead for bookings (default: 30)
75
-
76
- #### Methods
77
-
78
- **connect(callback: (events: BedloopEvent[]) => void): Promise<void>**
79
-
80
- Connects to the Bedloop API and starts polling for events. Automatically refreshes the authentication token every 12 hours.
81
-
82
- **disconnect(): void**
83
-
84
- Disconnects from the API and cleans up resources including token refresh interval.
85
-
86
- ### Event Types
87
-
88
- #### BedloopEvent
89
-
90
- ```typescript
91
- interface BedloopEvent {
92
- event: EventType
93
- timestamp: Date
94
- newMessage?: {
95
- bookingId: number
96
- conversationId: number
97
- messageId: number
98
- message: ConversationMessage
99
- }
100
- }
101
- ```
102
-
103
- #### EventType Enum
104
-
105
- ```typescript
106
- enum EventType {
107
- NEW_MESSAGE = 'new_message'
108
- }
109
- ```
110
-
111
- ## Examples
112
-
113
- ### Basic Usage
114
-
115
- ```typescript
116
- const client = new Client({
117
- user: 'username',
118
- password: 'password',
119
- url: 'https://api.bedloop.com'
120
- })
121
-
122
- await client.connect((events) => {
123
- events.forEach((event) => {
124
- console.log('Event received:', event)
125
- })
126
- })
127
- ```
128
-
129
- ### With Debug Logging
130
-
131
- ```typescript
132
- const client = new Client({
133
- user: 'username',
134
- password: 'password',
135
- url: 'https://api.bedloop.com',
136
- debug: true
137
- })
138
- ```
139
-
140
- ### Custom Polling Configuration
141
-
142
- ```typescript
143
- const client = new Client(
144
- {
145
- user: 'username',
146
- password: 'password',
147
- url: 'https://api.bedloop.com'
148
- },
149
- {
150
- interval: 10000,
151
- beforeDays: 14,
152
- afterDays: 60
153
- }
154
- )
155
- ```
156
-
157
- ### Graceful Shutdown
158
-
159
- ```typescript
160
- const client = new Client({...})
161
- await client.connect((events) => {...})
162
-
163
- // Clean up resources when done
164
- client.disconnect()
165
- ```
166
-
167
- ## Error Handling
168
-
169
- The client automatically handles:
170
-
171
- - Network failures with retry logic (3 attempts, 1 second intervals)
172
- - Token expiration with automatic refresh every 12 hours
173
- - Rate limiting with configurable polling intervals
174
-
175
- ```typescript
176
- client.connect((events) => {
177
- try {
178
- events.forEach((event) => {
179
- // Process event
180
- })
181
- } catch (error) {
182
- console.error('Error processing events:', error)
183
- }
184
- })
185
- ```
186
-
187
- ## License
188
-
189
- MIT
190
-
191
- ## Author
192
-
193
- johan12361
194
-
195
- ---
196
-
197
- **Note:** This is an alpha release. The API may change in future versions.
1
+ # Bedloop API Client
2
+
3
+ A TypeScript client for the Bedloop API with real-time messaging and booking management capabilities.
4
+
5
+ ## Features
6
+
7
+ - Authentication with automatic token management and retry logic
8
+ - Real-time message polling from conversations
9
+ - Booking management with date range queries
10
+ - Auto-retry mechanism for failed requests (up to 3 attempts)
11
+ - Memory-efficient cache with automatic cleanup
12
+ - Automatic token refresh every 12 hours
13
+ - Type-safe event system
14
+ - Full TypeScript support
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install bedloop
20
+ # or
21
+ pnpm add bedloop
22
+ # or
23
+ yarn add bedloop
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ ```typescript
29
+ import { Client, EventType } from 'bedloop'
30
+
31
+ const client = new Client(
32
+ {
33
+ user: 'your-username',
34
+ password: 'your-password',
35
+ url: 'https://your-bedloop-instance.com'
36
+ },
37
+ {
38
+ interval: 5000,
39
+ beforeDays: 7,
40
+ afterDays: 30
41
+ }
42
+ )
43
+
44
+ client.connect((events) => {
45
+ events.forEach((event) => {
46
+ if (event.event === EventType.NEW_MESSAGE) {
47
+ console.log('New message:', event.newMessage)
48
+ }
49
+ })
50
+ })
51
+ ```
52
+
53
+ ## API Reference
54
+
55
+ ### Client
56
+
57
+ #### Constructor
58
+
59
+ ```typescript
60
+ new Client(options: ClientOptions, pollingOptions?: PollingOptions)
61
+ ```
62
+
63
+ **ClientOptions:**
64
+
65
+ - `user` (string): Username for authentication
66
+ - `password` (string): Password for authentication
67
+ - `url` (string): Base URL of your Bedloop instance
68
+ - `debug` (boolean, optional): Enable debug logging (default: false)
69
+
70
+ **PollingOptions:**
71
+
72
+ - `interval` (number): Polling interval in milliseconds (default: 5000)
73
+ - `beforeDays` (number): Days to look back for bookings (default: 7)
74
+ - `afterDays` (number): Days to look ahead for bookings (default: 30)
75
+
76
+ #### Methods
77
+
78
+ **connect(callback: (events: BedloopEvent[]) => void): Promise<void>**
79
+
80
+ Connects to the Bedloop API and starts polling for events. Automatically refreshes the authentication token every 12 hours.
81
+
82
+ **disconnect(): void**
83
+
84
+ Disconnects from the API and cleans up resources including token refresh interval.
85
+
86
+ ### Event Types
87
+
88
+ #### BedloopEvent
89
+
90
+ ```typescript
91
+ interface BedloopEvent {
92
+ event: EventType
93
+ timestamp: Date
94
+ newMessage?: {
95
+ bookingId: number
96
+ conversationId: number
97
+ messageId: number
98
+ message: ConversationMessage
99
+ }
100
+ }
101
+ ```
102
+
103
+ #### EventType Enum
104
+
105
+ ```typescript
106
+ enum EventType {
107
+ NEW_MESSAGE = 'new_message'
108
+ }
109
+ ```
110
+
111
+ ## Examples
112
+
113
+ ### Basic Usage
114
+
115
+ ```typescript
116
+ const client = new Client({
117
+ user: 'username',
118
+ password: 'password',
119
+ url: 'https://api.bedloop.com'
120
+ })
121
+
122
+ await client.connect((events) => {
123
+ events.forEach((event) => {
124
+ console.log('Event received:', event)
125
+ })
126
+ })
127
+ ```
128
+
129
+ ### With Debug Logging
130
+
131
+ ```typescript
132
+ const client = new Client({
133
+ user: 'username',
134
+ password: 'password',
135
+ url: 'https://api.bedloop.com',
136
+ debug: true
137
+ })
138
+ ```
139
+
140
+ ### Custom Polling Configuration
141
+
142
+ ```typescript
143
+ const client = new Client(
144
+ {
145
+ user: 'username',
146
+ password: 'password',
147
+ url: 'https://api.bedloop.com'
148
+ },
149
+ {
150
+ interval: 10000,
151
+ beforeDays: 14,
152
+ afterDays: 60
153
+ }
154
+ )
155
+ ```
156
+
157
+ ### Graceful Shutdown
158
+
159
+ ```typescript
160
+ const client = new Client({...})
161
+ await client.connect((events) => {...})
162
+
163
+ // Clean up resources when done
164
+ client.disconnect()
165
+ ```
166
+
167
+ ## Error Handling
168
+
169
+ The client automatically handles:
170
+
171
+ - Network failures with retry logic (3 attempts, 1 second intervals)
172
+ - Token expiration with automatic refresh every 12 hours
173
+ - Rate limiting with configurable polling intervals
174
+
175
+ ```typescript
176
+ client.connect((events) => {
177
+ try {
178
+ events.forEach((event) => {
179
+ // Process event
180
+ })
181
+ } catch (error) {
182
+ console.error('Error processing events:', error)
183
+ }
184
+ })
185
+ ```
186
+
187
+ ## License
188
+
189
+ MIT
190
+
191
+ ## Author
192
+
193
+ johan12361
194
+
195
+ ---
196
+
197
+ **Note:** This is an alpha release. The API may change in future versions.
198
198
  # bedloop
package/dist/index.cjs CHANGED
@@ -256,7 +256,7 @@ async function pollingMessages(clientConfig, getAuthorization2, pollingOptions,
256
256
  try {
257
257
  const conversations = await getMessages(baseUrl, token, String(booking.booking_number));
258
258
  if (conversations.length === 0) return [];
259
- return filterNewMessages(conversations, booking.booking_number, messagesCache);
259
+ return filterNewMessages(conversations, booking.booking_number, messagesCache, pollingOptions.recentMinutes);
260
260
  } catch (error) {
261
261
  if (debug) {
262
262
  console.error(`Error getting messages for booking ${booking.booking_number}:`, error);
@@ -296,7 +296,8 @@ var defaultPollingOptions = {
296
296
  interval: 5e3,
297
297
  // 5 segundos
298
298
  beforeDays: 7,
299
- afterDays: 30
299
+ afterDays: 30,
300
+ recentMinutes: 15
300
301
  };
301
302
  var Client = class {
302
303
  constructor(options, pollingOptions = {}) {
package/dist/index.d.cts CHANGED
@@ -32,6 +32,7 @@ interface PollingOptions {
32
32
  interval: number;
33
33
  beforeDays: number;
34
34
  afterDays: number;
35
+ recentMinutes?: number;
35
36
  }
36
37
 
37
38
  declare class Client {
package/dist/index.d.ts CHANGED
@@ -32,6 +32,7 @@ interface PollingOptions {
32
32
  interval: number;
33
33
  beforeDays: number;
34
34
  afterDays: number;
35
+ recentMinutes?: number;
35
36
  }
36
37
 
37
38
  declare class Client {
package/dist/index.js CHANGED
@@ -219,7 +219,7 @@ async function pollingMessages(clientConfig, getAuthorization2, pollingOptions,
219
219
  try {
220
220
  const conversations = await getMessages(baseUrl, token, String(booking.booking_number));
221
221
  if (conversations.length === 0) return [];
222
- return filterNewMessages(conversations, booking.booking_number, messagesCache);
222
+ return filterNewMessages(conversations, booking.booking_number, messagesCache, pollingOptions.recentMinutes);
223
223
  } catch (error) {
224
224
  if (debug) {
225
225
  console.error(`Error getting messages for booking ${booking.booking_number}:`, error);
@@ -259,7 +259,8 @@ var defaultPollingOptions = {
259
259
  interval: 5e3,
260
260
  // 5 segundos
261
261
  beforeDays: 7,
262
- afterDays: 30
262
+ afterDays: 30,
263
+ recentMinutes: 15
263
264
  };
264
265
  var Client = class {
265
266
  constructor(options, pollingOptions = {}) {
package/package.json CHANGED
@@ -1,76 +1,72 @@
1
- {
2
- "name": "bedloop",
3
- "version": "0.1.0-alpha.1",
4
- "type": "module",
5
- "description": "TypeScript client for Bedloop API with real-time messaging and booking management",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "require": {
12
- "types": "./dist/index.d.cts",
13
- "default": "./dist/index.cjs"
14
- },
15
- "import": {
16
- "types": "./dist/index.d.ts",
17
- "default": "./dist/index.js"
18
- }
19
- }
20
- },
21
- "files": [
22
- "dist",
23
- "README.md",
24
- "LICENSE"
25
- ],
26
- "scripts": {
27
- "build": "tsup",
28
- "dev": "tsc --watch",
29
- "playground": "tsx playground/playground.ts",
30
- "lint": "eslint src/**/*.ts",
31
- "lint:fix": "eslint src/**/*.ts --fix",
32
- "format": "prettier --write \"src/**/*.ts\"",
33
- "typecheck": "tsc --noEmit",
34
- "test": "vitest",
35
- "test:ui": "vitest --ui",
36
- "test:run": "vitest run",
37
- "test:coverage": "vitest run --coverage",
38
- "prepublishOnly": "pnpm build"
39
- },
40
- "devDependencies": {
41
- "@types/node": "24.10.1",
42
- "@typescript-eslint/eslint-plugin": "8.48.0",
43
- "@typescript-eslint/parser": "8.48.0",
44
- "eslint": "9.39.1",
45
- "eslint-config-prettier": "10.1.8",
46
- "eslint-plugin-prettier": "5.5.4",
47
- "prettier": "3.7.3",
48
- "tsup": "8.5.1",
49
- "tsx": "4.20.6",
50
- "typescript": "5.9.3"
51
- },
52
- "keywords": [
53
- "bedloop",
54
- "api",
55
- "client",
56
- "typescript",
57
- "messaging",
58
- "booking",
59
- "real-time",
60
- "polling"
61
- ],
62
- "repository": {
63
- "type": "git",
64
- "url": "https://github.com/johan12361/bedloop.git"
65
- },
66
- "bugs": {
67
- "url": "https://github.com/johan12361/bedloop/issues"
68
- },
69
- "homepage": "https://github.com/johan12361/bedloop#readme",
70
- "author": "johan12361",
71
- "license": "MIT",
72
- "packageManager": "pnpm@10.18.3",
73
- "dependencies": {
74
- "axios": "1.13.2"
75
- }
76
- }
1
+ {
2
+ "name": "bedloop",
3
+ "version": "0.1.0-alpha.2",
4
+ "type": "module",
5
+ "description": "TypeScript client for Bedloop API with real-time messaging and booking management",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "require": {
12
+ "types": "./dist/index.d.cts",
13
+ "default": "./dist/index.cjs"
14
+ },
15
+ "import": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md",
24
+ "LICENSE"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsup",
28
+ "dev": "tsc --watch",
29
+ "playground": "tsx playground/playground.ts",
30
+ "lint": "eslint src/**/*.ts",
31
+ "lint:fix": "eslint src/**/*.ts --fix",
32
+ "format": "prettier --write \"src/**/*.ts\"",
33
+ "typecheck": "tsc --noEmit",
34
+ "prepublishOnly": "pnpm build"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "24.10.1",
38
+ "@typescript-eslint/eslint-plugin": "8.48.0",
39
+ "@typescript-eslint/parser": "8.48.0",
40
+ "eslint": "9.39.1",
41
+ "eslint-config-prettier": "10.1.8",
42
+ "eslint-plugin-prettier": "5.5.4",
43
+ "prettier": "3.7.3",
44
+ "tsup": "8.5.1",
45
+ "tsx": "4.20.6",
46
+ "typescript": "5.9.3"
47
+ },
48
+ "keywords": [
49
+ "bedloop",
50
+ "api",
51
+ "client",
52
+ "typescript",
53
+ "messaging",
54
+ "booking",
55
+ "real-time",
56
+ "polling"
57
+ ],
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "https://github.com/johan12361/bedloop.git"
61
+ },
62
+ "bugs": {
63
+ "url": "https://github.com/johan12361/bedloop/issues"
64
+ },
65
+ "homepage": "https://github.com/johan12361/bedloop#readme",
66
+ "author": "johan12361",
67
+ "license": "MIT",
68
+ "packageManager": "pnpm@10.18.3",
69
+ "dependencies": {
70
+ "axios": "1.13.2"
71
+ }
72
+ }