tripit 0.1.5 → 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",
@@ -48012,7 +48016,6 @@ async function authenticate(config) {
48012
48016
  const fetchCookie2 = (await Promise.resolve().then(() => (init_esm(), exports_esm4))).default;
48013
48017
  const { CookieJar: CookieJar2 } = await Promise.resolve().then(() => (init_dist(), exports_dist));
48014
48018
  const fetchWithCookie = fetchCookie2(fetch, new CookieJar2);
48015
- await fetchWithCookie(`${BASE_URL}/home`, { headers: BROWSER_HEADERS });
48016
48019
  const codeVerifier = crypto.randomBytes(32).toString("hex");
48017
48020
  const codeChallenge = crypto.createHash("sha256").update(codeVerifier).digest().toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
48018
48021
  const state = crypto.randomBytes(16).toString("hex");
@@ -48082,6 +48085,22 @@ function toBoolean(value) {
48082
48085
  }
48083
48086
 
48084
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
+
48085
48104
  class TripIt {
48086
48105
  config;
48087
48106
  accessToken = null;
@@ -48187,14 +48206,14 @@ class TripIt {
48187
48206
  return this.apiGet(this.identifierEndpoint("delete", "trip", id));
48188
48207
  }
48189
48208
  async buildImageAttachment(params) {
48190
- const file = Bun.file(params.filePath);
48191
- const exists = await file.exists();
48192
- if (!exists) {
48209
+ try {
48210
+ await access(params.filePath);
48211
+ } catch {
48193
48212
  throw new Error(`File not found: ${params.filePath}`);
48194
48213
  }
48195
- const buffer = await file.arrayBuffer();
48196
- const base64Content = Buffer.from(buffer).toString("base64");
48197
- 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";
48198
48217
  const caption = params.caption || params.filePath.split("/").pop() || "document";
48199
48218
  return orderObjectByKeys({
48200
48219
  caption,
@@ -48391,11 +48410,11 @@ class TripIt {
48391
48410
  async createHotel(params) {
48392
48411
  const tripKey = params.tripId.includes("-") ? "trip_uuid" : "trip_id";
48393
48412
  return this.apiPost(this.endpoint("v2", "create/lodging"), {
48394
- LodgingObject: clean({
48413
+ LodgingObject: orderObjectByKeys(clean({
48395
48414
  [tripKey]: params.tripId,
48396
- supplier_name: params.hotelName,
48397
- supplier_conf_num: params.supplierConfNum,
48398
48415
  booking_rate: params.bookingRate,
48416
+ supplier_conf_num: params.supplierConfNum,
48417
+ supplier_name: params.hotelName,
48399
48418
  notes: params.notes,
48400
48419
  total_cost: params.totalCost,
48401
48420
  StartDateTime: {
@@ -48415,7 +48434,7 @@ class TripIt {
48415
48434
  zip: params.zip,
48416
48435
  country: params.country
48417
48436
  })
48418
- })
48437
+ }), LODGING_FIELD_ORDER)
48419
48438
  });
48420
48439
  }
48421
48440
  async updateHotel(params) {
@@ -48506,15 +48525,15 @@ class TripIt {
48506
48525
  service_class: s2.serviceClass
48507
48526
  }));
48508
48527
  return this.apiPost(this.endpoint("v2", "create/air"), {
48509
- AirObject: clean({
48528
+ AirObject: orderObjectByKeys(clean({
48510
48529
  trip_uuid: params.tripId,
48511
48530
  display_name: params.displayName,
48512
- supplier_name: params.supplierName,
48513
48531
  supplier_conf_num: params.supplierConfNum,
48532
+ supplier_name: params.supplierName,
48514
48533
  notes: params.notes,
48515
48534
  total_cost: params.totalCost,
48516
48535
  Segment: segments
48517
- })
48536
+ }), AIR_FIELD_ORDER)
48518
48537
  });
48519
48538
  }
48520
48539
  async updateFlight(params) {
@@ -48558,8 +48577,8 @@ class TripIt {
48558
48577
  uuid: existingFlight.uuid,
48559
48578
  is_client_traveler: toBoolean(existingFlight.is_client_traveler),
48560
48579
  display_name: params.displayName ?? existingFlight.display_name,
48561
- supplier_name: params.supplierName ?? existingFlight.supplier_name,
48562
48580
  supplier_conf_num: params.supplierConfNum ?? existingFlight.supplier_conf_num,
48581
+ supplier_name: params.supplierName ?? existingFlight.supplier_name,
48563
48582
  is_purchased: toBoolean(existingFlight.is_purchased),
48564
48583
  notes: params.notes ?? existingFlight.notes,
48565
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",
@@ -50122,7 +50126,6 @@ async function authenticate(config) {
50122
50126
  const fetchCookie2 = (await Promise.resolve().then(() => (init_esm(), exports_esm4))).default;
50123
50127
  const { CookieJar: CookieJar2 } = await Promise.resolve().then(() => (init_dist(), exports_dist));
50124
50128
  const fetchWithCookie = fetchCookie2(fetch, new CookieJar2);
50125
- await fetchWithCookie(`${BASE_URL}/home`, { headers: BROWSER_HEADERS });
50126
50129
  const codeVerifier = crypto.randomBytes(32).toString("hex");
50127
50130
  const codeChallenge = crypto.createHash("sha256").update(codeVerifier).digest().toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
50128
50131
  const state = crypto.randomBytes(16).toString("hex");
@@ -50192,6 +50195,22 @@ function toBoolean(value) {
50192
50195
  }
50193
50196
 
50194
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
+
50195
50214
  class TripIt {
50196
50215
  config;
50197
50216
  accessToken = null;
@@ -50297,14 +50316,14 @@ class TripIt {
50297
50316
  return this.apiGet(this.identifierEndpoint("delete", "trip", id));
50298
50317
  }
50299
50318
  async buildImageAttachment(params) {
50300
- const file = Bun.file(params.filePath);
50301
- const exists = await file.exists();
50302
- if (!exists) {
50319
+ try {
50320
+ await access(params.filePath);
50321
+ } catch {
50303
50322
  throw new Error(`File not found: ${params.filePath}`);
50304
50323
  }
50305
- const buffer = await file.arrayBuffer();
50306
- const base64Content = Buffer.from(buffer).toString("base64");
50307
- 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";
50308
50327
  const caption = params.caption || params.filePath.split("/").pop() || "document";
50309
50328
  return orderObjectByKeys({
50310
50329
  caption,
@@ -50501,11 +50520,11 @@ class TripIt {
50501
50520
  async createHotel(params) {
50502
50521
  const tripKey = params.tripId.includes("-") ? "trip_uuid" : "trip_id";
50503
50522
  return this.apiPost(this.endpoint("v2", "create/lodging"), {
50504
- LodgingObject: clean({
50523
+ LodgingObject: orderObjectByKeys(clean({
50505
50524
  [tripKey]: params.tripId,
50506
- supplier_name: params.hotelName,
50507
- supplier_conf_num: params.supplierConfNum,
50508
50525
  booking_rate: params.bookingRate,
50526
+ supplier_conf_num: params.supplierConfNum,
50527
+ supplier_name: params.hotelName,
50509
50528
  notes: params.notes,
50510
50529
  total_cost: params.totalCost,
50511
50530
  StartDateTime: {
@@ -50525,7 +50544,7 @@ class TripIt {
50525
50544
  zip: params.zip,
50526
50545
  country: params.country
50527
50546
  })
50528
- })
50547
+ }), LODGING_FIELD_ORDER)
50529
50548
  });
50530
50549
  }
50531
50550
  async updateHotel(params) {
@@ -50616,15 +50635,15 @@ class TripIt {
50616
50635
  service_class: s2.serviceClass
50617
50636
  }));
50618
50637
  return this.apiPost(this.endpoint("v2", "create/air"), {
50619
- AirObject: clean({
50638
+ AirObject: orderObjectByKeys(clean({
50620
50639
  trip_uuid: params.tripId,
50621
50640
  display_name: params.displayName,
50622
- supplier_name: params.supplierName,
50623
50641
  supplier_conf_num: params.supplierConfNum,
50642
+ supplier_name: params.supplierName,
50624
50643
  notes: params.notes,
50625
50644
  total_cost: params.totalCost,
50626
50645
  Segment: segments
50627
- })
50646
+ }), AIR_FIELD_ORDER)
50628
50647
  });
50629
50648
  }
50630
50649
  async updateFlight(params) {
@@ -50668,8 +50687,8 @@ class TripIt {
50668
50687
  uuid: existingFlight.uuid,
50669
50688
  is_client_traveler: toBoolean(existingFlight.is_client_traveler),
50670
50689
  display_name: params.displayName ?? existingFlight.display_name,
50671
- supplier_name: params.supplierName ?? existingFlight.supplier_name,
50672
50690
  supplier_conf_num: params.supplierConfNum ?? existingFlight.supplier_conf_num,
50691
+ supplier_name: params.supplierName ?? existingFlight.supplier_name,
50673
50692
  is_purchased: toBoolean(existingFlight.is_purchased),
50674
50693
  notes: params.notes ?? existingFlight.notes,
50675
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.5",
3
+ "version": "0.1.7",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",