tripit 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -33198,6 +33198,10 @@ var init_esm = __esm(() => {
33198
33198
  fetchCookie.toughCookie = exports_dist;
33199
33199
  });
33200
33200
 
33201
+ // src/tripit.ts
33202
+ import { access, readFile } from "node:fs/promises";
33203
+ import { extname } from "node:path";
33204
+
33201
33205
  // node_modules/node-fetch/src/index.js
33202
33206
  import http2 from "node:http";
33203
33207
  import https from "node:https";
@@ -47790,14 +47794,14 @@ var TRIP_UPDATE_FIELD_ORDER = [
47790
47794
  ];
47791
47795
  var LODGING_FIELD_ORDER = [
47792
47796
  "uuid",
47793
- "trip_uuid",
47794
47797
  "trip_id",
47798
+ "trip_uuid",
47795
47799
  "is_client_traveler",
47796
47800
  "display_name",
47797
47801
  "Image",
47798
- "supplier_name",
47799
- "supplier_conf_num",
47800
47802
  "booking_rate",
47803
+ "supplier_conf_num",
47804
+ "supplier_name",
47801
47805
  "is_purchased",
47802
47806
  "notes",
47803
47807
  "total_cost",
@@ -47807,13 +47811,13 @@ var LODGING_FIELD_ORDER = [
47807
47811
  ];
47808
47812
  var AIR_FIELD_ORDER = [
47809
47813
  "uuid",
47810
- "trip_uuid",
47811
47814
  "trip_id",
47815
+ "trip_uuid",
47812
47816
  "is_client_traveler",
47813
47817
  "display_name",
47814
47818
  "Image",
47815
- "supplier_name",
47816
47819
  "supplier_conf_num",
47820
+ "supplier_name",
47817
47821
  "is_purchased",
47818
47822
  "notes",
47819
47823
  "total_cost",
@@ -47834,8 +47838,8 @@ var AIR_SEGMENT_FIELD_ORDER = [
47834
47838
  ];
47835
47839
  var TRANSPORT_FIELD_ORDER = [
47836
47840
  "uuid",
47837
- "trip_uuid",
47838
47841
  "trip_id",
47842
+ "trip_uuid",
47839
47843
  "is_client_traveler",
47840
47844
  "display_name",
47841
47845
  "Image",
@@ -47858,8 +47862,8 @@ var TRANSPORT_SEGMENT_FIELD_ORDER = [
47858
47862
  ];
47859
47863
  var ACTIVITY_FIELD_ORDER = [
47860
47864
  "uuid",
47861
- "trip_uuid",
47862
47865
  "trip_id",
47866
+ "trip_uuid",
47863
47867
  "is_client_traveler",
47864
47868
  "display_name",
47865
47869
  "Image",
@@ -48081,6 +48085,22 @@ function toBoolean(value) {
48081
48085
  }
48082
48086
 
48083
48087
  // src/tripit.ts
48088
+ function mimeTypeForPath(filePath) {
48089
+ switch (extname(filePath).toLowerCase()) {
48090
+ case ".pdf":
48091
+ return "application/pdf";
48092
+ case ".jpg":
48093
+ case ".jpeg":
48094
+ return "image/jpeg";
48095
+ case ".png":
48096
+ return "image/png";
48097
+ case ".gif":
48098
+ return "image/gif";
48099
+ default:
48100
+ return;
48101
+ }
48102
+ }
48103
+
48084
48104
  class TripIt {
48085
48105
  config;
48086
48106
  accessToken = null;
@@ -48186,14 +48206,14 @@ class TripIt {
48186
48206
  return this.apiGet(this.identifierEndpoint("delete", "trip", id));
48187
48207
  }
48188
48208
  async buildImageAttachment(params) {
48189
- const file = Bun.file(params.filePath);
48190
- const exists = await file.exists();
48191
- if (!exists) {
48209
+ try {
48210
+ await access(params.filePath);
48211
+ } catch {
48192
48212
  throw new Error(`File not found: ${params.filePath}`);
48193
48213
  }
48194
- const buffer = await file.arrayBuffer();
48195
- const base64Content = Buffer.from(buffer).toString("base64");
48196
- const mimeType = params.mimeType || file.type || "application/octet-stream";
48214
+ const buffer = await readFile(params.filePath);
48215
+ const base64Content = buffer.toString("base64");
48216
+ const mimeType = params.mimeType || mimeTypeForPath(params.filePath) || "application/pdf";
48197
48217
  const caption = params.caption || params.filePath.split("/").pop() || "document";
48198
48218
  return orderObjectByKeys({
48199
48219
  caption,
@@ -48390,11 +48410,11 @@ class TripIt {
48390
48410
  async createHotel(params) {
48391
48411
  const tripKey = params.tripId.includes("-") ? "trip_uuid" : "trip_id";
48392
48412
  return this.apiPost(this.endpoint("v2", "create/lodging"), {
48393
- LodgingObject: clean({
48413
+ LodgingObject: orderObjectByKeys(clean({
48394
48414
  [tripKey]: params.tripId,
48395
- supplier_name: params.hotelName,
48396
- supplier_conf_num: params.supplierConfNum,
48397
48415
  booking_rate: params.bookingRate,
48416
+ supplier_conf_num: params.supplierConfNum,
48417
+ supplier_name: params.hotelName,
48398
48418
  notes: params.notes,
48399
48419
  total_cost: params.totalCost,
48400
48420
  StartDateTime: {
@@ -48414,7 +48434,7 @@ class TripIt {
48414
48434
  zip: params.zip,
48415
48435
  country: params.country
48416
48436
  })
48417
- })
48437
+ }), LODGING_FIELD_ORDER)
48418
48438
  });
48419
48439
  }
48420
48440
  async updateHotel(params) {
@@ -48505,15 +48525,15 @@ class TripIt {
48505
48525
  service_class: s2.serviceClass
48506
48526
  }));
48507
48527
  return this.apiPost(this.endpoint("v2", "create/air"), {
48508
- AirObject: clean({
48528
+ AirObject: orderObjectByKeys(clean({
48509
48529
  trip_uuid: params.tripId,
48510
48530
  display_name: params.displayName,
48511
- supplier_name: params.supplierName,
48512
48531
  supplier_conf_num: params.supplierConfNum,
48532
+ supplier_name: params.supplierName,
48513
48533
  notes: params.notes,
48514
48534
  total_cost: params.totalCost,
48515
48535
  Segment: segments
48516
- })
48536
+ }), AIR_FIELD_ORDER)
48517
48537
  });
48518
48538
  }
48519
48539
  async updateFlight(params) {
@@ -48557,8 +48577,8 @@ class TripIt {
48557
48577
  uuid: existingFlight.uuid,
48558
48578
  is_client_traveler: toBoolean(existingFlight.is_client_traveler),
48559
48579
  display_name: params.displayName ?? existingFlight.display_name,
48560
- supplier_name: params.supplierName ?? existingFlight.supplier_name,
48561
48580
  supplier_conf_num: params.supplierConfNum ?? existingFlight.supplier_conf_num,
48581
+ supplier_name: params.supplierName ?? existingFlight.supplier_name,
48562
48582
  is_purchased: toBoolean(existingFlight.is_purchased),
48563
48583
  notes: params.notes ?? existingFlight.notes,
48564
48584
  total_cost: params.totalCost ?? existingFlight.total_cost,
package/dist/tripit.js CHANGED
@@ -35308,6 +35308,10 @@ var {
35308
35308
  Help
35309
35309
  } = import__.default;
35310
35310
 
35311
+ // src/tripit.ts
35312
+ import { access, readFile } from "node:fs/promises";
35313
+ import { extname } from "node:path";
35314
+
35311
35315
  // node_modules/node-fetch/src/index.js
35312
35316
  import http2 from "node:http";
35313
35317
  import https from "node:https";
@@ -49900,14 +49904,14 @@ var TRIP_UPDATE_FIELD_ORDER = [
49900
49904
  ];
49901
49905
  var LODGING_FIELD_ORDER = [
49902
49906
  "uuid",
49903
- "trip_uuid",
49904
49907
  "trip_id",
49908
+ "trip_uuid",
49905
49909
  "is_client_traveler",
49906
49910
  "display_name",
49907
49911
  "Image",
49908
- "supplier_name",
49909
- "supplier_conf_num",
49910
49912
  "booking_rate",
49913
+ "supplier_conf_num",
49914
+ "supplier_name",
49911
49915
  "is_purchased",
49912
49916
  "notes",
49913
49917
  "total_cost",
@@ -49917,13 +49921,13 @@ var LODGING_FIELD_ORDER = [
49917
49921
  ];
49918
49922
  var AIR_FIELD_ORDER = [
49919
49923
  "uuid",
49920
- "trip_uuid",
49921
49924
  "trip_id",
49925
+ "trip_uuid",
49922
49926
  "is_client_traveler",
49923
49927
  "display_name",
49924
49928
  "Image",
49925
- "supplier_name",
49926
49929
  "supplier_conf_num",
49930
+ "supplier_name",
49927
49931
  "is_purchased",
49928
49932
  "notes",
49929
49933
  "total_cost",
@@ -49944,8 +49948,8 @@ var AIR_SEGMENT_FIELD_ORDER = [
49944
49948
  ];
49945
49949
  var TRANSPORT_FIELD_ORDER = [
49946
49950
  "uuid",
49947
- "trip_uuid",
49948
49951
  "trip_id",
49952
+ "trip_uuid",
49949
49953
  "is_client_traveler",
49950
49954
  "display_name",
49951
49955
  "Image",
@@ -49968,8 +49972,8 @@ var TRANSPORT_SEGMENT_FIELD_ORDER = [
49968
49972
  ];
49969
49973
  var ACTIVITY_FIELD_ORDER = [
49970
49974
  "uuid",
49971
- "trip_uuid",
49972
49975
  "trip_id",
49976
+ "trip_uuid",
49973
49977
  "is_client_traveler",
49974
49978
  "display_name",
49975
49979
  "Image",
@@ -50191,6 +50195,22 @@ function toBoolean(value) {
50191
50195
  }
50192
50196
 
50193
50197
  // src/tripit.ts
50198
+ function mimeTypeForPath(filePath) {
50199
+ switch (extname(filePath).toLowerCase()) {
50200
+ case ".pdf":
50201
+ return "application/pdf";
50202
+ case ".jpg":
50203
+ case ".jpeg":
50204
+ return "image/jpeg";
50205
+ case ".png":
50206
+ return "image/png";
50207
+ case ".gif":
50208
+ return "image/gif";
50209
+ default:
50210
+ return;
50211
+ }
50212
+ }
50213
+
50194
50214
  class TripIt {
50195
50215
  config;
50196
50216
  accessToken = null;
@@ -50296,14 +50316,14 @@ class TripIt {
50296
50316
  return this.apiGet(this.identifierEndpoint("delete", "trip", id));
50297
50317
  }
50298
50318
  async buildImageAttachment(params) {
50299
- const file = Bun.file(params.filePath);
50300
- const exists = await file.exists();
50301
- if (!exists) {
50319
+ try {
50320
+ await access(params.filePath);
50321
+ } catch {
50302
50322
  throw new Error(`File not found: ${params.filePath}`);
50303
50323
  }
50304
- const buffer = await file.arrayBuffer();
50305
- const base64Content = Buffer.from(buffer).toString("base64");
50306
- const mimeType = params.mimeType || file.type || "application/octet-stream";
50324
+ const buffer = await readFile(params.filePath);
50325
+ const base64Content = buffer.toString("base64");
50326
+ const mimeType = params.mimeType || mimeTypeForPath(params.filePath) || "application/pdf";
50307
50327
  const caption = params.caption || params.filePath.split("/").pop() || "document";
50308
50328
  return orderObjectByKeys({
50309
50329
  caption,
@@ -50500,11 +50520,11 @@ class TripIt {
50500
50520
  async createHotel(params) {
50501
50521
  const tripKey = params.tripId.includes("-") ? "trip_uuid" : "trip_id";
50502
50522
  return this.apiPost(this.endpoint("v2", "create/lodging"), {
50503
- LodgingObject: clean({
50523
+ LodgingObject: orderObjectByKeys(clean({
50504
50524
  [tripKey]: params.tripId,
50505
- supplier_name: params.hotelName,
50506
- supplier_conf_num: params.supplierConfNum,
50507
50525
  booking_rate: params.bookingRate,
50526
+ supplier_conf_num: params.supplierConfNum,
50527
+ supplier_name: params.hotelName,
50508
50528
  notes: params.notes,
50509
50529
  total_cost: params.totalCost,
50510
50530
  StartDateTime: {
@@ -50524,7 +50544,7 @@ class TripIt {
50524
50544
  zip: params.zip,
50525
50545
  country: params.country
50526
50546
  })
50527
- })
50547
+ }), LODGING_FIELD_ORDER)
50528
50548
  });
50529
50549
  }
50530
50550
  async updateHotel(params) {
@@ -50615,15 +50635,15 @@ class TripIt {
50615
50635
  service_class: s2.serviceClass
50616
50636
  }));
50617
50637
  return this.apiPost(this.endpoint("v2", "create/air"), {
50618
- AirObject: clean({
50638
+ AirObject: orderObjectByKeys(clean({
50619
50639
  trip_uuid: params.tripId,
50620
50640
  display_name: params.displayName,
50621
- supplier_name: params.supplierName,
50622
50641
  supplier_conf_num: params.supplierConfNum,
50642
+ supplier_name: params.supplierName,
50623
50643
  notes: params.notes,
50624
50644
  total_cost: params.totalCost,
50625
50645
  Segment: segments
50626
- })
50646
+ }), AIR_FIELD_ORDER)
50627
50647
  });
50628
50648
  }
50629
50649
  async updateFlight(params) {
@@ -50667,8 +50687,8 @@ class TripIt {
50667
50687
  uuid: existingFlight.uuid,
50668
50688
  is_client_traveler: toBoolean(existingFlight.is_client_traveler),
50669
50689
  display_name: params.displayName ?? existingFlight.display_name,
50670
- supplier_name: params.supplierName ?? existingFlight.supplier_name,
50671
50690
  supplier_conf_num: params.supplierConfNum ?? existingFlight.supplier_conf_num,
50691
+ supplier_name: params.supplierName ?? existingFlight.supplier_name,
50672
50692
  is_purchased: toBoolean(existingFlight.is_purchased),
50673
50693
  notes: params.notes ?? existingFlight.notes,
50674
50694
  total_cost: params.totalCost ?? existingFlight.total_cost,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripit",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",