tripit 0.1.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/README.md +127 -0
- package/index.ts +1024 -0
- package/package.json +45 -0
- package/src/auth.ts +242 -0
- package/src/constants.ts +141 -0
- package/src/index.ts +2 -0
- package/src/tripit.ts +1295 -0
- package/src/types.ts +296 -0
- package/src/utils.ts +41 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
export interface CachedToken {
|
|
2
|
+
access_token: string;
|
|
3
|
+
expires_in: number;
|
|
4
|
+
token_type: string;
|
|
5
|
+
scope: string;
|
|
6
|
+
expiresAt: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TripItConfig {
|
|
10
|
+
clientId: string;
|
|
11
|
+
clientSecret: string;
|
|
12
|
+
username: string;
|
|
13
|
+
password: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type OneOrMany<T> = T | T[];
|
|
17
|
+
|
|
18
|
+
export interface ApiMetadata {
|
|
19
|
+
timestamp: string;
|
|
20
|
+
num_bytes: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface DeleteResponse {
|
|
24
|
+
timestamp: string;
|
|
25
|
+
num_bytes: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface WarningMessage {
|
|
29
|
+
description: string;
|
|
30
|
+
entity_type: string;
|
|
31
|
+
timestamp: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface WarningContainer {
|
|
35
|
+
Warning?: OneOrMany<WarningMessage>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface DateTimeValue {
|
|
39
|
+
date: string;
|
|
40
|
+
time: string;
|
|
41
|
+
timezone: string;
|
|
42
|
+
utc_offset?: string;
|
|
43
|
+
is_timezone_manual?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface AddressValue {
|
|
47
|
+
address?: string;
|
|
48
|
+
city?: string;
|
|
49
|
+
state?: string;
|
|
50
|
+
zip?: string;
|
|
51
|
+
country?: string;
|
|
52
|
+
latitude?: string;
|
|
53
|
+
longitude?: string;
|
|
54
|
+
risk_level?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface TripInvitee {
|
|
58
|
+
"@attributes"?: {
|
|
59
|
+
profile_ref?: string;
|
|
60
|
+
};
|
|
61
|
+
is_read_only?: string;
|
|
62
|
+
is_traveler?: string;
|
|
63
|
+
is_owner?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface TripPurposes {
|
|
67
|
+
purpose_type_code?: string;
|
|
68
|
+
is_auto_generated?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface TripRecord {
|
|
72
|
+
uuid: string;
|
|
73
|
+
relative_url?: string;
|
|
74
|
+
start_date?: string;
|
|
75
|
+
end_date?: string;
|
|
76
|
+
description?: string;
|
|
77
|
+
display_name?: string;
|
|
78
|
+
image_url?: string;
|
|
79
|
+
is_private?: string;
|
|
80
|
+
is_expensible?: string;
|
|
81
|
+
primary_location?: string;
|
|
82
|
+
PrimaryLocationAddress?: AddressValue;
|
|
83
|
+
TripInvitees?: {
|
|
84
|
+
Invitee?: OneOrMany<TripInvitee>;
|
|
85
|
+
};
|
|
86
|
+
TripPurposes?: TripPurposes;
|
|
87
|
+
is_pro_enabled?: string;
|
|
88
|
+
last_modified?: string;
|
|
89
|
+
is_concur_linked?: string;
|
|
90
|
+
public_guid?: string;
|
|
91
|
+
is_trip_owner_inner_circle_sharer?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface WeatherObject {
|
|
95
|
+
trip_uuid?: string;
|
|
96
|
+
is_client_traveler?: string;
|
|
97
|
+
display_name?: string;
|
|
98
|
+
is_display_name_auto_generated?: string;
|
|
99
|
+
last_modified?: string;
|
|
100
|
+
date?: string;
|
|
101
|
+
location?: string;
|
|
102
|
+
avg_high_temp_c?: string;
|
|
103
|
+
avg_low_temp_c?: string;
|
|
104
|
+
avg_wind_speed_kn?: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface ImageData {
|
|
108
|
+
content: string;
|
|
109
|
+
mime_type: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface TripImage {
|
|
113
|
+
caption?: string;
|
|
114
|
+
url?: string;
|
|
115
|
+
id?: string;
|
|
116
|
+
uuid?: string;
|
|
117
|
+
segment_id?: string;
|
|
118
|
+
segment_uuid?: string;
|
|
119
|
+
thumbnail_url?: string;
|
|
120
|
+
ImageData?: ImageData;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface TripListResponse extends ApiMetadata {
|
|
124
|
+
Trip: OneOrMany<TripRecord>;
|
|
125
|
+
Profile?: Record<string, unknown>;
|
|
126
|
+
page_num?: string;
|
|
127
|
+
page_size?: string;
|
|
128
|
+
max_page?: string;
|
|
129
|
+
total_items?: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface TripMutationResponse extends ApiMetadata {
|
|
133
|
+
Trip: TripRecord;
|
|
134
|
+
Profile?: Record<string, unknown>;
|
|
135
|
+
WeatherObject?: OneOrMany<WeatherObject>;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface LodgingObject {
|
|
139
|
+
uuid: string;
|
|
140
|
+
trip_uuid?: string;
|
|
141
|
+
trip_id?: string;
|
|
142
|
+
is_client_traveler?: string;
|
|
143
|
+
relative_url?: string;
|
|
144
|
+
display_name?: string;
|
|
145
|
+
Image?: OneOrMany<TripImage>;
|
|
146
|
+
is_display_name_auto_generated?: string;
|
|
147
|
+
last_modified?: string;
|
|
148
|
+
supplier_name?: string;
|
|
149
|
+
supplier_conf_num?: string;
|
|
150
|
+
booking_rate?: string;
|
|
151
|
+
is_purchased?: string;
|
|
152
|
+
notes?: string;
|
|
153
|
+
total_cost?: string;
|
|
154
|
+
is_tripit_booking?: string;
|
|
155
|
+
has_possible_cancellation?: string;
|
|
156
|
+
is_concur_booked?: string;
|
|
157
|
+
StartDateTime?: DateTimeValue;
|
|
158
|
+
EndDateTime?: DateTimeValue;
|
|
159
|
+
Address?: AddressValue;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface AirSegmentStatus {
|
|
163
|
+
flight_status?: string;
|
|
164
|
+
last_modified?: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface AirSegmentEmissions {
|
|
168
|
+
co2?: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface AirSegment {
|
|
172
|
+
uuid?: string;
|
|
173
|
+
StartDateTime?: DateTimeValue;
|
|
174
|
+
EndDateTime?: DateTimeValue;
|
|
175
|
+
Status?: AirSegmentStatus;
|
|
176
|
+
start_airport_code?: string;
|
|
177
|
+
start_airport_name?: string;
|
|
178
|
+
start_airport_latitude?: string;
|
|
179
|
+
start_airport_longitude?: string;
|
|
180
|
+
start_city_name?: string;
|
|
181
|
+
start_country_code?: string;
|
|
182
|
+
end_airport_code?: string;
|
|
183
|
+
end_airport_name?: string;
|
|
184
|
+
end_airport_latitude?: string;
|
|
185
|
+
end_airport_longitude?: string;
|
|
186
|
+
end_city_name?: string;
|
|
187
|
+
end_country_code?: string;
|
|
188
|
+
marketing_airline?: string;
|
|
189
|
+
marketing_airline_code?: string;
|
|
190
|
+
marketing_flight_number?: string;
|
|
191
|
+
aircraft?: string;
|
|
192
|
+
service_class?: string;
|
|
193
|
+
is_eligible_seattracker?: string;
|
|
194
|
+
is_eligible_airhelp?: string;
|
|
195
|
+
is_hidden?: string;
|
|
196
|
+
is_international?: string;
|
|
197
|
+
does_cross_idl?: string;
|
|
198
|
+
Emissions?: AirSegmentEmissions;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface AirObject {
|
|
202
|
+
uuid: string;
|
|
203
|
+
trip_uuid?: string;
|
|
204
|
+
trip_id?: string;
|
|
205
|
+
is_client_traveler?: string;
|
|
206
|
+
relative_url?: string;
|
|
207
|
+
display_name?: string;
|
|
208
|
+
Image?: OneOrMany<TripImage>;
|
|
209
|
+
is_display_name_auto_generated?: string;
|
|
210
|
+
last_modified?: string;
|
|
211
|
+
supplier_name?: string;
|
|
212
|
+
supplier_conf_num?: string;
|
|
213
|
+
is_purchased?: string;
|
|
214
|
+
notes?: string;
|
|
215
|
+
total_cost?: string;
|
|
216
|
+
is_tripit_booking?: string;
|
|
217
|
+
has_possible_cancellation?: string;
|
|
218
|
+
is_concur_booked?: string;
|
|
219
|
+
Segment?: OneOrMany<AirSegment>;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface TransportSegment {
|
|
223
|
+
uuid?: string;
|
|
224
|
+
StartLocationAddress?: AddressValue;
|
|
225
|
+
StartDateTime?: DateTimeValue;
|
|
226
|
+
EndLocationAddress?: AddressValue;
|
|
227
|
+
EndDateTime?: DateTimeValue;
|
|
228
|
+
vehicle_description?: string;
|
|
229
|
+
start_location_name?: string;
|
|
230
|
+
end_location_name?: string;
|
|
231
|
+
confirmation_num?: string;
|
|
232
|
+
carrier_name?: string;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface TransportObject {
|
|
236
|
+
uuid: string;
|
|
237
|
+
trip_uuid?: string;
|
|
238
|
+
trip_id?: string;
|
|
239
|
+
is_client_traveler?: string;
|
|
240
|
+
relative_url?: string;
|
|
241
|
+
display_name?: string;
|
|
242
|
+
Image?: OneOrMany<TripImage>;
|
|
243
|
+
is_display_name_auto_generated?: string;
|
|
244
|
+
last_modified?: string;
|
|
245
|
+
is_purchased?: string;
|
|
246
|
+
is_tripit_booking?: string;
|
|
247
|
+
has_possible_cancellation?: string;
|
|
248
|
+
is_concur_booked?: string;
|
|
249
|
+
Segment?: OneOrMany<TransportSegment>;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export interface ActivityObject {
|
|
253
|
+
uuid: string;
|
|
254
|
+
trip_uuid?: string;
|
|
255
|
+
trip_id?: string;
|
|
256
|
+
is_client_traveler?: string;
|
|
257
|
+
relative_url?: string;
|
|
258
|
+
display_name?: string;
|
|
259
|
+
Image?: OneOrMany<TripImage>;
|
|
260
|
+
is_display_name_auto_generated?: string;
|
|
261
|
+
last_modified?: string;
|
|
262
|
+
is_purchased?: string;
|
|
263
|
+
notes?: string;
|
|
264
|
+
is_tripit_booking?: string;
|
|
265
|
+
is_concur_booked?: string;
|
|
266
|
+
StartDateTime?: DateTimeValue;
|
|
267
|
+
EndDateTime?: DateTimeValue;
|
|
268
|
+
end_time?: string;
|
|
269
|
+
Address?: AddressValue;
|
|
270
|
+
location_name?: string;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface TripGetResponse extends ApiMetadata {
|
|
274
|
+
Trip: TripRecord;
|
|
275
|
+
WeatherObject?: OneOrMany<WeatherObject>;
|
|
276
|
+
AirObject?: OneOrMany<AirObject>;
|
|
277
|
+
LodgingObject?: OneOrMany<LodgingObject>;
|
|
278
|
+
TransportObject?: OneOrMany<TransportObject>;
|
|
279
|
+
ActivityObject?: OneOrMany<ActivityObject>;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export interface LodgingResponse extends ApiMetadata, WarningContainer {
|
|
283
|
+
LodgingObject: LodgingObject;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export interface AirResponse extends ApiMetadata, WarningContainer {
|
|
287
|
+
AirObject: AirObject;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export interface TransportResponse extends ApiMetadata, WarningContainer {
|
|
291
|
+
TransportObject: TransportObject;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export interface ActivityResponse extends ApiMetadata, WarningContainer {
|
|
295
|
+
ActivityObject: ActivityObject;
|
|
296
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function normalizeTime(time: string): string | undefined {
|
|
2
|
+
if (!time) return undefined;
|
|
3
|
+
const parts = time.split(":");
|
|
4
|
+
if (parts.length === 2) return `${time}:00`;
|
|
5
|
+
return time;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function clean(obj: any): any {
|
|
9
|
+
if (typeof obj !== "object" || obj === null) return obj;
|
|
10
|
+
if (Array.isArray(obj))
|
|
11
|
+
return obj.map(clean).filter((v) => v !== undefined && v !== null);
|
|
12
|
+
return Object.entries(obj).reduce<Record<string, any>>((acc, [k, v]) => {
|
|
13
|
+
if (v !== undefined && v !== null) acc[k] = clean(v);
|
|
14
|
+
return acc;
|
|
15
|
+
}, {});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function normalizeArray(node: any): any[] {
|
|
19
|
+
if (!node) return [];
|
|
20
|
+
if (Array.isArray(node)) return node;
|
|
21
|
+
return [node];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function orderObjectByKeys<T extends object>(
|
|
25
|
+
obj: T,
|
|
26
|
+
orderArray: readonly string[],
|
|
27
|
+
): T {
|
|
28
|
+
return orderArray.reduce<T>((ordered, key) => {
|
|
29
|
+
if (key in obj) {
|
|
30
|
+
ordered[key as keyof T] = obj[key as keyof T];
|
|
31
|
+
}
|
|
32
|
+
return ordered;
|
|
33
|
+
}, {} as T);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function toBoolean(value: unknown): boolean | undefined {
|
|
37
|
+
if (value === undefined || value === null) return undefined;
|
|
38
|
+
if (typeof value === "boolean") return value;
|
|
39
|
+
if (typeof value === "string") return value === "true";
|
|
40
|
+
return Boolean(value);
|
|
41
|
+
}
|