order3000 0.3.1 → 0.6.0
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/client.cjs +42 -29
- package/dist/client.d.cts +100 -21
- package/dist/client.d.mts +100 -21
- package/dist/client.mjs +42 -29
- package/package.json +3 -3
package/dist/client.cjs
CHANGED
|
@@ -6,15 +6,15 @@ var __defProp$1 = Object.defineProperty;
|
|
|
6
6
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
7
|
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
8
|
class TokenManager {
|
|
9
|
-
constructor(clientId, clientSecret, tokenEndpoint,
|
|
9
|
+
constructor(clientId, clientSecret, tokenEndpoint, userVenueId) {
|
|
10
10
|
this.clientId = clientId;
|
|
11
11
|
this.clientSecret = clientSecret;
|
|
12
12
|
this.tokenEndpoint = tokenEndpoint;
|
|
13
|
-
this.
|
|
13
|
+
this.userVenueId = userVenueId;
|
|
14
14
|
__publicField$1(this, "accessToken", null);
|
|
15
15
|
__publicField$1(this, "tokenExpiresAt", 0);
|
|
16
16
|
__publicField$1(this, "refreshPromise", null);
|
|
17
|
-
__publicField$1(this, "
|
|
17
|
+
__publicField$1(this, "defaultVenueId");
|
|
18
18
|
}
|
|
19
19
|
async initialize() {
|
|
20
20
|
await this.refreshToken();
|
|
@@ -25,46 +25,49 @@ class TokenManager {
|
|
|
25
25
|
}
|
|
26
26
|
return this.refreshToken();
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
if (this.
|
|
30
|
-
if (!this.
|
|
31
|
-
return this.
|
|
28
|
+
getVenueId() {
|
|
29
|
+
if (this.userVenueId) return this.userVenueId;
|
|
30
|
+
if (!this.defaultVenueId) throw new Error("No venue ID available");
|
|
31
|
+
return this.defaultVenueId;
|
|
32
32
|
}
|
|
33
33
|
async refreshToken() {
|
|
34
|
-
console.log("refreshToken 1");
|
|
35
34
|
if (this.refreshPromise) return this.refreshPromise;
|
|
36
|
-
console.log("
|
|
35
|
+
console.log("[SDK TOKEN] Requesting token from:", this.tokenEndpoint);
|
|
36
|
+
console.log("[SDK TOKEN] Using clientId:", this.clientId);
|
|
37
|
+
console.log("[SDK TOKEN] Secret length:", this.clientSecret?.length);
|
|
37
38
|
this.refreshPromise = got.post(this.tokenEndpoint, {
|
|
38
39
|
json: { clientId: this.clientId, clientSecret: this.clientSecret },
|
|
39
40
|
responseType: "json",
|
|
40
41
|
timeout: { request: 36e4 },
|
|
41
42
|
retry: { limit: 3 }
|
|
42
43
|
}).then((response) => {
|
|
43
|
-
console.log("
|
|
44
|
+
console.log("[SDK TOKEN] Token received successfully");
|
|
44
45
|
this.accessToken = response.body.accessToken;
|
|
45
46
|
this.tokenExpiresAt = Date.now() + response.body.expiresIn * 1e3;
|
|
46
|
-
this.
|
|
47
|
+
this.setDefaultVenueId();
|
|
47
48
|
return this.accessToken;
|
|
49
|
+
}).catch((error) => {
|
|
50
|
+
console.log("[SDK TOKEN] Token request failed:", error.message);
|
|
51
|
+
if (error.response) {
|
|
52
|
+
console.log("[SDK TOKEN] Response status:", error.response.statusCode);
|
|
53
|
+
console.log("[SDK TOKEN] Response body:", error.response.body);
|
|
54
|
+
}
|
|
55
|
+
throw error;
|
|
48
56
|
}).finally(() => {
|
|
49
|
-
console.log("refreshToken 4");
|
|
50
57
|
this.refreshPromise = null;
|
|
51
58
|
});
|
|
52
|
-
console.log("refreshToken 5");
|
|
53
59
|
return this.refreshPromise;
|
|
54
60
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (this.userTenantId || !this.accessToken) return;
|
|
61
|
+
setDefaultVenueId() {
|
|
62
|
+
if (this.userVenueId || !this.accessToken) return;
|
|
58
63
|
try {
|
|
59
|
-
console.log("refreshToken 7");
|
|
60
64
|
const [, payload] = this.accessToken.split(".");
|
|
61
65
|
const decoded = JSON.parse(
|
|
62
66
|
Buffer.from(payload, "base64").toString()
|
|
63
67
|
);
|
|
64
|
-
this.
|
|
68
|
+
this.defaultVenueId = decoded.tenants?.[0];
|
|
65
69
|
} catch (error) {
|
|
66
|
-
|
|
67
|
-
throw new Error("Failed to parse tenant ID from token");
|
|
70
|
+
throw new Error("Failed to parse venue ID from token");
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
}
|
|
@@ -77,9 +80,11 @@ class BaseResource {
|
|
|
77
80
|
}
|
|
78
81
|
async request(method, path, data) {
|
|
79
82
|
const token = await this.tokenManager.getToken();
|
|
80
|
-
const
|
|
83
|
+
const venueId = this.tokenManager.getVenueId();
|
|
84
|
+
const url = `${this.baseUrl}/venues/${venueId}${this.resourcePath}${path}`;
|
|
85
|
+
console.log(`[SDK] Making ${method} request to: ${url}`);
|
|
81
86
|
return got(
|
|
82
|
-
|
|
87
|
+
url,
|
|
83
88
|
{
|
|
84
89
|
method,
|
|
85
90
|
json: data,
|
|
@@ -92,6 +97,18 @@ class BaseResource {
|
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
|
|
100
|
+
class EventsResource extends BaseResource {
|
|
101
|
+
constructor(tokenManager, baseUrl) {
|
|
102
|
+
super(tokenManager, baseUrl, "/events");
|
|
103
|
+
}
|
|
104
|
+
async place(event) {
|
|
105
|
+
return this.request("POST", "", event);
|
|
106
|
+
}
|
|
107
|
+
async get(eventId) {
|
|
108
|
+
return this.request("GET", `/${eventId}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
95
112
|
class OrdersResource extends BaseResource {
|
|
96
113
|
constructor(tokenManager, baseUrl) {
|
|
97
114
|
super(tokenManager, baseUrl, "/orders");
|
|
@@ -131,6 +148,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
131
148
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
132
149
|
class Order3000Client {
|
|
133
150
|
constructor(config) {
|
|
151
|
+
__publicField(this, "events");
|
|
134
152
|
__publicField(this, "orders");
|
|
135
153
|
__publicField(this, "reservations");
|
|
136
154
|
__publicField(this, "baseUrl");
|
|
@@ -141,25 +159,20 @@ class Order3000Client {
|
|
|
141
159
|
config.clientId,
|
|
142
160
|
config.clientSecret,
|
|
143
161
|
tokenUrl,
|
|
144
|
-
config.
|
|
162
|
+
config.venueId
|
|
145
163
|
);
|
|
146
|
-
|
|
164
|
+
this.events = new EventsResource(this.tokenManager, this.baseUrl);
|
|
147
165
|
this.orders = new OrdersResource(this.tokenManager, this.baseUrl);
|
|
148
166
|
this.reservations = new ReservationsResource(
|
|
149
167
|
this.tokenManager,
|
|
150
168
|
this.baseUrl
|
|
151
169
|
);
|
|
152
|
-
console.log("refreshToken 13");
|
|
153
170
|
this.initialize();
|
|
154
|
-
console.log("refreshToken 14");
|
|
155
171
|
}
|
|
156
172
|
async initialize() {
|
|
157
173
|
try {
|
|
158
|
-
console.log("refreshToken 9");
|
|
159
174
|
await this.tokenManager.initialize();
|
|
160
|
-
console.log("refreshToken 10");
|
|
161
175
|
} catch (error) {
|
|
162
|
-
console.log("refreshToken 11");
|
|
163
176
|
console.error("Failed to initialize client:", error);
|
|
164
177
|
process.exit(1);
|
|
165
178
|
}
|
package/dist/client.d.cts
CHANGED
|
@@ -2,17 +2,17 @@ declare class TokenManager {
|
|
|
2
2
|
private readonly clientId;
|
|
3
3
|
private readonly clientSecret;
|
|
4
4
|
private readonly tokenEndpoint;
|
|
5
|
-
private readonly
|
|
5
|
+
private readonly userVenueId?;
|
|
6
6
|
private accessToken;
|
|
7
7
|
private tokenExpiresAt;
|
|
8
8
|
private refreshPromise;
|
|
9
|
-
private
|
|
10
|
-
constructor(clientId: string, clientSecret: string, tokenEndpoint: string,
|
|
9
|
+
private defaultVenueId?;
|
|
10
|
+
constructor(clientId: string, clientSecret: string, tokenEndpoint: string, userVenueId?: string | undefined);
|
|
11
11
|
initialize(): Promise<void>;
|
|
12
12
|
getToken(): Promise<string>;
|
|
13
|
-
|
|
13
|
+
getVenueId(): string;
|
|
14
14
|
private refreshToken;
|
|
15
|
-
private
|
|
15
|
+
private setDefaultVenueId;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
declare abstract class BaseResource {
|
|
@@ -27,11 +27,11 @@ interface components {
|
|
|
27
27
|
schemas: {
|
|
28
28
|
/**
|
|
29
29
|
* PlaceOrderRequest
|
|
30
|
-
* @description Place a new order for a specific
|
|
30
|
+
* @description Place a new order for a specific venue
|
|
31
31
|
*/
|
|
32
32
|
PlaceOrderRequest: {
|
|
33
33
|
id?: string;
|
|
34
|
-
|
|
34
|
+
venueId: string;
|
|
35
35
|
basketId: string;
|
|
36
36
|
/** @enum {string} */
|
|
37
37
|
status?: "DRAFT" | "PENDING" | "PAID" | "FULFILLED" | "CANCELLED" | "REFUNDED";
|
|
@@ -51,7 +51,7 @@ interface components {
|
|
|
51
51
|
/** PlaceOrderResponse */
|
|
52
52
|
PlaceOrderResponse: {
|
|
53
53
|
id: string;
|
|
54
|
-
|
|
54
|
+
venueId: string;
|
|
55
55
|
basketId: string;
|
|
56
56
|
/** @enum {string} */
|
|
57
57
|
status: "DRAFT" | "PENDING" | "PAID" | "FULFILLED" | "CANCELLED" | "REFUNDED";
|
|
@@ -73,6 +73,11 @@ interface components {
|
|
|
73
73
|
* @description Request payload for making a new reservation
|
|
74
74
|
*/
|
|
75
75
|
MakeReservationRequest: {
|
|
76
|
+
/**
|
|
77
|
+
* Format: uuid
|
|
78
|
+
* @description UUID of the event this reservation is for
|
|
79
|
+
*/
|
|
80
|
+
eventId: string;
|
|
76
81
|
/** @description Date of the reservation in YYYY-MM-DD format */
|
|
77
82
|
reservationDate: string;
|
|
78
83
|
/** @description Time of the reservation in HH:MM:SS format */
|
|
@@ -86,8 +91,10 @@ interface components {
|
|
|
86
91
|
* @description UUID of existing customer profile if available
|
|
87
92
|
*/
|
|
88
93
|
customerId: string | null;
|
|
89
|
-
/** @description
|
|
90
|
-
|
|
94
|
+
/** @description First name of the customer making the reservation */
|
|
95
|
+
customerFirstName: string;
|
|
96
|
+
/** @description Last name of the customer making the reservation */
|
|
97
|
+
customerLastName: string;
|
|
91
98
|
/**
|
|
92
99
|
* Format: email
|
|
93
100
|
* @description Email address for reservation confirmations and updates
|
|
@@ -124,7 +131,12 @@ interface components {
|
|
|
124
131
|
* Format: uuid
|
|
125
132
|
* @description Restaurant/tenant identifier
|
|
126
133
|
*/
|
|
127
|
-
|
|
134
|
+
venueId: string;
|
|
135
|
+
/**
|
|
136
|
+
* Format: uuid
|
|
137
|
+
* @description Event identifier for this reservation
|
|
138
|
+
*/
|
|
139
|
+
eventId: string;
|
|
128
140
|
/** @description Date of the reservation in YYYY-MM-DD format */
|
|
129
141
|
reservationDate: string;
|
|
130
142
|
/** @description Time of the reservation in HH:MM:SS format */
|
|
@@ -138,8 +150,10 @@ interface components {
|
|
|
138
150
|
* @description Link to customer profile if exists
|
|
139
151
|
*/
|
|
140
152
|
customerId: string | null;
|
|
141
|
-
/** @description
|
|
142
|
-
|
|
153
|
+
/** @description First name of the customer */
|
|
154
|
+
customerFirstName: string;
|
|
155
|
+
/** @description Last name of the customer */
|
|
156
|
+
customerLastName: string;
|
|
143
157
|
/** @description Customer email address */
|
|
144
158
|
customerEmail: string | null;
|
|
145
159
|
/** @description Customer phone number */
|
|
@@ -198,9 +212,9 @@ interface components {
|
|
|
198
212
|
/** @description Preferred seating location */
|
|
199
213
|
tablePreference: string | null;
|
|
200
214
|
/** @description User ID who created the reservation */
|
|
201
|
-
createdBy: string;
|
|
215
|
+
createdBy: string | null;
|
|
202
216
|
/** @description User ID who last updated the reservation */
|
|
203
|
-
updatedBy: string;
|
|
217
|
+
updatedBy: string | null;
|
|
204
218
|
/**
|
|
205
219
|
* Format: date-time
|
|
206
220
|
* @description Reservation creation timestamp
|
|
@@ -226,7 +240,12 @@ interface components {
|
|
|
226
240
|
* Format: uuid
|
|
227
241
|
* @description Restaurant/tenant identifier
|
|
228
242
|
*/
|
|
229
|
-
|
|
243
|
+
venueId: string;
|
|
244
|
+
/**
|
|
245
|
+
* Format: uuid
|
|
246
|
+
* @description Event identifier for this reservation
|
|
247
|
+
*/
|
|
248
|
+
eventId: string;
|
|
230
249
|
/** @description Date of the reservation in YYYY-MM-DD format */
|
|
231
250
|
reservationDate: string;
|
|
232
251
|
/** @description Time of the reservation in HH:MM:SS format */
|
|
@@ -240,8 +259,10 @@ interface components {
|
|
|
240
259
|
* @description Link to customer profile if exists
|
|
241
260
|
*/
|
|
242
261
|
customerId: string | null;
|
|
243
|
-
/** @description
|
|
244
|
-
|
|
262
|
+
/** @description First name of the customer */
|
|
263
|
+
customerFirstName: string;
|
|
264
|
+
/** @description Last name of the customer */
|
|
265
|
+
customerLastName: string;
|
|
245
266
|
/** @description Customer email address */
|
|
246
267
|
customerEmail: string | null;
|
|
247
268
|
/** @description Customer phone number */
|
|
@@ -300,9 +321,9 @@ interface components {
|
|
|
300
321
|
/** @description Preferred seating location */
|
|
301
322
|
tablePreference: string | null;
|
|
302
323
|
/** @description User ID who created the reservation */
|
|
303
|
-
createdBy: string;
|
|
324
|
+
createdBy: string | null;
|
|
304
325
|
/** @description User ID who last updated the reservation */
|
|
305
|
-
updatedBy: string;
|
|
326
|
+
updatedBy: string | null;
|
|
306
327
|
/**
|
|
307
328
|
* Format: date-time
|
|
308
329
|
* @description Reservation creation timestamp
|
|
@@ -314,6 +335,55 @@ interface components {
|
|
|
314
335
|
*/
|
|
315
336
|
updatedAt: string | null;
|
|
316
337
|
};
|
|
338
|
+
/**
|
|
339
|
+
* CreateEventRequest
|
|
340
|
+
* @description Request payload for creating a new event
|
|
341
|
+
*/
|
|
342
|
+
CreateEventRequest: {
|
|
343
|
+
venueId: string;
|
|
344
|
+
/** @enum {string} */
|
|
345
|
+
type: "regular" | "private" | "closure" | "maintenance";
|
|
346
|
+
name: (((string | number | boolean | (string | null)) | null) | {
|
|
347
|
+
[key: string]: unknown;
|
|
348
|
+
} | unknown[]) | null;
|
|
349
|
+
description?: (((string | number | boolean | (string | null)) | null) | {
|
|
350
|
+
[key: string]: unknown;
|
|
351
|
+
} | unknown[]) | null;
|
|
352
|
+
scheduleId?: string | null;
|
|
353
|
+
maxBookings?: number | null;
|
|
354
|
+
maxGuests?: number | null;
|
|
355
|
+
minPartySize?: number | null;
|
|
356
|
+
maxPartySize?: number | null;
|
|
357
|
+
isActive?: boolean;
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* CreateEventResponse
|
|
361
|
+
* @description Successfully created event
|
|
362
|
+
*/
|
|
363
|
+
CreateEventResponse: {
|
|
364
|
+
id: string;
|
|
365
|
+
venueId: string;
|
|
366
|
+
/** @enum {string} */
|
|
367
|
+
type: "regular" | "private" | "closure" | "maintenance";
|
|
368
|
+
name: (((string | number | boolean | (string | null)) | null) | {
|
|
369
|
+
[key: string]: unknown;
|
|
370
|
+
} | unknown[]) | null;
|
|
371
|
+
description: (((string | number | boolean | (string | null)) | null) | {
|
|
372
|
+
[key: string]: unknown;
|
|
373
|
+
} | unknown[]) | null;
|
|
374
|
+
scheduleId: string | null;
|
|
375
|
+
maxBookings: number | null;
|
|
376
|
+
maxGuests: number | null;
|
|
377
|
+
minPartySize: number | null;
|
|
378
|
+
maxPartySize: number | null;
|
|
379
|
+
isActive: boolean;
|
|
380
|
+
createdBy: string | null;
|
|
381
|
+
updatedBy: string | null;
|
|
382
|
+
/** Format: date-time */
|
|
383
|
+
createdAt: string | null;
|
|
384
|
+
/** Format: date-time */
|
|
385
|
+
updatedAt: string | null;
|
|
386
|
+
};
|
|
317
387
|
};
|
|
318
388
|
responses: never;
|
|
319
389
|
parameters: never;
|
|
@@ -323,11 +393,19 @@ interface components {
|
|
|
323
393
|
}
|
|
324
394
|
|
|
325
395
|
type schemas = components['schemas'];
|
|
396
|
+
type CreateEventRequest = schemas['CreateEventRequest'];
|
|
397
|
+
type CreateEventResponse = schemas['CreateEventResponse'];
|
|
326
398
|
type PlaceOrderRequest = schemas['PlaceOrderRequest'];
|
|
327
399
|
type PlaceOrderResponse = schemas['PlaceOrderResponse'];
|
|
328
400
|
type MakeReservationRequest = schemas['MakeReservationRequest'];
|
|
329
401
|
type MakeReservationResponse = schemas['MakeReservationResponse'];
|
|
330
402
|
|
|
403
|
+
declare class EventsResource extends BaseResource {
|
|
404
|
+
constructor(tokenManager: TokenManager, baseUrl: string);
|
|
405
|
+
place(event: CreateEventRequest): Promise<CreateEventResponse>;
|
|
406
|
+
get(eventId: string): Promise<CreateEventRequest>;
|
|
407
|
+
}
|
|
408
|
+
|
|
331
409
|
declare class OrdersResource extends BaseResource {
|
|
332
410
|
constructor(tokenManager: TokenManager, baseUrl: string);
|
|
333
411
|
place(order: PlaceOrderRequest): Promise<PlaceOrderResponse>;
|
|
@@ -353,7 +431,7 @@ declare class ReservationsResource extends BaseResource {
|
|
|
353
431
|
interface Order3000ClientConfig {
|
|
354
432
|
clientId: string;
|
|
355
433
|
clientSecret: string;
|
|
356
|
-
|
|
434
|
+
venueId?: string;
|
|
357
435
|
/**
|
|
358
436
|
* Base URL for API requests
|
|
359
437
|
* @default "https://order3000.com/api"
|
|
@@ -366,6 +444,7 @@ interface Order3000ClientConfig {
|
|
|
366
444
|
tokenUrl?: string;
|
|
367
445
|
}
|
|
368
446
|
declare class Order3000Client {
|
|
447
|
+
events: EventsResource;
|
|
369
448
|
orders: OrdersResource;
|
|
370
449
|
reservations: ReservationsResource;
|
|
371
450
|
private readonly baseUrl;
|
package/dist/client.d.mts
CHANGED
|
@@ -2,17 +2,17 @@ declare class TokenManager {
|
|
|
2
2
|
private readonly clientId;
|
|
3
3
|
private readonly clientSecret;
|
|
4
4
|
private readonly tokenEndpoint;
|
|
5
|
-
private readonly
|
|
5
|
+
private readonly userVenueId?;
|
|
6
6
|
private accessToken;
|
|
7
7
|
private tokenExpiresAt;
|
|
8
8
|
private refreshPromise;
|
|
9
|
-
private
|
|
10
|
-
constructor(clientId: string, clientSecret: string, tokenEndpoint: string,
|
|
9
|
+
private defaultVenueId?;
|
|
10
|
+
constructor(clientId: string, clientSecret: string, tokenEndpoint: string, userVenueId?: string | undefined);
|
|
11
11
|
initialize(): Promise<void>;
|
|
12
12
|
getToken(): Promise<string>;
|
|
13
|
-
|
|
13
|
+
getVenueId(): string;
|
|
14
14
|
private refreshToken;
|
|
15
|
-
private
|
|
15
|
+
private setDefaultVenueId;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
declare abstract class BaseResource {
|
|
@@ -27,11 +27,11 @@ interface components {
|
|
|
27
27
|
schemas: {
|
|
28
28
|
/**
|
|
29
29
|
* PlaceOrderRequest
|
|
30
|
-
* @description Place a new order for a specific
|
|
30
|
+
* @description Place a new order for a specific venue
|
|
31
31
|
*/
|
|
32
32
|
PlaceOrderRequest: {
|
|
33
33
|
id?: string;
|
|
34
|
-
|
|
34
|
+
venueId: string;
|
|
35
35
|
basketId: string;
|
|
36
36
|
/** @enum {string} */
|
|
37
37
|
status?: "DRAFT" | "PENDING" | "PAID" | "FULFILLED" | "CANCELLED" | "REFUNDED";
|
|
@@ -51,7 +51,7 @@ interface components {
|
|
|
51
51
|
/** PlaceOrderResponse */
|
|
52
52
|
PlaceOrderResponse: {
|
|
53
53
|
id: string;
|
|
54
|
-
|
|
54
|
+
venueId: string;
|
|
55
55
|
basketId: string;
|
|
56
56
|
/** @enum {string} */
|
|
57
57
|
status: "DRAFT" | "PENDING" | "PAID" | "FULFILLED" | "CANCELLED" | "REFUNDED";
|
|
@@ -73,6 +73,11 @@ interface components {
|
|
|
73
73
|
* @description Request payload for making a new reservation
|
|
74
74
|
*/
|
|
75
75
|
MakeReservationRequest: {
|
|
76
|
+
/**
|
|
77
|
+
* Format: uuid
|
|
78
|
+
* @description UUID of the event this reservation is for
|
|
79
|
+
*/
|
|
80
|
+
eventId: string;
|
|
76
81
|
/** @description Date of the reservation in YYYY-MM-DD format */
|
|
77
82
|
reservationDate: string;
|
|
78
83
|
/** @description Time of the reservation in HH:MM:SS format */
|
|
@@ -86,8 +91,10 @@ interface components {
|
|
|
86
91
|
* @description UUID of existing customer profile if available
|
|
87
92
|
*/
|
|
88
93
|
customerId: string | null;
|
|
89
|
-
/** @description
|
|
90
|
-
|
|
94
|
+
/** @description First name of the customer making the reservation */
|
|
95
|
+
customerFirstName: string;
|
|
96
|
+
/** @description Last name of the customer making the reservation */
|
|
97
|
+
customerLastName: string;
|
|
91
98
|
/**
|
|
92
99
|
* Format: email
|
|
93
100
|
* @description Email address for reservation confirmations and updates
|
|
@@ -124,7 +131,12 @@ interface components {
|
|
|
124
131
|
* Format: uuid
|
|
125
132
|
* @description Restaurant/tenant identifier
|
|
126
133
|
*/
|
|
127
|
-
|
|
134
|
+
venueId: string;
|
|
135
|
+
/**
|
|
136
|
+
* Format: uuid
|
|
137
|
+
* @description Event identifier for this reservation
|
|
138
|
+
*/
|
|
139
|
+
eventId: string;
|
|
128
140
|
/** @description Date of the reservation in YYYY-MM-DD format */
|
|
129
141
|
reservationDate: string;
|
|
130
142
|
/** @description Time of the reservation in HH:MM:SS format */
|
|
@@ -138,8 +150,10 @@ interface components {
|
|
|
138
150
|
* @description Link to customer profile if exists
|
|
139
151
|
*/
|
|
140
152
|
customerId: string | null;
|
|
141
|
-
/** @description
|
|
142
|
-
|
|
153
|
+
/** @description First name of the customer */
|
|
154
|
+
customerFirstName: string;
|
|
155
|
+
/** @description Last name of the customer */
|
|
156
|
+
customerLastName: string;
|
|
143
157
|
/** @description Customer email address */
|
|
144
158
|
customerEmail: string | null;
|
|
145
159
|
/** @description Customer phone number */
|
|
@@ -198,9 +212,9 @@ interface components {
|
|
|
198
212
|
/** @description Preferred seating location */
|
|
199
213
|
tablePreference: string | null;
|
|
200
214
|
/** @description User ID who created the reservation */
|
|
201
|
-
createdBy: string;
|
|
215
|
+
createdBy: string | null;
|
|
202
216
|
/** @description User ID who last updated the reservation */
|
|
203
|
-
updatedBy: string;
|
|
217
|
+
updatedBy: string | null;
|
|
204
218
|
/**
|
|
205
219
|
* Format: date-time
|
|
206
220
|
* @description Reservation creation timestamp
|
|
@@ -226,7 +240,12 @@ interface components {
|
|
|
226
240
|
* Format: uuid
|
|
227
241
|
* @description Restaurant/tenant identifier
|
|
228
242
|
*/
|
|
229
|
-
|
|
243
|
+
venueId: string;
|
|
244
|
+
/**
|
|
245
|
+
* Format: uuid
|
|
246
|
+
* @description Event identifier for this reservation
|
|
247
|
+
*/
|
|
248
|
+
eventId: string;
|
|
230
249
|
/** @description Date of the reservation in YYYY-MM-DD format */
|
|
231
250
|
reservationDate: string;
|
|
232
251
|
/** @description Time of the reservation in HH:MM:SS format */
|
|
@@ -240,8 +259,10 @@ interface components {
|
|
|
240
259
|
* @description Link to customer profile if exists
|
|
241
260
|
*/
|
|
242
261
|
customerId: string | null;
|
|
243
|
-
/** @description
|
|
244
|
-
|
|
262
|
+
/** @description First name of the customer */
|
|
263
|
+
customerFirstName: string;
|
|
264
|
+
/** @description Last name of the customer */
|
|
265
|
+
customerLastName: string;
|
|
245
266
|
/** @description Customer email address */
|
|
246
267
|
customerEmail: string | null;
|
|
247
268
|
/** @description Customer phone number */
|
|
@@ -300,9 +321,9 @@ interface components {
|
|
|
300
321
|
/** @description Preferred seating location */
|
|
301
322
|
tablePreference: string | null;
|
|
302
323
|
/** @description User ID who created the reservation */
|
|
303
|
-
createdBy: string;
|
|
324
|
+
createdBy: string | null;
|
|
304
325
|
/** @description User ID who last updated the reservation */
|
|
305
|
-
updatedBy: string;
|
|
326
|
+
updatedBy: string | null;
|
|
306
327
|
/**
|
|
307
328
|
* Format: date-time
|
|
308
329
|
* @description Reservation creation timestamp
|
|
@@ -314,6 +335,55 @@ interface components {
|
|
|
314
335
|
*/
|
|
315
336
|
updatedAt: string | null;
|
|
316
337
|
};
|
|
338
|
+
/**
|
|
339
|
+
* CreateEventRequest
|
|
340
|
+
* @description Request payload for creating a new event
|
|
341
|
+
*/
|
|
342
|
+
CreateEventRequest: {
|
|
343
|
+
venueId: string;
|
|
344
|
+
/** @enum {string} */
|
|
345
|
+
type: "regular" | "private" | "closure" | "maintenance";
|
|
346
|
+
name: (((string | number | boolean | (string | null)) | null) | {
|
|
347
|
+
[key: string]: unknown;
|
|
348
|
+
} | unknown[]) | null;
|
|
349
|
+
description?: (((string | number | boolean | (string | null)) | null) | {
|
|
350
|
+
[key: string]: unknown;
|
|
351
|
+
} | unknown[]) | null;
|
|
352
|
+
scheduleId?: string | null;
|
|
353
|
+
maxBookings?: number | null;
|
|
354
|
+
maxGuests?: number | null;
|
|
355
|
+
minPartySize?: number | null;
|
|
356
|
+
maxPartySize?: number | null;
|
|
357
|
+
isActive?: boolean;
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* CreateEventResponse
|
|
361
|
+
* @description Successfully created event
|
|
362
|
+
*/
|
|
363
|
+
CreateEventResponse: {
|
|
364
|
+
id: string;
|
|
365
|
+
venueId: string;
|
|
366
|
+
/** @enum {string} */
|
|
367
|
+
type: "regular" | "private" | "closure" | "maintenance";
|
|
368
|
+
name: (((string | number | boolean | (string | null)) | null) | {
|
|
369
|
+
[key: string]: unknown;
|
|
370
|
+
} | unknown[]) | null;
|
|
371
|
+
description: (((string | number | boolean | (string | null)) | null) | {
|
|
372
|
+
[key: string]: unknown;
|
|
373
|
+
} | unknown[]) | null;
|
|
374
|
+
scheduleId: string | null;
|
|
375
|
+
maxBookings: number | null;
|
|
376
|
+
maxGuests: number | null;
|
|
377
|
+
minPartySize: number | null;
|
|
378
|
+
maxPartySize: number | null;
|
|
379
|
+
isActive: boolean;
|
|
380
|
+
createdBy: string | null;
|
|
381
|
+
updatedBy: string | null;
|
|
382
|
+
/** Format: date-time */
|
|
383
|
+
createdAt: string | null;
|
|
384
|
+
/** Format: date-time */
|
|
385
|
+
updatedAt: string | null;
|
|
386
|
+
};
|
|
317
387
|
};
|
|
318
388
|
responses: never;
|
|
319
389
|
parameters: never;
|
|
@@ -323,11 +393,19 @@ interface components {
|
|
|
323
393
|
}
|
|
324
394
|
|
|
325
395
|
type schemas = components['schemas'];
|
|
396
|
+
type CreateEventRequest = schemas['CreateEventRequest'];
|
|
397
|
+
type CreateEventResponse = schemas['CreateEventResponse'];
|
|
326
398
|
type PlaceOrderRequest = schemas['PlaceOrderRequest'];
|
|
327
399
|
type PlaceOrderResponse = schemas['PlaceOrderResponse'];
|
|
328
400
|
type MakeReservationRequest = schemas['MakeReservationRequest'];
|
|
329
401
|
type MakeReservationResponse = schemas['MakeReservationResponse'];
|
|
330
402
|
|
|
403
|
+
declare class EventsResource extends BaseResource {
|
|
404
|
+
constructor(tokenManager: TokenManager, baseUrl: string);
|
|
405
|
+
place(event: CreateEventRequest): Promise<CreateEventResponse>;
|
|
406
|
+
get(eventId: string): Promise<CreateEventRequest>;
|
|
407
|
+
}
|
|
408
|
+
|
|
331
409
|
declare class OrdersResource extends BaseResource {
|
|
332
410
|
constructor(tokenManager: TokenManager, baseUrl: string);
|
|
333
411
|
place(order: PlaceOrderRequest): Promise<PlaceOrderResponse>;
|
|
@@ -353,7 +431,7 @@ declare class ReservationsResource extends BaseResource {
|
|
|
353
431
|
interface Order3000ClientConfig {
|
|
354
432
|
clientId: string;
|
|
355
433
|
clientSecret: string;
|
|
356
|
-
|
|
434
|
+
venueId?: string;
|
|
357
435
|
/**
|
|
358
436
|
* Base URL for API requests
|
|
359
437
|
* @default "https://order3000.com/api"
|
|
@@ -366,6 +444,7 @@ interface Order3000ClientConfig {
|
|
|
366
444
|
tokenUrl?: string;
|
|
367
445
|
}
|
|
368
446
|
declare class Order3000Client {
|
|
447
|
+
events: EventsResource;
|
|
369
448
|
orders: OrdersResource;
|
|
370
449
|
reservations: ReservationsResource;
|
|
371
450
|
private readonly baseUrl;
|
package/dist/client.mjs
CHANGED
|
@@ -4,15 +4,15 @@ var __defProp$1 = Object.defineProperty;
|
|
|
4
4
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
5
|
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
6
|
class TokenManager {
|
|
7
|
-
constructor(clientId, clientSecret, tokenEndpoint,
|
|
7
|
+
constructor(clientId, clientSecret, tokenEndpoint, userVenueId) {
|
|
8
8
|
this.clientId = clientId;
|
|
9
9
|
this.clientSecret = clientSecret;
|
|
10
10
|
this.tokenEndpoint = tokenEndpoint;
|
|
11
|
-
this.
|
|
11
|
+
this.userVenueId = userVenueId;
|
|
12
12
|
__publicField$1(this, "accessToken", null);
|
|
13
13
|
__publicField$1(this, "tokenExpiresAt", 0);
|
|
14
14
|
__publicField$1(this, "refreshPromise", null);
|
|
15
|
-
__publicField$1(this, "
|
|
15
|
+
__publicField$1(this, "defaultVenueId");
|
|
16
16
|
}
|
|
17
17
|
async initialize() {
|
|
18
18
|
await this.refreshToken();
|
|
@@ -23,46 +23,49 @@ class TokenManager {
|
|
|
23
23
|
}
|
|
24
24
|
return this.refreshToken();
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
if (this.
|
|
28
|
-
if (!this.
|
|
29
|
-
return this.
|
|
26
|
+
getVenueId() {
|
|
27
|
+
if (this.userVenueId) return this.userVenueId;
|
|
28
|
+
if (!this.defaultVenueId) throw new Error("No venue ID available");
|
|
29
|
+
return this.defaultVenueId;
|
|
30
30
|
}
|
|
31
31
|
async refreshToken() {
|
|
32
|
-
console.log("refreshToken 1");
|
|
33
32
|
if (this.refreshPromise) return this.refreshPromise;
|
|
34
|
-
console.log("
|
|
33
|
+
console.log("[SDK TOKEN] Requesting token from:", this.tokenEndpoint);
|
|
34
|
+
console.log("[SDK TOKEN] Using clientId:", this.clientId);
|
|
35
|
+
console.log("[SDK TOKEN] Secret length:", this.clientSecret?.length);
|
|
35
36
|
this.refreshPromise = got.post(this.tokenEndpoint, {
|
|
36
37
|
json: { clientId: this.clientId, clientSecret: this.clientSecret },
|
|
37
38
|
responseType: "json",
|
|
38
39
|
timeout: { request: 36e4 },
|
|
39
40
|
retry: { limit: 3 }
|
|
40
41
|
}).then((response) => {
|
|
41
|
-
console.log("
|
|
42
|
+
console.log("[SDK TOKEN] Token received successfully");
|
|
42
43
|
this.accessToken = response.body.accessToken;
|
|
43
44
|
this.tokenExpiresAt = Date.now() + response.body.expiresIn * 1e3;
|
|
44
|
-
this.
|
|
45
|
+
this.setDefaultVenueId();
|
|
45
46
|
return this.accessToken;
|
|
47
|
+
}).catch((error) => {
|
|
48
|
+
console.log("[SDK TOKEN] Token request failed:", error.message);
|
|
49
|
+
if (error.response) {
|
|
50
|
+
console.log("[SDK TOKEN] Response status:", error.response.statusCode);
|
|
51
|
+
console.log("[SDK TOKEN] Response body:", error.response.body);
|
|
52
|
+
}
|
|
53
|
+
throw error;
|
|
46
54
|
}).finally(() => {
|
|
47
|
-
console.log("refreshToken 4");
|
|
48
55
|
this.refreshPromise = null;
|
|
49
56
|
});
|
|
50
|
-
console.log("refreshToken 5");
|
|
51
57
|
return this.refreshPromise;
|
|
52
58
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (this.userTenantId || !this.accessToken) return;
|
|
59
|
+
setDefaultVenueId() {
|
|
60
|
+
if (this.userVenueId || !this.accessToken) return;
|
|
56
61
|
try {
|
|
57
|
-
console.log("refreshToken 7");
|
|
58
62
|
const [, payload] = this.accessToken.split(".");
|
|
59
63
|
const decoded = JSON.parse(
|
|
60
64
|
Buffer.from(payload, "base64").toString()
|
|
61
65
|
);
|
|
62
|
-
this.
|
|
66
|
+
this.defaultVenueId = decoded.tenants?.[0];
|
|
63
67
|
} catch (error) {
|
|
64
|
-
|
|
65
|
-
throw new Error("Failed to parse tenant ID from token");
|
|
68
|
+
throw new Error("Failed to parse venue ID from token");
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
}
|
|
@@ -75,9 +78,11 @@ class BaseResource {
|
|
|
75
78
|
}
|
|
76
79
|
async request(method, path, data) {
|
|
77
80
|
const token = await this.tokenManager.getToken();
|
|
78
|
-
const
|
|
81
|
+
const venueId = this.tokenManager.getVenueId();
|
|
82
|
+
const url = `${this.baseUrl}/venues/${venueId}${this.resourcePath}${path}`;
|
|
83
|
+
console.log(`[SDK] Making ${method} request to: ${url}`);
|
|
79
84
|
return got(
|
|
80
|
-
|
|
85
|
+
url,
|
|
81
86
|
{
|
|
82
87
|
method,
|
|
83
88
|
json: data,
|
|
@@ -90,6 +95,18 @@ class BaseResource {
|
|
|
90
95
|
}
|
|
91
96
|
}
|
|
92
97
|
|
|
98
|
+
class EventsResource extends BaseResource {
|
|
99
|
+
constructor(tokenManager, baseUrl) {
|
|
100
|
+
super(tokenManager, baseUrl, "/events");
|
|
101
|
+
}
|
|
102
|
+
async place(event) {
|
|
103
|
+
return this.request("POST", "", event);
|
|
104
|
+
}
|
|
105
|
+
async get(eventId) {
|
|
106
|
+
return this.request("GET", `/${eventId}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
93
110
|
class OrdersResource extends BaseResource {
|
|
94
111
|
constructor(tokenManager, baseUrl) {
|
|
95
112
|
super(tokenManager, baseUrl, "/orders");
|
|
@@ -129,6 +146,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
129
146
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
130
147
|
class Order3000Client {
|
|
131
148
|
constructor(config) {
|
|
149
|
+
__publicField(this, "events");
|
|
132
150
|
__publicField(this, "orders");
|
|
133
151
|
__publicField(this, "reservations");
|
|
134
152
|
__publicField(this, "baseUrl");
|
|
@@ -139,25 +157,20 @@ class Order3000Client {
|
|
|
139
157
|
config.clientId,
|
|
140
158
|
config.clientSecret,
|
|
141
159
|
tokenUrl,
|
|
142
|
-
config.
|
|
160
|
+
config.venueId
|
|
143
161
|
);
|
|
144
|
-
|
|
162
|
+
this.events = new EventsResource(this.tokenManager, this.baseUrl);
|
|
145
163
|
this.orders = new OrdersResource(this.tokenManager, this.baseUrl);
|
|
146
164
|
this.reservations = new ReservationsResource(
|
|
147
165
|
this.tokenManager,
|
|
148
166
|
this.baseUrl
|
|
149
167
|
);
|
|
150
|
-
console.log("refreshToken 13");
|
|
151
168
|
this.initialize();
|
|
152
|
-
console.log("refreshToken 14");
|
|
153
169
|
}
|
|
154
170
|
async initialize() {
|
|
155
171
|
try {
|
|
156
|
-
console.log("refreshToken 9");
|
|
157
172
|
await this.tokenManager.initialize();
|
|
158
|
-
console.log("refreshToken 10");
|
|
159
173
|
} catch (error) {
|
|
160
|
-
console.log("refreshToken 11");
|
|
161
174
|
console.error("Failed to initialize client:", error);
|
|
162
175
|
process.exit(1);
|
|
163
176
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "order3000",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "order3000 node.js sdk",
|
|
5
5
|
"main": "./dist/client.cjs",
|
|
6
6
|
"module": "./dist/client.mjs",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"prettier": "^3.5.3",
|
|
31
31
|
"tsx": "^4.19.2",
|
|
32
32
|
"typescript": "^5.7.3",
|
|
33
|
-
"@kolaveri/
|
|
34
|
-
"@kolaveri/
|
|
33
|
+
"@kolaveri/prettier-config": "1.0.5",
|
|
34
|
+
"@kolaveri/eslint-config": "1.0.8"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"dist"
|