order3000 0.4.0 → 0.6.1

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 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, userTenantId) {
9
+ constructor(clientId, clientSecret, tokenEndpoint, userVenueId) {
10
10
  this.clientId = clientId;
11
11
  this.clientSecret = clientSecret;
12
12
  this.tokenEndpoint = tokenEndpoint;
13
- this.userTenantId = userTenantId;
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, "defaultTenantId");
17
+ __publicField$1(this, "defaultVenueId");
18
18
  }
19
19
  async initialize() {
20
20
  await this.refreshToken();
@@ -25,15 +25,24 @@ class TokenManager {
25
25
  }
26
26
  return this.refreshToken();
27
27
  }
28
- getTenantId() {
29
- if (this.userTenantId) return this.userTenantId;
30
- if (!this.defaultTenantId) throw new Error("No tenant ID available");
31
- return this.defaultTenantId;
28
+ getVenueId() {
29
+ console.log("[SDK VENUE] Getting venue ID...");
30
+ console.log("[SDK VENUE] User venue ID:", this.userVenueId);
31
+ console.log("[SDK VENUE] Default venue ID:", this.defaultVenueId);
32
+ if (this.userVenueId) {
33
+ console.log("[SDK VENUE] Using user venue ID:", this.userVenueId);
34
+ return this.userVenueId;
35
+ }
36
+ if (!this.defaultVenueId) {
37
+ console.error("[SDK VENUE] No venue ID available!");
38
+ console.error("[SDK VENUE] Token exists:", !!this.accessToken);
39
+ throw new Error("No venue ID available. The robot account may not be associated with any venues.");
40
+ }
41
+ console.log("[SDK VENUE] Using default venue ID:", this.defaultVenueId);
42
+ return this.defaultVenueId;
32
43
  }
33
44
  async refreshToken() {
34
- console.log("refreshToken 1");
35
45
  if (this.refreshPromise) return this.refreshPromise;
36
- console.log("refreshToken 2");
37
46
  console.log("[SDK TOKEN] Requesting token from:", this.tokenEndpoint);
38
47
  console.log("[SDK TOKEN] Using clientId:", this.clientId);
39
48
  console.log("[SDK TOKEN] Secret length:", this.clientSecret?.length);
@@ -43,11 +52,10 @@ class TokenManager {
43
52
  timeout: { request: 36e4 },
44
53
  retry: { limit: 3 }
45
54
  }).then((response) => {
46
- console.log("refreshToken 3");
47
55
  console.log("[SDK TOKEN] Token received successfully");
48
56
  this.accessToken = response.body.accessToken;
49
57
  this.tokenExpiresAt = Date.now() + response.body.expiresIn * 1e3;
50
- this.setDefaultTenantId();
58
+ this.setDefaultVenueId();
51
59
  return this.accessToken;
52
60
  }).catch((error) => {
53
61
  console.log("[SDK TOKEN] Token request failed:", error.message);
@@ -57,25 +65,29 @@ class TokenManager {
57
65
  }
58
66
  throw error;
59
67
  }).finally(() => {
60
- console.log("refreshToken 4");
61
68
  this.refreshPromise = null;
62
69
  });
63
- console.log("refreshToken 5");
64
70
  return this.refreshPromise;
65
71
  }
66
- setDefaultTenantId() {
67
- console.log("refreshToken 6");
68
- if (this.userTenantId || !this.accessToken) return;
72
+ setDefaultVenueId() {
73
+ if (this.userVenueId || !this.accessToken) return;
69
74
  try {
70
- console.log("refreshToken 7");
75
+ console.log("[SDK VENUE] Parsing token to extract default venue ID...");
71
76
  const [, payload] = this.accessToken.split(".");
72
77
  const decoded = JSON.parse(
73
78
  Buffer.from(payload, "base64").toString()
74
79
  );
75
- this.defaultTenantId = decoded.tenants?.[0];
80
+ console.log("[SDK VENUE] Token payload venues:", decoded.venues);
81
+ if (!decoded.venues || decoded.venues.length === 0) {
82
+ console.warn("[SDK VENUE] No venues found in token. Robot account may not be associated with any venues.");
83
+ this.defaultVenueId = void 0;
84
+ return;
85
+ }
86
+ this.defaultVenueId = decoded.venues[0];
87
+ console.log("[SDK VENUE] Set default venue ID to:", this.defaultVenueId);
76
88
  } catch (error) {
77
- console.log("refreshToken 8");
78
- throw new Error("Failed to parse tenant ID from token");
89
+ console.error("[SDK VENUE] Failed to parse venue ID from token:", error);
90
+ throw new Error("Failed to parse venue ID from token");
79
91
  }
80
92
  }
81
93
  }
@@ -88,8 +100,8 @@ class BaseResource {
88
100
  }
89
101
  async request(method, path, data) {
90
102
  const token = await this.tokenManager.getToken();
91
- const tenantId = this.tokenManager.getTenantId();
92
- const url = `${this.baseUrl}/tenants/${tenantId}${this.resourcePath}${path}`;
103
+ const venueId = this.tokenManager.getVenueId();
104
+ const url = `${this.baseUrl}/venues/${venueId}${this.resourcePath}${path}`;
93
105
  console.log(`[SDK] Making ${method} request to: ${url}`);
94
106
  return got(
95
107
  url,
@@ -105,6 +117,18 @@ class BaseResource {
105
117
  }
106
118
  }
107
119
 
120
+ class EventsResource extends BaseResource {
121
+ constructor(tokenManager, baseUrl) {
122
+ super(tokenManager, baseUrl, "/events");
123
+ }
124
+ async place(event) {
125
+ return this.request("POST", "", event);
126
+ }
127
+ async get(eventId) {
128
+ return this.request("GET", `/${eventId}`);
129
+ }
130
+ }
131
+
108
132
  class OrdersResource extends BaseResource {
109
133
  constructor(tokenManager, baseUrl) {
110
134
  super(tokenManager, baseUrl, "/orders");
@@ -144,6 +168,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
144
168
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
145
169
  class Order3000Client {
146
170
  constructor(config) {
171
+ __publicField(this, "events");
147
172
  __publicField(this, "orders");
148
173
  __publicField(this, "reservations");
149
174
  __publicField(this, "baseUrl");
@@ -154,25 +179,20 @@ class Order3000Client {
154
179
  config.clientId,
155
180
  config.clientSecret,
156
181
  tokenUrl,
157
- config.tenantId
182
+ config.venueId
158
183
  );
159
- console.log("refreshToken 12");
184
+ this.events = new EventsResource(this.tokenManager, this.baseUrl);
160
185
  this.orders = new OrdersResource(this.tokenManager, this.baseUrl);
161
186
  this.reservations = new ReservationsResource(
162
187
  this.tokenManager,
163
188
  this.baseUrl
164
189
  );
165
- console.log("refreshToken 13");
166
190
  this.initialize();
167
- console.log("refreshToken 14");
168
191
  }
169
192
  async initialize() {
170
193
  try {
171
- console.log("refreshToken 9");
172
194
  await this.tokenManager.initialize();
173
- console.log("refreshToken 10");
174
195
  } catch (error) {
175
- console.log("refreshToken 11");
176
196
  console.error("Failed to initialize client:", error);
177
197
  process.exit(1);
178
198
  }
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 userTenantId?;
5
+ private readonly userVenueId?;
6
6
  private accessToken;
7
7
  private tokenExpiresAt;
8
8
  private refreshPromise;
9
- private defaultTenantId?;
10
- constructor(clientId: string, clientSecret: string, tokenEndpoint: string, userTenantId?: string | undefined);
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
- getTenantId(): string;
13
+ getVenueId(): string;
14
14
  private refreshToken;
15
- private setDefaultTenantId;
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 tenant
30
+ * @description Place a new order for a specific venue
31
31
  */
32
32
  PlaceOrderRequest: {
33
33
  id?: string;
34
- tenantId: string;
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
- tenantId: string;
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
- tenantId: string;
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
- tenantId: string;
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
- tenantId?: string;
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 userTenantId?;
5
+ private readonly userVenueId?;
6
6
  private accessToken;
7
7
  private tokenExpiresAt;
8
8
  private refreshPromise;
9
- private defaultTenantId?;
10
- constructor(clientId: string, clientSecret: string, tokenEndpoint: string, userTenantId?: string | undefined);
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
- getTenantId(): string;
13
+ getVenueId(): string;
14
14
  private refreshToken;
15
- private setDefaultTenantId;
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 tenant
30
+ * @description Place a new order for a specific venue
31
31
  */
32
32
  PlaceOrderRequest: {
33
33
  id?: string;
34
- tenantId: string;
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
- tenantId: string;
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
- tenantId: string;
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
- tenantId: string;
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
- tenantId?: string;
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, userTenantId) {
7
+ constructor(clientId, clientSecret, tokenEndpoint, userVenueId) {
8
8
  this.clientId = clientId;
9
9
  this.clientSecret = clientSecret;
10
10
  this.tokenEndpoint = tokenEndpoint;
11
- this.userTenantId = userTenantId;
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, "defaultTenantId");
15
+ __publicField$1(this, "defaultVenueId");
16
16
  }
17
17
  async initialize() {
18
18
  await this.refreshToken();
@@ -23,15 +23,24 @@ class TokenManager {
23
23
  }
24
24
  return this.refreshToken();
25
25
  }
26
- getTenantId() {
27
- if (this.userTenantId) return this.userTenantId;
28
- if (!this.defaultTenantId) throw new Error("No tenant ID available");
29
- return this.defaultTenantId;
26
+ getVenueId() {
27
+ console.log("[SDK VENUE] Getting venue ID...");
28
+ console.log("[SDK VENUE] User venue ID:", this.userVenueId);
29
+ console.log("[SDK VENUE] Default venue ID:", this.defaultVenueId);
30
+ if (this.userVenueId) {
31
+ console.log("[SDK VENUE] Using user venue ID:", this.userVenueId);
32
+ return this.userVenueId;
33
+ }
34
+ if (!this.defaultVenueId) {
35
+ console.error("[SDK VENUE] No venue ID available!");
36
+ console.error("[SDK VENUE] Token exists:", !!this.accessToken);
37
+ throw new Error("No venue ID available. The robot account may not be associated with any venues.");
38
+ }
39
+ console.log("[SDK VENUE] Using default venue ID:", this.defaultVenueId);
40
+ return this.defaultVenueId;
30
41
  }
31
42
  async refreshToken() {
32
- console.log("refreshToken 1");
33
43
  if (this.refreshPromise) return this.refreshPromise;
34
- console.log("refreshToken 2");
35
44
  console.log("[SDK TOKEN] Requesting token from:", this.tokenEndpoint);
36
45
  console.log("[SDK TOKEN] Using clientId:", this.clientId);
37
46
  console.log("[SDK TOKEN] Secret length:", this.clientSecret?.length);
@@ -41,11 +50,10 @@ class TokenManager {
41
50
  timeout: { request: 36e4 },
42
51
  retry: { limit: 3 }
43
52
  }).then((response) => {
44
- console.log("refreshToken 3");
45
53
  console.log("[SDK TOKEN] Token received successfully");
46
54
  this.accessToken = response.body.accessToken;
47
55
  this.tokenExpiresAt = Date.now() + response.body.expiresIn * 1e3;
48
- this.setDefaultTenantId();
56
+ this.setDefaultVenueId();
49
57
  return this.accessToken;
50
58
  }).catch((error) => {
51
59
  console.log("[SDK TOKEN] Token request failed:", error.message);
@@ -55,25 +63,29 @@ class TokenManager {
55
63
  }
56
64
  throw error;
57
65
  }).finally(() => {
58
- console.log("refreshToken 4");
59
66
  this.refreshPromise = null;
60
67
  });
61
- console.log("refreshToken 5");
62
68
  return this.refreshPromise;
63
69
  }
64
- setDefaultTenantId() {
65
- console.log("refreshToken 6");
66
- if (this.userTenantId || !this.accessToken) return;
70
+ setDefaultVenueId() {
71
+ if (this.userVenueId || !this.accessToken) return;
67
72
  try {
68
- console.log("refreshToken 7");
73
+ console.log("[SDK VENUE] Parsing token to extract default venue ID...");
69
74
  const [, payload] = this.accessToken.split(".");
70
75
  const decoded = JSON.parse(
71
76
  Buffer.from(payload, "base64").toString()
72
77
  );
73
- this.defaultTenantId = decoded.tenants?.[0];
78
+ console.log("[SDK VENUE] Token payload venues:", decoded.venues);
79
+ if (!decoded.venues || decoded.venues.length === 0) {
80
+ console.warn("[SDK VENUE] No venues found in token. Robot account may not be associated with any venues.");
81
+ this.defaultVenueId = void 0;
82
+ return;
83
+ }
84
+ this.defaultVenueId = decoded.venues[0];
85
+ console.log("[SDK VENUE] Set default venue ID to:", this.defaultVenueId);
74
86
  } catch (error) {
75
- console.log("refreshToken 8");
76
- throw new Error("Failed to parse tenant ID from token");
87
+ console.error("[SDK VENUE] Failed to parse venue ID from token:", error);
88
+ throw new Error("Failed to parse venue ID from token");
77
89
  }
78
90
  }
79
91
  }
@@ -86,8 +98,8 @@ class BaseResource {
86
98
  }
87
99
  async request(method, path, data) {
88
100
  const token = await this.tokenManager.getToken();
89
- const tenantId = this.tokenManager.getTenantId();
90
- const url = `${this.baseUrl}/tenants/${tenantId}${this.resourcePath}${path}`;
101
+ const venueId = this.tokenManager.getVenueId();
102
+ const url = `${this.baseUrl}/venues/${venueId}${this.resourcePath}${path}`;
91
103
  console.log(`[SDK] Making ${method} request to: ${url}`);
92
104
  return got(
93
105
  url,
@@ -103,6 +115,18 @@ class BaseResource {
103
115
  }
104
116
  }
105
117
 
118
+ class EventsResource extends BaseResource {
119
+ constructor(tokenManager, baseUrl) {
120
+ super(tokenManager, baseUrl, "/events");
121
+ }
122
+ async place(event) {
123
+ return this.request("POST", "", event);
124
+ }
125
+ async get(eventId) {
126
+ return this.request("GET", `/${eventId}`);
127
+ }
128
+ }
129
+
106
130
  class OrdersResource extends BaseResource {
107
131
  constructor(tokenManager, baseUrl) {
108
132
  super(tokenManager, baseUrl, "/orders");
@@ -142,6 +166,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
142
166
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
143
167
  class Order3000Client {
144
168
  constructor(config) {
169
+ __publicField(this, "events");
145
170
  __publicField(this, "orders");
146
171
  __publicField(this, "reservations");
147
172
  __publicField(this, "baseUrl");
@@ -152,25 +177,20 @@ class Order3000Client {
152
177
  config.clientId,
153
178
  config.clientSecret,
154
179
  tokenUrl,
155
- config.tenantId
180
+ config.venueId
156
181
  );
157
- console.log("refreshToken 12");
182
+ this.events = new EventsResource(this.tokenManager, this.baseUrl);
158
183
  this.orders = new OrdersResource(this.tokenManager, this.baseUrl);
159
184
  this.reservations = new ReservationsResource(
160
185
  this.tokenManager,
161
186
  this.baseUrl
162
187
  );
163
- console.log("refreshToken 13");
164
188
  this.initialize();
165
- console.log("refreshToken 14");
166
189
  }
167
190
  async initialize() {
168
191
  try {
169
- console.log("refreshToken 9");
170
192
  await this.tokenManager.initialize();
171
- console.log("refreshToken 10");
172
193
  } catch (error) {
173
- console.log("refreshToken 11");
174
194
  console.error("Failed to initialize client:", error);
175
195
  process.exit(1);
176
196
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "order3000",
3
- "version": "0.4.0",
3
+ "version": "0.6.1",
4
4
  "description": "order3000 node.js sdk",
5
5
  "main": "./dist/client.cjs",
6
6
  "module": "./dist/client.mjs",
@@ -30,7 +30,7 @@
30
30
  "prettier": "^3.5.3",
31
31
  "tsx": "^4.19.2",
32
32
  "typescript": "^5.7.3",
33
- "@kolaveri/eslint-config": "1.0.7",
33
+ "@kolaveri/eslint-config": "1.0.8",
34
34
  "@kolaveri/prettier-config": "1.0.5"
35
35
  },
36
36
  "files": [