order3000 0.4.0 → 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 +29 -29
- package/dist/client.d.cts +84 -11
- package/dist/client.d.mts +84 -11
- package/dist/client.mjs +29 -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,15 +25,13 @@ 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("refreshToken 2");
|
|
37
35
|
console.log("[SDK TOKEN] Requesting token from:", this.tokenEndpoint);
|
|
38
36
|
console.log("[SDK TOKEN] Using clientId:", this.clientId);
|
|
39
37
|
console.log("[SDK TOKEN] Secret length:", this.clientSecret?.length);
|
|
@@ -43,11 +41,10 @@ class TokenManager {
|
|
|
43
41
|
timeout: { request: 36e4 },
|
|
44
42
|
retry: { limit: 3 }
|
|
45
43
|
}).then((response) => {
|
|
46
|
-
console.log("refreshToken 3");
|
|
47
44
|
console.log("[SDK TOKEN] Token received successfully");
|
|
48
45
|
this.accessToken = response.body.accessToken;
|
|
49
46
|
this.tokenExpiresAt = Date.now() + response.body.expiresIn * 1e3;
|
|
50
|
-
this.
|
|
47
|
+
this.setDefaultVenueId();
|
|
51
48
|
return this.accessToken;
|
|
52
49
|
}).catch((error) => {
|
|
53
50
|
console.log("[SDK TOKEN] Token request failed:", error.message);
|
|
@@ -57,25 +54,20 @@ class TokenManager {
|
|
|
57
54
|
}
|
|
58
55
|
throw error;
|
|
59
56
|
}).finally(() => {
|
|
60
|
-
console.log("refreshToken 4");
|
|
61
57
|
this.refreshPromise = null;
|
|
62
58
|
});
|
|
63
|
-
console.log("refreshToken 5");
|
|
64
59
|
return this.refreshPromise;
|
|
65
60
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (this.userTenantId || !this.accessToken) return;
|
|
61
|
+
setDefaultVenueId() {
|
|
62
|
+
if (this.userVenueId || !this.accessToken) return;
|
|
69
63
|
try {
|
|
70
|
-
console.log("refreshToken 7");
|
|
71
64
|
const [, payload] = this.accessToken.split(".");
|
|
72
65
|
const decoded = JSON.parse(
|
|
73
66
|
Buffer.from(payload, "base64").toString()
|
|
74
67
|
);
|
|
75
|
-
this.
|
|
68
|
+
this.defaultVenueId = decoded.tenants?.[0];
|
|
76
69
|
} catch (error) {
|
|
77
|
-
|
|
78
|
-
throw new Error("Failed to parse tenant ID from token");
|
|
70
|
+
throw new Error("Failed to parse venue ID from token");
|
|
79
71
|
}
|
|
80
72
|
}
|
|
81
73
|
}
|
|
@@ -88,8 +80,8 @@ class BaseResource {
|
|
|
88
80
|
}
|
|
89
81
|
async request(method, path, data) {
|
|
90
82
|
const token = await this.tokenManager.getToken();
|
|
91
|
-
const
|
|
92
|
-
const url = `${this.baseUrl}/
|
|
83
|
+
const venueId = this.tokenManager.getVenueId();
|
|
84
|
+
const url = `${this.baseUrl}/venues/${venueId}${this.resourcePath}${path}`;
|
|
93
85
|
console.log(`[SDK] Making ${method} request to: ${url}`);
|
|
94
86
|
return got(
|
|
95
87
|
url,
|
|
@@ -105,6 +97,18 @@ class BaseResource {
|
|
|
105
97
|
}
|
|
106
98
|
}
|
|
107
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
|
+
|
|
108
112
|
class OrdersResource extends BaseResource {
|
|
109
113
|
constructor(tokenManager, baseUrl) {
|
|
110
114
|
super(tokenManager, baseUrl, "/orders");
|
|
@@ -144,6 +148,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
144
148
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
145
149
|
class Order3000Client {
|
|
146
150
|
constructor(config) {
|
|
151
|
+
__publicField(this, "events");
|
|
147
152
|
__publicField(this, "orders");
|
|
148
153
|
__publicField(this, "reservations");
|
|
149
154
|
__publicField(this, "baseUrl");
|
|
@@ -154,25 +159,20 @@ class Order3000Client {
|
|
|
154
159
|
config.clientId,
|
|
155
160
|
config.clientSecret,
|
|
156
161
|
tokenUrl,
|
|
157
|
-
config.
|
|
162
|
+
config.venueId
|
|
158
163
|
);
|
|
159
|
-
|
|
164
|
+
this.events = new EventsResource(this.tokenManager, this.baseUrl);
|
|
160
165
|
this.orders = new OrdersResource(this.tokenManager, this.baseUrl);
|
|
161
166
|
this.reservations = new ReservationsResource(
|
|
162
167
|
this.tokenManager,
|
|
163
168
|
this.baseUrl
|
|
164
169
|
);
|
|
165
|
-
console.log("refreshToken 13");
|
|
166
170
|
this.initialize();
|
|
167
|
-
console.log("refreshToken 14");
|
|
168
171
|
}
|
|
169
172
|
async initialize() {
|
|
170
173
|
try {
|
|
171
|
-
console.log("refreshToken 9");
|
|
172
174
|
await this.tokenManager.initialize();
|
|
173
|
-
console.log("refreshToken 10");
|
|
174
175
|
} catch (error) {
|
|
175
|
-
console.log("refreshToken 11");
|
|
176
176
|
console.error("Failed to initialize client:", error);
|
|
177
177
|
process.exit(1);
|
|
178
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 */
|
|
@@ -126,7 +131,12 @@ interface components {
|
|
|
126
131
|
* Format: uuid
|
|
127
132
|
* @description Restaurant/tenant identifier
|
|
128
133
|
*/
|
|
129
|
-
|
|
134
|
+
venueId: string;
|
|
135
|
+
/**
|
|
136
|
+
* Format: uuid
|
|
137
|
+
* @description Event identifier for this reservation
|
|
138
|
+
*/
|
|
139
|
+
eventId: string;
|
|
130
140
|
/** @description Date of the reservation in YYYY-MM-DD format */
|
|
131
141
|
reservationDate: string;
|
|
132
142
|
/** @description Time of the reservation in HH:MM:SS format */
|
|
@@ -230,7 +240,12 @@ interface components {
|
|
|
230
240
|
* Format: uuid
|
|
231
241
|
* @description Restaurant/tenant identifier
|
|
232
242
|
*/
|
|
233
|
-
|
|
243
|
+
venueId: string;
|
|
244
|
+
/**
|
|
245
|
+
* Format: uuid
|
|
246
|
+
* @description Event identifier for this reservation
|
|
247
|
+
*/
|
|
248
|
+
eventId: string;
|
|
234
249
|
/** @description Date of the reservation in YYYY-MM-DD format */
|
|
235
250
|
reservationDate: string;
|
|
236
251
|
/** @description Time of the reservation in HH:MM:SS format */
|
|
@@ -320,6 +335,55 @@ interface components {
|
|
|
320
335
|
*/
|
|
321
336
|
updatedAt: string | null;
|
|
322
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
|
+
};
|
|
323
387
|
};
|
|
324
388
|
responses: never;
|
|
325
389
|
parameters: never;
|
|
@@ -329,11 +393,19 @@ interface components {
|
|
|
329
393
|
}
|
|
330
394
|
|
|
331
395
|
type schemas = components['schemas'];
|
|
396
|
+
type CreateEventRequest = schemas['CreateEventRequest'];
|
|
397
|
+
type CreateEventResponse = schemas['CreateEventResponse'];
|
|
332
398
|
type PlaceOrderRequest = schemas['PlaceOrderRequest'];
|
|
333
399
|
type PlaceOrderResponse = schemas['PlaceOrderResponse'];
|
|
334
400
|
type MakeReservationRequest = schemas['MakeReservationRequest'];
|
|
335
401
|
type MakeReservationResponse = schemas['MakeReservationResponse'];
|
|
336
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
|
+
|
|
337
409
|
declare class OrdersResource extends BaseResource {
|
|
338
410
|
constructor(tokenManager: TokenManager, baseUrl: string);
|
|
339
411
|
place(order: PlaceOrderRequest): Promise<PlaceOrderResponse>;
|
|
@@ -359,7 +431,7 @@ declare class ReservationsResource extends BaseResource {
|
|
|
359
431
|
interface Order3000ClientConfig {
|
|
360
432
|
clientId: string;
|
|
361
433
|
clientSecret: string;
|
|
362
|
-
|
|
434
|
+
venueId?: string;
|
|
363
435
|
/**
|
|
364
436
|
* Base URL for API requests
|
|
365
437
|
* @default "https://order3000.com/api"
|
|
@@ -372,6 +444,7 @@ interface Order3000ClientConfig {
|
|
|
372
444
|
tokenUrl?: string;
|
|
373
445
|
}
|
|
374
446
|
declare class Order3000Client {
|
|
447
|
+
events: EventsResource;
|
|
375
448
|
orders: OrdersResource;
|
|
376
449
|
reservations: ReservationsResource;
|
|
377
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 */
|
|
@@ -126,7 +131,12 @@ interface components {
|
|
|
126
131
|
* Format: uuid
|
|
127
132
|
* @description Restaurant/tenant identifier
|
|
128
133
|
*/
|
|
129
|
-
|
|
134
|
+
venueId: string;
|
|
135
|
+
/**
|
|
136
|
+
* Format: uuid
|
|
137
|
+
* @description Event identifier for this reservation
|
|
138
|
+
*/
|
|
139
|
+
eventId: string;
|
|
130
140
|
/** @description Date of the reservation in YYYY-MM-DD format */
|
|
131
141
|
reservationDate: string;
|
|
132
142
|
/** @description Time of the reservation in HH:MM:SS format */
|
|
@@ -230,7 +240,12 @@ interface components {
|
|
|
230
240
|
* Format: uuid
|
|
231
241
|
* @description Restaurant/tenant identifier
|
|
232
242
|
*/
|
|
233
|
-
|
|
243
|
+
venueId: string;
|
|
244
|
+
/**
|
|
245
|
+
* Format: uuid
|
|
246
|
+
* @description Event identifier for this reservation
|
|
247
|
+
*/
|
|
248
|
+
eventId: string;
|
|
234
249
|
/** @description Date of the reservation in YYYY-MM-DD format */
|
|
235
250
|
reservationDate: string;
|
|
236
251
|
/** @description Time of the reservation in HH:MM:SS format */
|
|
@@ -320,6 +335,55 @@ interface components {
|
|
|
320
335
|
*/
|
|
321
336
|
updatedAt: string | null;
|
|
322
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
|
+
};
|
|
323
387
|
};
|
|
324
388
|
responses: never;
|
|
325
389
|
parameters: never;
|
|
@@ -329,11 +393,19 @@ interface components {
|
|
|
329
393
|
}
|
|
330
394
|
|
|
331
395
|
type schemas = components['schemas'];
|
|
396
|
+
type CreateEventRequest = schemas['CreateEventRequest'];
|
|
397
|
+
type CreateEventResponse = schemas['CreateEventResponse'];
|
|
332
398
|
type PlaceOrderRequest = schemas['PlaceOrderRequest'];
|
|
333
399
|
type PlaceOrderResponse = schemas['PlaceOrderResponse'];
|
|
334
400
|
type MakeReservationRequest = schemas['MakeReservationRequest'];
|
|
335
401
|
type MakeReservationResponse = schemas['MakeReservationResponse'];
|
|
336
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
|
+
|
|
337
409
|
declare class OrdersResource extends BaseResource {
|
|
338
410
|
constructor(tokenManager: TokenManager, baseUrl: string);
|
|
339
411
|
place(order: PlaceOrderRequest): Promise<PlaceOrderResponse>;
|
|
@@ -359,7 +431,7 @@ declare class ReservationsResource extends BaseResource {
|
|
|
359
431
|
interface Order3000ClientConfig {
|
|
360
432
|
clientId: string;
|
|
361
433
|
clientSecret: string;
|
|
362
|
-
|
|
434
|
+
venueId?: string;
|
|
363
435
|
/**
|
|
364
436
|
* Base URL for API requests
|
|
365
437
|
* @default "https://order3000.com/api"
|
|
@@ -372,6 +444,7 @@ interface Order3000ClientConfig {
|
|
|
372
444
|
tokenUrl?: string;
|
|
373
445
|
}
|
|
374
446
|
declare class Order3000Client {
|
|
447
|
+
events: EventsResource;
|
|
375
448
|
orders: OrdersResource;
|
|
376
449
|
reservations: ReservationsResource;
|
|
377
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,15 +23,13 @@ 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("refreshToken 2");
|
|
35
33
|
console.log("[SDK TOKEN] Requesting token from:", this.tokenEndpoint);
|
|
36
34
|
console.log("[SDK TOKEN] Using clientId:", this.clientId);
|
|
37
35
|
console.log("[SDK TOKEN] Secret length:", this.clientSecret?.length);
|
|
@@ -41,11 +39,10 @@ class TokenManager {
|
|
|
41
39
|
timeout: { request: 36e4 },
|
|
42
40
|
retry: { limit: 3 }
|
|
43
41
|
}).then((response) => {
|
|
44
|
-
console.log("refreshToken 3");
|
|
45
42
|
console.log("[SDK TOKEN] Token received successfully");
|
|
46
43
|
this.accessToken = response.body.accessToken;
|
|
47
44
|
this.tokenExpiresAt = Date.now() + response.body.expiresIn * 1e3;
|
|
48
|
-
this.
|
|
45
|
+
this.setDefaultVenueId();
|
|
49
46
|
return this.accessToken;
|
|
50
47
|
}).catch((error) => {
|
|
51
48
|
console.log("[SDK TOKEN] Token request failed:", error.message);
|
|
@@ -55,25 +52,20 @@ class TokenManager {
|
|
|
55
52
|
}
|
|
56
53
|
throw error;
|
|
57
54
|
}).finally(() => {
|
|
58
|
-
console.log("refreshToken 4");
|
|
59
55
|
this.refreshPromise = null;
|
|
60
56
|
});
|
|
61
|
-
console.log("refreshToken 5");
|
|
62
57
|
return this.refreshPromise;
|
|
63
58
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (this.userTenantId || !this.accessToken) return;
|
|
59
|
+
setDefaultVenueId() {
|
|
60
|
+
if (this.userVenueId || !this.accessToken) return;
|
|
67
61
|
try {
|
|
68
|
-
console.log("refreshToken 7");
|
|
69
62
|
const [, payload] = this.accessToken.split(".");
|
|
70
63
|
const decoded = JSON.parse(
|
|
71
64
|
Buffer.from(payload, "base64").toString()
|
|
72
65
|
);
|
|
73
|
-
this.
|
|
66
|
+
this.defaultVenueId = decoded.tenants?.[0];
|
|
74
67
|
} catch (error) {
|
|
75
|
-
|
|
76
|
-
throw new Error("Failed to parse tenant ID from token");
|
|
68
|
+
throw new Error("Failed to parse venue ID from token");
|
|
77
69
|
}
|
|
78
70
|
}
|
|
79
71
|
}
|
|
@@ -86,8 +78,8 @@ class BaseResource {
|
|
|
86
78
|
}
|
|
87
79
|
async request(method, path, data) {
|
|
88
80
|
const token = await this.tokenManager.getToken();
|
|
89
|
-
const
|
|
90
|
-
const url = `${this.baseUrl}/
|
|
81
|
+
const venueId = this.tokenManager.getVenueId();
|
|
82
|
+
const url = `${this.baseUrl}/venues/${venueId}${this.resourcePath}${path}`;
|
|
91
83
|
console.log(`[SDK] Making ${method} request to: ${url}`);
|
|
92
84
|
return got(
|
|
93
85
|
url,
|
|
@@ -103,6 +95,18 @@ class BaseResource {
|
|
|
103
95
|
}
|
|
104
96
|
}
|
|
105
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
|
+
|
|
106
110
|
class OrdersResource extends BaseResource {
|
|
107
111
|
constructor(tokenManager, baseUrl) {
|
|
108
112
|
super(tokenManager, baseUrl, "/orders");
|
|
@@ -142,6 +146,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
142
146
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
143
147
|
class Order3000Client {
|
|
144
148
|
constructor(config) {
|
|
149
|
+
__publicField(this, "events");
|
|
145
150
|
__publicField(this, "orders");
|
|
146
151
|
__publicField(this, "reservations");
|
|
147
152
|
__publicField(this, "baseUrl");
|
|
@@ -152,25 +157,20 @@ class Order3000Client {
|
|
|
152
157
|
config.clientId,
|
|
153
158
|
config.clientSecret,
|
|
154
159
|
tokenUrl,
|
|
155
|
-
config.
|
|
160
|
+
config.venueId
|
|
156
161
|
);
|
|
157
|
-
|
|
162
|
+
this.events = new EventsResource(this.tokenManager, this.baseUrl);
|
|
158
163
|
this.orders = new OrdersResource(this.tokenManager, this.baseUrl);
|
|
159
164
|
this.reservations = new ReservationsResource(
|
|
160
165
|
this.tokenManager,
|
|
161
166
|
this.baseUrl
|
|
162
167
|
);
|
|
163
|
-
console.log("refreshToken 13");
|
|
164
168
|
this.initialize();
|
|
165
|
-
console.log("refreshToken 14");
|
|
166
169
|
}
|
|
167
170
|
async initialize() {
|
|
168
171
|
try {
|
|
169
|
-
console.log("refreshToken 9");
|
|
170
172
|
await this.tokenManager.initialize();
|
|
171
|
-
console.log("refreshToken 10");
|
|
172
173
|
} catch (error) {
|
|
173
|
-
console.log("refreshToken 11");
|
|
174
174
|
console.error("Failed to initialize client:", error);
|
|
175
175
|
process.exit(1);
|
|
176
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"
|