kaafil-js 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +37 -0
- package/dist/client-entry.cjs +1782 -0
- package/dist/client-entry.cjs.map +1 -0
- package/dist/client-entry.d.cts +187 -0
- package/dist/client-entry.d.ts +187 -0
- package/dist/client-entry.js +1739 -0
- package/dist/client-entry.js.map +1 -0
- package/dist/index.cjs +3541 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2311 -0
- package/dist/index.d.ts +2311 -0
- package/dist/index.js +3458 -0
- package/dist/index.js.map +1 -0
- package/dist/paginator-CE9JhsLi.d.cts +24009 -0
- package/dist/paginator-CE9JhsLi.d.ts +24009 -0
- package/package.json +75 -0
|
@@ -0,0 +1,1739 @@
|
|
|
1
|
+
// src/generated/security.ts
|
|
2
|
+
var SecuritySchemeId = {
|
|
3
|
+
AgencyAdminAuth: "agencyAdminAuth",
|
|
4
|
+
ApiKeyAuth: "apiKeyAuth",
|
|
5
|
+
ManagerAuth: "managerAuth",
|
|
6
|
+
ShareAuth: "shareAuth"
|
|
7
|
+
};
|
|
8
|
+
var SECURITY_SCHEME_CARRIERS = {
|
|
9
|
+
agencyAdminAuth: { kind: "bearer" },
|
|
10
|
+
apiKeyAuth: { kind: "header", headerName: "X-API-Key" },
|
|
11
|
+
consoleAuth: { kind: "cookie", cookieName: "kaafil_console_session" },
|
|
12
|
+
managerAuth: { kind: "bearer" },
|
|
13
|
+
platformAdminAuth: { kind: "bearer" },
|
|
14
|
+
shareAuth: { kind: "bearer" }
|
|
15
|
+
};
|
|
16
|
+
var OperationId = {
|
|
17
|
+
ListJourneyTriggers: "listJourneyTriggers",
|
|
18
|
+
ListTripVendors: "listTripVendors",
|
|
19
|
+
PatchJourneyTrigger: "patchJourneyTrigger",
|
|
20
|
+
ReadJourney: "readJourney",
|
|
21
|
+
ReadJourneyCapabilities: "readJourneyCapabilities",
|
|
22
|
+
RebuildJourney: "rebuildJourney",
|
|
23
|
+
RunJourneyStep: "runJourneyStep"};
|
|
24
|
+
var OPERATION_SECURITY = {
|
|
25
|
+
acceptConsoleInvite: [],
|
|
26
|
+
acceptPlatformAdminInvite: [],
|
|
27
|
+
addChecklistItem: ["managerAuth"],
|
|
28
|
+
addItineraryItem: ["managerAuth"],
|
|
29
|
+
adjustFloat: ["managerAuth", "apiKeyAuth", "agencyAdminAuth"],
|
|
30
|
+
assignManager: ["apiKeyAuth"],
|
|
31
|
+
assignPickupTraveller: ["managerAuth"],
|
|
32
|
+
assignRoomingBed: ["managerAuth"],
|
|
33
|
+
assignSeating: ["managerAuth"],
|
|
34
|
+
autoAssignRooming: ["managerAuth"],
|
|
35
|
+
autoAssignSeating: ["managerAuth"],
|
|
36
|
+
boardPickupTraveller: ["managerAuth"],
|
|
37
|
+
cancelTrip: ["apiKeyAuth"],
|
|
38
|
+
changeOwnPlatformPassword: ["platformAdminAuth"],
|
|
39
|
+
claimStatusIngest: ["apiKeyAuth"],
|
|
40
|
+
closePickupStop: ["managerAuth"],
|
|
41
|
+
confirmFileUpload: ["managerAuth"],
|
|
42
|
+
consoleLogin: [],
|
|
43
|
+
consoleLogout: ["consoleAuth"],
|
|
44
|
+
consoleSwitchPlane: ["consoleAuth"],
|
|
45
|
+
createApiKey: ["consoleAuth"],
|
|
46
|
+
createConsoleUser: ["consoleAuth"],
|
|
47
|
+
createPickupStop: ["managerAuth"],
|
|
48
|
+
createPlatformAdmin: ["platformAdminAuth"],
|
|
49
|
+
createPlatformPartner: ["platformAdminAuth"],
|
|
50
|
+
createPlatformPartnerConsoleUser: ["platformAdminAuth"],
|
|
51
|
+
createRoomingRoom: ["managerAuth"],
|
|
52
|
+
createRoomingStayWindow: ["managerAuth"],
|
|
53
|
+
createSeatingVehicle: ["managerAuth"],
|
|
54
|
+
createTrekWalkIn: ["managerAuth"],
|
|
55
|
+
deleteChecklistItem: ["managerAuth"],
|
|
56
|
+
deleteItineraryItem: ["managerAuth"],
|
|
57
|
+
deletePickupStop: ["managerAuth"],
|
|
58
|
+
deletePlatformPartnerPlan: ["platformAdminAuth"],
|
|
59
|
+
deleteRoomingRoom: ["managerAuth"],
|
|
60
|
+
deleteRoomingStayWindow: ["managerAuth"],
|
|
61
|
+
deleteSeatingVehicle: ["managerAuth"],
|
|
62
|
+
editWebhookEndpoint: ["consoleAuth"],
|
|
63
|
+
getTrip: ["apiKeyAuth"],
|
|
64
|
+
health: [],
|
|
65
|
+
healthV1: [],
|
|
66
|
+
inspectConsoleInvite: [],
|
|
67
|
+
inspectPlatformAdminInvite: [],
|
|
68
|
+
issueFloat: ["managerAuth", "apiKeyAuth", "agencyAdminAuth"],
|
|
69
|
+
linkExpenseReceipt: ["managerAuth"],
|
|
70
|
+
linkSeatingManager: ["managerAuth"],
|
|
71
|
+
listAgencies: ["consoleAuth"],
|
|
72
|
+
listApiKeys: ["consoleAuth"],
|
|
73
|
+
listChecklistTemplates: ["managerAuth", "apiKeyAuth"],
|
|
74
|
+
listCollections: ["managerAuth", "apiKeyAuth"],
|
|
75
|
+
listConsoleTrips: ["consoleAuth"],
|
|
76
|
+
listConsoleUsers: ["consoleAuth"],
|
|
77
|
+
listEligibleCollections: ["managerAuth", "apiKeyAuth"],
|
|
78
|
+
listEvents: ["apiKeyAuth"],
|
|
79
|
+
listExpenses: ["managerAuth", "apiKeyAuth"],
|
|
80
|
+
listJourneyTriggers: ["apiKeyAuth", "agencyAdminAuth"],
|
|
81
|
+
listPickupStops: ["managerAuth", "agencyAdminAuth", "apiKeyAuth"],
|
|
82
|
+
listPlatformAdmins: ["platformAdminAuth"],
|
|
83
|
+
listPlatformPartnerApiKeys: ["platformAdminAuth"],
|
|
84
|
+
listPlatformPartnerConsoleUsers: ["platformAdminAuth"],
|
|
85
|
+
listPlatformPartners: ["platformAdminAuth"],
|
|
86
|
+
listRoomingStayWindows: ["managerAuth", "agencyAdminAuth", "apiKeyAuth"],
|
|
87
|
+
listTripVendors: ["apiKeyAuth", "managerAuth", "agencyAdminAuth"],
|
|
88
|
+
listWebhookDeliveries: ["apiKeyAuth"],
|
|
89
|
+
listWebhookEndpoints: ["consoleAuth"],
|
|
90
|
+
logExpense: ["managerAuth"],
|
|
91
|
+
mintAgencyAdminTokens: ["apiKeyAuth"],
|
|
92
|
+
mintManagerTokens: ["apiKeyAuth"],
|
|
93
|
+
mintShareToken: ["apiKeyAuth"],
|
|
94
|
+
patchAgencyEntitlement: ["consoleAuth"],
|
|
95
|
+
patchChecklistItem: ["managerAuth"],
|
|
96
|
+
patchConsoleUser: ["consoleAuth"],
|
|
97
|
+
patchItineraryDay: ["managerAuth"],
|
|
98
|
+
patchItineraryItem: ["managerAuth"],
|
|
99
|
+
patchJourneyTrigger: ["apiKeyAuth", "agencyAdminAuth"],
|
|
100
|
+
patchPickupStop: ["managerAuth"],
|
|
101
|
+
patchPlatformAdmin: ["platformAdminAuth"],
|
|
102
|
+
patchPlatformPartnerConsoleUser: ["platformAdminAuth"],
|
|
103
|
+
patchRoomingRoom: ["managerAuth"],
|
|
104
|
+
patchRoomingStayWindow: ["managerAuth"],
|
|
105
|
+
patchSeatingVehicle: ["managerAuth"],
|
|
106
|
+
platformLogin: [],
|
|
107
|
+
platformLogout: ["platformAdminAuth"],
|
|
108
|
+
platformMe: ["platformAdminAuth"],
|
|
109
|
+
platformRefreshTokens: ["platformAdminAuth"],
|
|
110
|
+
postponeTrek: ["managerAuth"],
|
|
111
|
+
pullChecklistTemplate: ["managerAuth"],
|
|
112
|
+
pushBulkTrips: ["apiKeyAuth"],
|
|
113
|
+
pushManifest: ["apiKeyAuth"],
|
|
114
|
+
pushTripBalances: ["apiKeyAuth"],
|
|
115
|
+
putPlatformPartnerPlan: ["platformAdminAuth"],
|
|
116
|
+
readAgencyEntitlement: ["consoleAuth"],
|
|
117
|
+
readApiKey: ["consoleAuth"],
|
|
118
|
+
readChecklistAggregate: ["managerAuth", "apiKeyAuth"],
|
|
119
|
+
readConsoleAudit: ["consoleAuth"],
|
|
120
|
+
readConsoleChecklist: ["consoleAuth"],
|
|
121
|
+
readConsoleItinerary: ["consoleAuth"],
|
|
122
|
+
readConsolePickups: ["consoleAuth"],
|
|
123
|
+
readConsoleRooming: ["consoleAuth"],
|
|
124
|
+
readConsoleSeating: ["consoleAuth"],
|
|
125
|
+
readConsoleUserInvite: ["consoleAuth"],
|
|
126
|
+
readEndpointDeliveries: ["consoleAuth"],
|
|
127
|
+
readEndpointDelivery: ["consoleAuth"],
|
|
128
|
+
readEntitlementCatalog: ["consoleAuth"],
|
|
129
|
+
readExpense: ["managerAuth", "apiKeyAuth"],
|
|
130
|
+
readFile: ["managerAuth", "apiKeyAuth"],
|
|
131
|
+
readFileUrl: ["managerAuth", "apiKeyAuth"],
|
|
132
|
+
readFloatLedger: ["managerAuth", "agencyAdminAuth", "apiKeyAuth"],
|
|
133
|
+
readFloatSummary: ["managerAuth", "agencyAdminAuth", "apiKeyAuth"],
|
|
134
|
+
readIngestLog: ["consoleAuth"],
|
|
135
|
+
readItinerary: ["apiKeyAuth", "managerAuth", "agencyAdminAuth"],
|
|
136
|
+
readItineraryChangeLog: ["apiKeyAuth", "managerAuth", "agencyAdminAuth"],
|
|
137
|
+
readJourney: ["apiKeyAuth", "managerAuth", "agencyAdminAuth"],
|
|
138
|
+
readJourneyCapabilities: ["apiKeyAuth", "managerAuth", "agencyAdminAuth"],
|
|
139
|
+
readManifestByPickup: ["managerAuth", "agencyAdminAuth", "apiKeyAuth"],
|
|
140
|
+
readPlan: ["consoleAuth"],
|
|
141
|
+
readPlatformPartner: ["platformAdminAuth"],
|
|
142
|
+
readRoomingBoard: ["managerAuth", "agencyAdminAuth", "apiKeyAuth"],
|
|
143
|
+
readSeatingBoard: ["managerAuth", "agencyAdminAuth", "apiKeyAuth"],
|
|
144
|
+
readShareToken: ["apiKeyAuth"],
|
|
145
|
+
readTrekBoard: ["managerAuth", "apiKeyAuth"],
|
|
146
|
+
readTrekWalkInMeta: ["managerAuth", "apiKeyAuth"],
|
|
147
|
+
readUsage: ["consoleAuth"],
|
|
148
|
+
readWebhookDelivery: ["apiKeyAuth"],
|
|
149
|
+
readWebhookEndpoint: ["consoleAuth"],
|
|
150
|
+
rebuildJourney: ["apiKeyAuth"],
|
|
151
|
+
recordCollection: ["managerAuth"],
|
|
152
|
+
redeliverEndpointDelivery: ["consoleAuth"],
|
|
153
|
+
redeliverWebhookDelivery: ["apiKeyAuth"],
|
|
154
|
+
refreshAgencyAdminTokens: ["agencyAdminAuth"],
|
|
155
|
+
refreshManagerTokens: ["managerAuth"],
|
|
156
|
+
registerWebhookEndpoint: ["consoleAuth"],
|
|
157
|
+
reissueConsoleUserInvite: ["consoleAuth"],
|
|
158
|
+
reissuePlatformAdminInvite: ["platformAdminAuth"],
|
|
159
|
+
reissuePlatformPartnerConsoleUserInvite: ["platformAdminAuth"],
|
|
160
|
+
removeFromManifest: ["apiKeyAuth"],
|
|
161
|
+
renamePlatformPartner: ["platformAdminAuth"],
|
|
162
|
+
reopenPickupStop: ["managerAuth"],
|
|
163
|
+
reorderItineraryItem: ["managerAuth"],
|
|
164
|
+
reorderPickupStops: ["managerAuth"],
|
|
165
|
+
replayWebhookEndpoint: ["apiKeyAuth"],
|
|
166
|
+
requestFileUpload: ["managerAuth"],
|
|
167
|
+
resetPlatformPartnerConsoleUser: ["platformAdminAuth"],
|
|
168
|
+
returnFloat: ["managerAuth"],
|
|
169
|
+
revokeApiKey: ["consoleAuth"],
|
|
170
|
+
revokePlatformPartnerApiKey: ["platformAdminAuth"],
|
|
171
|
+
revokeShareToken: ["apiKeyAuth"],
|
|
172
|
+
rotateApiKey: ["consoleAuth"],
|
|
173
|
+
rotateWebhookEndpointSecret: ["consoleAuth"],
|
|
174
|
+
runJourneyStep: ["apiKeyAuth"],
|
|
175
|
+
setPlatformPartnerStatus: ["platformAdminAuth"],
|
|
176
|
+
submitExpenseClaim: ["managerAuth"],
|
|
177
|
+
toggleChecklistItem: ["managerAuth"],
|
|
178
|
+
unassignManager: ["apiKeyAuth"],
|
|
179
|
+
unlinkSeatingManager: ["managerAuth"],
|
|
180
|
+
upsertAgencyAdmin: ["apiKeyAuth"],
|
|
181
|
+
upsertManager: ["apiKeyAuth"],
|
|
182
|
+
upsertTravellerProfile: ["apiKeyAuth"],
|
|
183
|
+
upsertTrip: ["apiKeyAuth"],
|
|
184
|
+
voidCollection: ["managerAuth"],
|
|
185
|
+
voidExpense: ["managerAuth"],
|
|
186
|
+
withdrawExpenseClaim: ["managerAuth"]
|
|
187
|
+
};
|
|
188
|
+
var OPERATION_ACCEPTS_IDEMPOTENCY_KEY = {
|
|
189
|
+
acceptConsoleInvite: true,
|
|
190
|
+
acceptPlatformAdminInvite: true,
|
|
191
|
+
addChecklistItem: true,
|
|
192
|
+
addItineraryItem: true,
|
|
193
|
+
adjustFloat: true,
|
|
194
|
+
assignManager: true,
|
|
195
|
+
assignPickupTraveller: true,
|
|
196
|
+
assignRoomingBed: true,
|
|
197
|
+
assignSeating: true,
|
|
198
|
+
autoAssignRooming: true,
|
|
199
|
+
autoAssignSeating: true,
|
|
200
|
+
boardPickupTraveller: true,
|
|
201
|
+
cancelTrip: true,
|
|
202
|
+
changeOwnPlatformPassword: false,
|
|
203
|
+
claimStatusIngest: true,
|
|
204
|
+
closePickupStop: true,
|
|
205
|
+
confirmFileUpload: true,
|
|
206
|
+
consoleLogin: false,
|
|
207
|
+
consoleLogout: false,
|
|
208
|
+
consoleSwitchPlane: false,
|
|
209
|
+
createApiKey: true,
|
|
210
|
+
createConsoleUser: true,
|
|
211
|
+
createPickupStop: true,
|
|
212
|
+
createPlatformAdmin: false,
|
|
213
|
+
createPlatformPartner: false,
|
|
214
|
+
createPlatformPartnerConsoleUser: false,
|
|
215
|
+
createRoomingRoom: true,
|
|
216
|
+
createRoomingStayWindow: true,
|
|
217
|
+
createSeatingVehicle: true,
|
|
218
|
+
createTrekWalkIn: true,
|
|
219
|
+
deleteChecklistItem: false,
|
|
220
|
+
deleteItineraryItem: false,
|
|
221
|
+
deletePickupStop: false,
|
|
222
|
+
deletePlatformPartnerPlan: false,
|
|
223
|
+
deleteRoomingRoom: false,
|
|
224
|
+
deleteRoomingStayWindow: false,
|
|
225
|
+
deleteSeatingVehicle: false,
|
|
226
|
+
editWebhookEndpoint: true,
|
|
227
|
+
getTrip: false,
|
|
228
|
+
health: false,
|
|
229
|
+
healthV1: false,
|
|
230
|
+
inspectConsoleInvite: false,
|
|
231
|
+
inspectPlatformAdminInvite: false,
|
|
232
|
+
issueFloat: true,
|
|
233
|
+
linkExpenseReceipt: true,
|
|
234
|
+
linkSeatingManager: true,
|
|
235
|
+
listAgencies: false,
|
|
236
|
+
listApiKeys: false,
|
|
237
|
+
listChecklistTemplates: false,
|
|
238
|
+
listCollections: false,
|
|
239
|
+
listConsoleTrips: false,
|
|
240
|
+
listConsoleUsers: false,
|
|
241
|
+
listEligibleCollections: false,
|
|
242
|
+
listEvents: false,
|
|
243
|
+
listExpenses: false,
|
|
244
|
+
listJourneyTriggers: false,
|
|
245
|
+
listPickupStops: false,
|
|
246
|
+
listPlatformAdmins: false,
|
|
247
|
+
listPlatformPartnerApiKeys: false,
|
|
248
|
+
listPlatformPartnerConsoleUsers: false,
|
|
249
|
+
listPlatformPartners: false,
|
|
250
|
+
listRoomingStayWindows: false,
|
|
251
|
+
listTripVendors: false,
|
|
252
|
+
listWebhookDeliveries: false,
|
|
253
|
+
listWebhookEndpoints: false,
|
|
254
|
+
logExpense: true,
|
|
255
|
+
mintAgencyAdminTokens: false,
|
|
256
|
+
mintManagerTokens: false,
|
|
257
|
+
mintShareToken: true,
|
|
258
|
+
patchAgencyEntitlement: true,
|
|
259
|
+
patchChecklistItem: false,
|
|
260
|
+
patchConsoleUser: true,
|
|
261
|
+
patchItineraryDay: false,
|
|
262
|
+
patchItineraryItem: false,
|
|
263
|
+
patchJourneyTrigger: true,
|
|
264
|
+
patchPickupStop: false,
|
|
265
|
+
patchPlatformAdmin: false,
|
|
266
|
+
patchPlatformPartnerConsoleUser: false,
|
|
267
|
+
patchRoomingRoom: false,
|
|
268
|
+
patchRoomingStayWindow: false,
|
|
269
|
+
patchSeatingVehicle: false,
|
|
270
|
+
platformLogin: true,
|
|
271
|
+
platformLogout: false,
|
|
272
|
+
platformMe: false,
|
|
273
|
+
platformRefreshTokens: true,
|
|
274
|
+
postponeTrek: true,
|
|
275
|
+
pullChecklistTemplate: true,
|
|
276
|
+
pushBulkTrips: true,
|
|
277
|
+
pushManifest: true,
|
|
278
|
+
pushTripBalances: true,
|
|
279
|
+
putPlatformPartnerPlan: false,
|
|
280
|
+
readAgencyEntitlement: false,
|
|
281
|
+
readApiKey: false,
|
|
282
|
+
readChecklistAggregate: false,
|
|
283
|
+
readConsoleAudit: false,
|
|
284
|
+
readConsoleChecklist: false,
|
|
285
|
+
readConsoleItinerary: false,
|
|
286
|
+
readConsolePickups: false,
|
|
287
|
+
readConsoleRooming: false,
|
|
288
|
+
readConsoleSeating: false,
|
|
289
|
+
readConsoleUserInvite: false,
|
|
290
|
+
readEndpointDeliveries: false,
|
|
291
|
+
readEndpointDelivery: false,
|
|
292
|
+
readEntitlementCatalog: false,
|
|
293
|
+
readExpense: false,
|
|
294
|
+
readFile: false,
|
|
295
|
+
readFileUrl: false,
|
|
296
|
+
readFloatLedger: false,
|
|
297
|
+
readFloatSummary: false,
|
|
298
|
+
readIngestLog: false,
|
|
299
|
+
readItinerary: false,
|
|
300
|
+
readItineraryChangeLog: false,
|
|
301
|
+
readJourney: false,
|
|
302
|
+
readJourneyCapabilities: false,
|
|
303
|
+
readManifestByPickup: false,
|
|
304
|
+
readPlan: false,
|
|
305
|
+
readPlatformPartner: false,
|
|
306
|
+
readRoomingBoard: false,
|
|
307
|
+
readSeatingBoard: false,
|
|
308
|
+
readShareToken: false,
|
|
309
|
+
readTrekBoard: false,
|
|
310
|
+
readTrekWalkInMeta: false,
|
|
311
|
+
readUsage: false,
|
|
312
|
+
readWebhookDelivery: false,
|
|
313
|
+
readWebhookEndpoint: false,
|
|
314
|
+
rebuildJourney: true,
|
|
315
|
+
recordCollection: true,
|
|
316
|
+
redeliverEndpointDelivery: true,
|
|
317
|
+
redeliverWebhookDelivery: true,
|
|
318
|
+
refreshAgencyAdminTokens: false,
|
|
319
|
+
refreshManagerTokens: false,
|
|
320
|
+
registerWebhookEndpoint: true,
|
|
321
|
+
reissueConsoleUserInvite: true,
|
|
322
|
+
reissuePlatformAdminInvite: false,
|
|
323
|
+
reissuePlatformPartnerConsoleUserInvite: false,
|
|
324
|
+
removeFromManifest: true,
|
|
325
|
+
renamePlatformPartner: false,
|
|
326
|
+
reopenPickupStop: true,
|
|
327
|
+
reorderItineraryItem: true,
|
|
328
|
+
reorderPickupStops: true,
|
|
329
|
+
replayWebhookEndpoint: true,
|
|
330
|
+
requestFileUpload: true,
|
|
331
|
+
resetPlatformPartnerConsoleUser: false,
|
|
332
|
+
returnFloat: true,
|
|
333
|
+
revokeApiKey: true,
|
|
334
|
+
revokePlatformPartnerApiKey: false,
|
|
335
|
+
revokeShareToken: false,
|
|
336
|
+
rotateApiKey: true,
|
|
337
|
+
rotateWebhookEndpointSecret: true,
|
|
338
|
+
runJourneyStep: true,
|
|
339
|
+
setPlatformPartnerStatus: false,
|
|
340
|
+
submitExpenseClaim: true,
|
|
341
|
+
toggleChecklistItem: true,
|
|
342
|
+
unassignManager: true,
|
|
343
|
+
unlinkSeatingManager: false,
|
|
344
|
+
upsertAgencyAdmin: true,
|
|
345
|
+
upsertManager: true,
|
|
346
|
+
upsertTravellerProfile: true,
|
|
347
|
+
upsertTrip: true,
|
|
348
|
+
voidCollection: false,
|
|
349
|
+
voidExpense: false,
|
|
350
|
+
withdrawExpenseClaim: false
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// src/generated/error-codes.ts
|
|
354
|
+
var KaafilErrorCode = {
|
|
355
|
+
BusinessRuleViolation: "BUSINESS_RULE_VIOLATION",
|
|
356
|
+
CannotPostpone: "CANNOT_POSTPONE",
|
|
357
|
+
CapabilityUnavailable: "CAPABILITY_UNAVAILABLE",
|
|
358
|
+
ConflictVersion: "CONFLICT_VERSION",
|
|
359
|
+
FileOrphaned: "FILE_ORPHANED",
|
|
360
|
+
FilePurged: "FILE_PURGED",
|
|
361
|
+
IdempotencyKeyReused: "IDEMPOTENCY_KEY_REUSED",
|
|
362
|
+
InternalError: "INTERNAL_ERROR",
|
|
363
|
+
Locked: "LOCKED",
|
|
364
|
+
NotATrek: "NOT_A_TREK",
|
|
365
|
+
NotImplemented: "NOT_IMPLEMENTED",
|
|
366
|
+
OutOfTripWindow: "OUT_OF_TRIP_WINDOW",
|
|
367
|
+
PlanFeatureDisabled: "PLAN_FEATURE_DISABLED",
|
|
368
|
+
RateLimited: "RATE_LIMITED",
|
|
369
|
+
ReadOnlyRole: "READ_ONLY_ROLE",
|
|
370
|
+
ResourceNotFound: "RESOURCE_NOT_FOUND",
|
|
371
|
+
ResponseClosed: "RESPONSE_CLOSED",
|
|
372
|
+
SeatingCapacityOrphan: "SEATING_CAPACITY_ORPHAN",
|
|
373
|
+
SecretNotReplayable: "SECRET_NOT_REPLAYABLE",
|
|
374
|
+
ShareTokenExpired: "SHARE_TOKEN_EXPIRED",
|
|
375
|
+
ShareTokenRevoked: "SHARE_TOKEN_REVOKED",
|
|
376
|
+
StayWindowHasAssignments: "STAY_WINDOW_HAS_ASSIGNMENTS",
|
|
377
|
+
StayWindowOverlap: "STAY_WINDOW_OVERLAP",
|
|
378
|
+
StopHasPending: "STOP_HAS_PENDING",
|
|
379
|
+
SubjectRequired: "SUBJECT_REQUIRED",
|
|
380
|
+
TenantScopeMissing: "TENANT_SCOPE_MISSING",
|
|
381
|
+
Unauthenticated: "UNAUTHENTICATED",
|
|
382
|
+
UploadMismatch: "UPLOAD_MISMATCH",
|
|
383
|
+
ValidationError: "VALIDATION_ERROR"
|
|
384
|
+
};
|
|
385
|
+
var Retryability = {
|
|
386
|
+
No: "no",
|
|
387
|
+
Yes: "yes",
|
|
388
|
+
AfterRefresh: "after-refresh",
|
|
389
|
+
HonourRetryAfter: "honour-retry-after"
|
|
390
|
+
};
|
|
391
|
+
var OutboxClass = {
|
|
392
|
+
Transient: "TRANSIENT",
|
|
393
|
+
Conflict: "CONFLICT",
|
|
394
|
+
Fatal: "FATAL"
|
|
395
|
+
};
|
|
396
|
+
var ERROR_CODE_TABLE = {
|
|
397
|
+
BUSINESS_RULE_VIOLATION: { status: 422, retryability: "no", outboxClass: "FATAL" },
|
|
398
|
+
CANNOT_POSTPONE: { status: 422, retryability: "no", outboxClass: "FATAL" },
|
|
399
|
+
CAPABILITY_UNAVAILABLE: { status: 422, retryability: "no", outboxClass: "FATAL" },
|
|
400
|
+
CONFLICT_VERSION: { status: 409, retryability: "no", outboxClass: "CONFLICT" },
|
|
401
|
+
FILE_ORPHANED: { status: 409, retryability: "no", outboxClass: "FATAL" },
|
|
402
|
+
FILE_PURGED: { status: 410, retryability: "no", outboxClass: "FATAL" },
|
|
403
|
+
IDEMPOTENCY_KEY_REUSED: { status: 422, retryability: "no", outboxClass: "FATAL" },
|
|
404
|
+
INTERNAL_ERROR: { status: 500, retryability: "yes", outboxClass: "TRANSIENT" },
|
|
405
|
+
LOCKED: { status: 423, retryability: "no", outboxClass: "FATAL" },
|
|
406
|
+
NOT_A_TREK: { status: 422, retryability: "no", outboxClass: "FATAL" },
|
|
407
|
+
NOT_IMPLEMENTED: { status: 501, retryability: "no", outboxClass: "FATAL" },
|
|
408
|
+
OUT_OF_TRIP_WINDOW: { status: 422, retryability: "no", outboxClass: "FATAL" },
|
|
409
|
+
PLAN_FEATURE_DISABLED: { status: 402, retryability: "no", outboxClass: "FATAL" },
|
|
410
|
+
RATE_LIMITED: { status: 429, retryability: "honour-retry-after", outboxClass: "TRANSIENT" },
|
|
411
|
+
READ_ONLY_ROLE: { status: 422, retryability: "no", outboxClass: "FATAL" },
|
|
412
|
+
RESOURCE_NOT_FOUND: { status: 404, retryability: "no", outboxClass: "FATAL" },
|
|
413
|
+
RESPONSE_CLOSED: { status: 409, retryability: "no", outboxClass: "FATAL" },
|
|
414
|
+
SEATING_CAPACITY_ORPHAN: { status: 422, retryability: "no", outboxClass: "FATAL" },
|
|
415
|
+
SECRET_NOT_REPLAYABLE: { status: 409, retryability: "no", outboxClass: "CONFLICT" },
|
|
416
|
+
SHARE_TOKEN_EXPIRED: { status: 401, retryability: "no", outboxClass: "FATAL" },
|
|
417
|
+
SHARE_TOKEN_REVOKED: { status: 401, retryability: "no", outboxClass: "FATAL" },
|
|
418
|
+
STAY_WINDOW_HAS_ASSIGNMENTS: { status: 422, retryability: "no", outboxClass: "FATAL" },
|
|
419
|
+
STAY_WINDOW_OVERLAP: { status: 422, retryability: "no", outboxClass: "FATAL" },
|
|
420
|
+
STOP_HAS_PENDING: { status: 422, retryability: "no", outboxClass: "FATAL" },
|
|
421
|
+
SUBJECT_REQUIRED: { status: 422, retryability: "no", outboxClass: "FATAL" },
|
|
422
|
+
TENANT_SCOPE_MISSING: { status: 500, retryability: "yes", outboxClass: "TRANSIENT" },
|
|
423
|
+
UNAUTHENTICATED: { status: 401, retryability: "after-refresh", outboxClass: "FATAL" },
|
|
424
|
+
UPLOAD_MISMATCH: { status: 422, retryability: "no", outboxClass: "FATAL" },
|
|
425
|
+
VALIDATION_ERROR: { status: 422, retryability: "no", outboxClass: "FATAL" }
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
// src/http/errors.ts
|
|
429
|
+
var KaafilError = class extends Error {
|
|
430
|
+
code;
|
|
431
|
+
status;
|
|
432
|
+
details;
|
|
433
|
+
requestId;
|
|
434
|
+
meta;
|
|
435
|
+
constructor(message, init = {}) {
|
|
436
|
+
super(message, init.cause !== void 0 ? { cause: init.cause } : void 0);
|
|
437
|
+
this.name = "KaafilError";
|
|
438
|
+
this.code = init.code;
|
|
439
|
+
this.status = init.status;
|
|
440
|
+
this.details = init.details;
|
|
441
|
+
this.requestId = init.requestId;
|
|
442
|
+
this.meta = init.meta;
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
var KaafilApiError = class _KaafilApiError extends KaafilError {
|
|
446
|
+
kind = "api";
|
|
447
|
+
code;
|
|
448
|
+
constructor(code, message, init = {}) {
|
|
449
|
+
super(message, { ...init, code });
|
|
450
|
+
this.name = "KaafilApiError";
|
|
451
|
+
this.code = code;
|
|
452
|
+
Object.setPrototypeOf(this, _KaafilApiError.prototype);
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
var KaafilNotFoundError = class _KaafilNotFoundError extends KaafilApiError {
|
|
456
|
+
code;
|
|
457
|
+
constructor(message, init = {}) {
|
|
458
|
+
super(KaafilErrorCode.ResourceNotFound, message, init);
|
|
459
|
+
this.name = "KaafilNotFoundError";
|
|
460
|
+
this.code = KaafilErrorCode.ResourceNotFound;
|
|
461
|
+
Object.setPrototypeOf(this, _KaafilNotFoundError.prototype);
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
var KaafilEntitlementError = class _KaafilEntitlementError extends KaafilApiError {
|
|
465
|
+
code;
|
|
466
|
+
constructor(message, init = {}) {
|
|
467
|
+
super(KaafilErrorCode.PlanFeatureDisabled, message, init);
|
|
468
|
+
this.name = "KaafilEntitlementError";
|
|
469
|
+
this.code = KaafilErrorCode.PlanFeatureDisabled;
|
|
470
|
+
Object.setPrototypeOf(this, _KaafilEntitlementError.prototype);
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* `details.reason` — which of three different people can fix this. Read
|
|
474
|
+
* defensively, like `.fields`/`.currentVersion` below: `details` is
|
|
475
|
+
* untyped at the transport boundary, so a value this SDK does not
|
|
476
|
+
* recognise (an engine that ships a fourth reason before this SDK knows
|
|
477
|
+
* about it) surfaces as `undefined` rather than a wrong branch.
|
|
478
|
+
*/
|
|
479
|
+
get reason() {
|
|
480
|
+
const value = this.details?.reason;
|
|
481
|
+
return value === "agencyFlag" || value === "partnerTier" || value === "tripQuota" ? value : void 0;
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
var KaafilCapabilityUnavailableError = class _KaafilCapabilityUnavailableError extends KaafilApiError {
|
|
485
|
+
code;
|
|
486
|
+
constructor(message, init = {}) {
|
|
487
|
+
super(KaafilErrorCode.CapabilityUnavailable, message, init);
|
|
488
|
+
this.name = "KaafilCapabilityUnavailableError";
|
|
489
|
+
this.code = KaafilErrorCode.CapabilityUnavailable;
|
|
490
|
+
Object.setPrototypeOf(this, _KaafilCapabilityUnavailableError.prototype);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
var KaafilReadOnlyRoleError = class _KaafilReadOnlyRoleError extends KaafilApiError {
|
|
494
|
+
code;
|
|
495
|
+
constructor(message, init = {}) {
|
|
496
|
+
super(KaafilErrorCode.ReadOnlyRole, message, init);
|
|
497
|
+
this.name = "KaafilReadOnlyRoleError";
|
|
498
|
+
this.code = KaafilErrorCode.ReadOnlyRole;
|
|
499
|
+
Object.setPrototypeOf(this, _KaafilReadOnlyRoleError.prototype);
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
var KaafilValidationError = class _KaafilValidationError extends KaafilApiError {
|
|
503
|
+
code;
|
|
504
|
+
constructor(message, init = {}) {
|
|
505
|
+
super(KaafilErrorCode.ValidationError, message, init);
|
|
506
|
+
this.name = "KaafilValidationError";
|
|
507
|
+
this.code = KaafilErrorCode.ValidationError;
|
|
508
|
+
Object.setPrototypeOf(this, _KaafilValidationError.prototype);
|
|
509
|
+
}
|
|
510
|
+
get fields() {
|
|
511
|
+
const value = this.details?.fields;
|
|
512
|
+
return typeof value === "object" && value !== null ? value : void 0;
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
var KaafilVersionConflictError = class _KaafilVersionConflictError extends KaafilApiError {
|
|
516
|
+
code;
|
|
517
|
+
constructor(message, init = {}) {
|
|
518
|
+
super(KaafilErrorCode.ConflictVersion, message, init);
|
|
519
|
+
this.name = "KaafilVersionConflictError";
|
|
520
|
+
this.code = KaafilErrorCode.ConflictVersion;
|
|
521
|
+
Object.setPrototypeOf(this, _KaafilVersionConflictError.prototype);
|
|
522
|
+
}
|
|
523
|
+
get currentVersion() {
|
|
524
|
+
const value = this.details?.currentVersion;
|
|
525
|
+
return typeof value === "number" ? value : void 0;
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
var KaafilLockedError = class _KaafilLockedError extends KaafilApiError {
|
|
529
|
+
code;
|
|
530
|
+
constructor(message, init = {}) {
|
|
531
|
+
super(KaafilErrorCode.Locked, message, init);
|
|
532
|
+
this.name = "KaafilLockedError";
|
|
533
|
+
this.code = KaafilErrorCode.Locked;
|
|
534
|
+
Object.setPrototypeOf(this, _KaafilLockedError.prototype);
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
var KaafilRateLimitedError = class _KaafilRateLimitedError extends KaafilApiError {
|
|
538
|
+
code;
|
|
539
|
+
retryAfterSeconds;
|
|
540
|
+
constructor(message, init = {}) {
|
|
541
|
+
const { retryAfterSeconds, ...rest } = init;
|
|
542
|
+
super(KaafilErrorCode.RateLimited, message, rest);
|
|
543
|
+
this.name = "KaafilRateLimitedError";
|
|
544
|
+
this.code = KaafilErrorCode.RateLimited;
|
|
545
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
546
|
+
Object.setPrototypeOf(this, _KaafilRateLimitedError.prototype);
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
var KaafilUnauthenticatedError = class _KaafilUnauthenticatedError extends KaafilApiError {
|
|
550
|
+
code;
|
|
551
|
+
constructor(message, init = {}) {
|
|
552
|
+
super(KaafilErrorCode.Unauthenticated, message, init);
|
|
553
|
+
this.name = "KaafilUnauthenticatedError";
|
|
554
|
+
this.code = KaafilErrorCode.Unauthenticated;
|
|
555
|
+
Object.setPrototypeOf(this, _KaafilUnauthenticatedError.prototype);
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
var KaafilShareTokenExpiredError = class _KaafilShareTokenExpiredError extends KaafilApiError {
|
|
559
|
+
code;
|
|
560
|
+
constructor(message, init = {}) {
|
|
561
|
+
super(KaafilErrorCode.ShareTokenExpired, message, init);
|
|
562
|
+
this.name = "KaafilShareTokenExpiredError";
|
|
563
|
+
this.code = KaafilErrorCode.ShareTokenExpired;
|
|
564
|
+
Object.setPrototypeOf(this, _KaafilShareTokenExpiredError.prototype);
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
var KaafilShareTokenRevokedError = class _KaafilShareTokenRevokedError extends KaafilApiError {
|
|
568
|
+
code;
|
|
569
|
+
constructor(message, init = {}) {
|
|
570
|
+
super(KaafilErrorCode.ShareTokenRevoked, message, init);
|
|
571
|
+
this.name = "KaafilShareTokenRevokedError";
|
|
572
|
+
this.code = KaafilErrorCode.ShareTokenRevoked;
|
|
573
|
+
Object.setPrototypeOf(this, _KaafilShareTokenRevokedError.prototype);
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
var KaafilNotImplementedError = class _KaafilNotImplementedError extends KaafilApiError {
|
|
577
|
+
code;
|
|
578
|
+
constructor(message, init = {}) {
|
|
579
|
+
super(KaafilErrorCode.NotImplemented, message, init);
|
|
580
|
+
this.name = "KaafilNotImplementedError";
|
|
581
|
+
this.code = KaafilErrorCode.NotImplemented;
|
|
582
|
+
Object.setPrototypeOf(this, _KaafilNotImplementedError.prototype);
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
var KaafilTransportError = class extends KaafilError {
|
|
586
|
+
kind = "transport";
|
|
587
|
+
code;
|
|
588
|
+
constructor(message, init = {}) {
|
|
589
|
+
super(message, init);
|
|
590
|
+
this.code = void 0;
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
var KaafilTimeoutError = class _KaafilTimeoutError extends KaafilTransportError {
|
|
594
|
+
constructor(message = "Request timed out", init = {}) {
|
|
595
|
+
super(message, init);
|
|
596
|
+
this.name = "KaafilTimeoutError";
|
|
597
|
+
Object.setPrototypeOf(this, _KaafilTimeoutError.prototype);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
var KaafilAbortError = class _KaafilAbortError extends KaafilTransportError {
|
|
601
|
+
constructor(message = "Request aborted", init = {}) {
|
|
602
|
+
super(message, init);
|
|
603
|
+
this.name = "KaafilAbortError";
|
|
604
|
+
Object.setPrototypeOf(this, _KaafilAbortError.prototype);
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
var KaafilNetworkError = class _KaafilNetworkError extends KaafilTransportError {
|
|
608
|
+
constructor(message = "Network request failed", init = {}) {
|
|
609
|
+
super(message, init);
|
|
610
|
+
this.name = "KaafilNetworkError";
|
|
611
|
+
Object.setPrototypeOf(this, _KaafilNetworkError.prototype);
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
var KaafilInvalidRequestError = class _KaafilInvalidRequestError extends KaafilTransportError {
|
|
615
|
+
constructor(message, init = {}) {
|
|
616
|
+
super(message, init);
|
|
617
|
+
this.name = "KaafilInvalidRequestError";
|
|
618
|
+
Object.setPrototypeOf(this, _KaafilInvalidRequestError.prototype);
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
function isKaafilError(error) {
|
|
622
|
+
if (error instanceof KaafilError) {
|
|
623
|
+
return true;
|
|
624
|
+
}
|
|
625
|
+
if (typeof error !== "object" || error === null) {
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
const candidate = error;
|
|
629
|
+
return (candidate.kind === "api" || candidate.kind === "transport") && typeof candidate.message === "string";
|
|
630
|
+
}
|
|
631
|
+
var RETRYABLE_CODES = new Set(
|
|
632
|
+
Object.keys(ERROR_CODE_TABLE).filter(
|
|
633
|
+
(code) => ERROR_CODE_TABLE[code].retryability !== Retryability.No
|
|
634
|
+
)
|
|
635
|
+
);
|
|
636
|
+
function isRetryable(error) {
|
|
637
|
+
if (!isKaafilError(error)) {
|
|
638
|
+
return false;
|
|
639
|
+
}
|
|
640
|
+
if (error.kind === "transport") {
|
|
641
|
+
return !(error instanceof KaafilAbortError) && !(error instanceof KaafilInvalidRequestError);
|
|
642
|
+
}
|
|
643
|
+
return error.code !== void 0 && RETRYABLE_CODES.has(error.code);
|
|
644
|
+
}
|
|
645
|
+
var KAAFIL_ERROR_CODE_VALUES = new Set(Object.values(KaafilErrorCode));
|
|
646
|
+
function isKaafilErrorCode(value) {
|
|
647
|
+
return KAAFIL_ERROR_CODE_VALUES.has(value);
|
|
648
|
+
}
|
|
649
|
+
function parseErrorEnvelope(body) {
|
|
650
|
+
if (typeof body !== "object" || body === null) {
|
|
651
|
+
return void 0;
|
|
652
|
+
}
|
|
653
|
+
const errorField = body.error;
|
|
654
|
+
if (typeof errorField !== "object" || errorField === null) {
|
|
655
|
+
return void 0;
|
|
656
|
+
}
|
|
657
|
+
const errorRecord = errorField;
|
|
658
|
+
const code = errorRecord.code;
|
|
659
|
+
const message = errorRecord.message;
|
|
660
|
+
if (typeof code !== "string" || !isKaafilErrorCode(code) || typeof message !== "string") {
|
|
661
|
+
return void 0;
|
|
662
|
+
}
|
|
663
|
+
const details = errorRecord.details;
|
|
664
|
+
return {
|
|
665
|
+
code,
|
|
666
|
+
message,
|
|
667
|
+
details: typeof details === "object" && details !== null ? details : void 0
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
function buildApiErrorInit(init, details) {
|
|
671
|
+
return {
|
|
672
|
+
status: init.status,
|
|
673
|
+
...details !== void 0 ? { details } : {},
|
|
674
|
+
...init.requestId !== void 0 ? { requestId: init.requestId } : {},
|
|
675
|
+
...init.meta !== void 0 ? { meta: init.meta } : {},
|
|
676
|
+
...init.cause !== void 0 ? { cause: init.cause } : {}
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
function fromEnvelope(body, init) {
|
|
680
|
+
const parsed = parseErrorEnvelope(body);
|
|
681
|
+
if (parsed === void 0) {
|
|
682
|
+
return new KaafilNetworkError(
|
|
683
|
+
`Received an unrecognizable error body for HTTP ${init.status}`,
|
|
684
|
+
buildApiErrorInit(init, void 0)
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
const commonInit = buildApiErrorInit(init, parsed.details);
|
|
688
|
+
switch (parsed.code) {
|
|
689
|
+
case KaafilErrorCode.ResourceNotFound:
|
|
690
|
+
return new KaafilNotFoundError(parsed.message, commonInit);
|
|
691
|
+
case KaafilErrorCode.PlanFeatureDisabled:
|
|
692
|
+
return new KaafilEntitlementError(parsed.message, commonInit);
|
|
693
|
+
case KaafilErrorCode.CapabilityUnavailable:
|
|
694
|
+
return new KaafilCapabilityUnavailableError(parsed.message, commonInit);
|
|
695
|
+
case KaafilErrorCode.ReadOnlyRole:
|
|
696
|
+
return new KaafilReadOnlyRoleError(parsed.message, commonInit);
|
|
697
|
+
case KaafilErrorCode.ValidationError:
|
|
698
|
+
return new KaafilValidationError(parsed.message, commonInit);
|
|
699
|
+
case KaafilErrorCode.ConflictVersion:
|
|
700
|
+
return new KaafilVersionConflictError(parsed.message, commonInit);
|
|
701
|
+
case KaafilErrorCode.Locked:
|
|
702
|
+
return new KaafilLockedError(parsed.message, commonInit);
|
|
703
|
+
case KaafilErrorCode.RateLimited:
|
|
704
|
+
return new KaafilRateLimitedError(parsed.message, {
|
|
705
|
+
...commonInit,
|
|
706
|
+
...init.retryAfterSeconds !== void 0 ? { retryAfterSeconds: init.retryAfterSeconds } : {}
|
|
707
|
+
});
|
|
708
|
+
case KaafilErrorCode.Unauthenticated:
|
|
709
|
+
return new KaafilUnauthenticatedError(parsed.message, commonInit);
|
|
710
|
+
case KaafilErrorCode.ShareTokenExpired:
|
|
711
|
+
return new KaafilShareTokenExpiredError(parsed.message, commonInit);
|
|
712
|
+
case KaafilErrorCode.ShareTokenRevoked:
|
|
713
|
+
return new KaafilShareTokenRevokedError(parsed.message, commonInit);
|
|
714
|
+
case KaafilErrorCode.NotImplemented:
|
|
715
|
+
return new KaafilNotImplementedError(parsed.message, commonInit);
|
|
716
|
+
default:
|
|
717
|
+
return new KaafilApiError(parsed.code, parsed.message, commonInit);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
// src/auth/credentials.ts
|
|
722
|
+
async function resolveValue(value) {
|
|
723
|
+
return typeof value === "function" ? await value() : value;
|
|
724
|
+
}
|
|
725
|
+
var CredentialKind = {
|
|
726
|
+
AgencyAdmin: "agencyAdmin",
|
|
727
|
+
ApiKey: "apiKey",
|
|
728
|
+
ManagerSession: "managerSession",
|
|
729
|
+
ShareToken: "shareToken"
|
|
730
|
+
};
|
|
731
|
+
var ROTATING_ACCESS_TOKEN_REFRESH_SKEW_MS = 3e4;
|
|
732
|
+
function isRotatingCredentialKind(kind) {
|
|
733
|
+
return kind === CredentialKind.AgencyAdmin || kind === CredentialKind.ManagerSession;
|
|
734
|
+
}
|
|
735
|
+
function isRotatingConfig(config) {
|
|
736
|
+
return isRotatingCredentialKind(config.kind);
|
|
737
|
+
}
|
|
738
|
+
var CREDENTIAL_KIND_SCHEME = {
|
|
739
|
+
agencyAdmin: SecuritySchemeId.AgencyAdminAuth,
|
|
740
|
+
apiKey: SecuritySchemeId.ApiKeyAuth,
|
|
741
|
+
managerSession: SecuritySchemeId.ManagerAuth,
|
|
742
|
+
shareToken: SecuritySchemeId.ShareAuth
|
|
743
|
+
};
|
|
744
|
+
var UnsatisfiableSchemeError = class _UnsatisfiableSchemeError extends KaafilInvalidRequestError {
|
|
745
|
+
operationId;
|
|
746
|
+
acceptedSchemes;
|
|
747
|
+
credentialKind;
|
|
748
|
+
constructor(operationId, acceptedSchemes, credentialKind) {
|
|
749
|
+
const schemeList = acceptedSchemes.length > 0 ? acceptedSchemes.join(", ") : "(no scheme declared)";
|
|
750
|
+
super(
|
|
751
|
+
`"${operationId}" accepts [${schemeList}], but the configured "${credentialKind}" credential cannot satisfy any of them.`
|
|
752
|
+
);
|
|
753
|
+
this.name = "UnsatisfiableSchemeError";
|
|
754
|
+
Object.setPrototypeOf(this, _UnsatisfiableSchemeError.prototype);
|
|
755
|
+
this.operationId = operationId;
|
|
756
|
+
this.acceptedSchemes = acceptedSchemes;
|
|
757
|
+
this.credentialKind = credentialKind;
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
function headersForCarrier(schemeId, value) {
|
|
761
|
+
const carrier = SECURITY_SCHEME_CARRIERS[schemeId];
|
|
762
|
+
switch (carrier.kind) {
|
|
763
|
+
case "header":
|
|
764
|
+
return { [carrier.headerName]: value };
|
|
765
|
+
case "bearer":
|
|
766
|
+
return { Authorization: `Bearer ${value}` };
|
|
767
|
+
case "cookie":
|
|
768
|
+
throw new Error(`Scheme "${schemeId}" is cookie-borne and has no SDK-side credential kind.`);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
function createInitialState(config) {
|
|
772
|
+
return {
|
|
773
|
+
rotating: isRotatingCredentialKind(config.kind) ? { current: null, refreshPromise: null } : null
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
function isExpiringSoon(expiresAt, nowMs) {
|
|
777
|
+
if (expiresAt === void 0) {
|
|
778
|
+
return false;
|
|
779
|
+
}
|
|
780
|
+
const expiryMs = Date.parse(expiresAt);
|
|
781
|
+
if (Number.isNaN(expiryMs)) {
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
return expiryMs - nowMs <= ROTATING_ACCESS_TOKEN_REFRESH_SKEW_MS;
|
|
785
|
+
}
|
|
786
|
+
var CredentialResolver = class {
|
|
787
|
+
config;
|
|
788
|
+
state;
|
|
789
|
+
/**
|
|
790
|
+
* The default exchange for a rotating (`managerSession`/`agencyAdmin`)
|
|
791
|
+
* credential — `undefined` for the two non-rotating kinds, and for a
|
|
792
|
+
* rotating config that always uses its own `refresh` override instead.
|
|
793
|
+
* See `RotatingSessionExchange`'s doc comment for why this arrives as a
|
|
794
|
+
* constructor argument rather than an import.
|
|
795
|
+
*/
|
|
796
|
+
rotatingSessionExchange;
|
|
797
|
+
constructor(config, rotatingSessionExchange) {
|
|
798
|
+
this.config = config;
|
|
799
|
+
this.state = createInitialState(config);
|
|
800
|
+
this.rotatingSessionExchange = rotatingSessionExchange;
|
|
801
|
+
}
|
|
802
|
+
get kind() {
|
|
803
|
+
return this.config.kind;
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Picks the first scheme in `acceptedSchemes` (spec declaration order)
|
|
807
|
+
* the configured credential can satisfy and returns its headers. Throws
|
|
808
|
+
* `UnsatisfiableSchemeError` — never makes the doomed round trip — if
|
|
809
|
+
* none match. An empty `acceptedSchemes` (a public operation) needs no
|
|
810
|
+
* credential and returns no headers.
|
|
811
|
+
*/
|
|
812
|
+
async resolveHeaders(operationId, acceptedSchemes) {
|
|
813
|
+
if (acceptedSchemes.length === 0) {
|
|
814
|
+
return { schemeId: null, headers: {} };
|
|
815
|
+
}
|
|
816
|
+
const config = this.config;
|
|
817
|
+
const mySchemeId = CREDENTIAL_KIND_SCHEME[config.kind];
|
|
818
|
+
if (!acceptedSchemes.includes(mySchemeId)) {
|
|
819
|
+
throw new UnsatisfiableSchemeError(operationId, acceptedSchemes, config.kind);
|
|
820
|
+
}
|
|
821
|
+
const value = await this.currentValue(config);
|
|
822
|
+
return { schemeId: mySchemeId, headers: headersForCarrier(mySchemeId, value) };
|
|
823
|
+
}
|
|
824
|
+
async currentValue(config) {
|
|
825
|
+
switch (config.kind) {
|
|
826
|
+
case CredentialKind.ApiKey:
|
|
827
|
+
return resolveValue(config.apiKey);
|
|
828
|
+
case CredentialKind.ShareToken:
|
|
829
|
+
return resolveValue(config.token);
|
|
830
|
+
case CredentialKind.ManagerSession:
|
|
831
|
+
case CredentialKind.AgencyAdmin:
|
|
832
|
+
return this.currentRotatingAccessToken(config);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
async currentRotatingAccessToken(config) {
|
|
836
|
+
const state = this.rotatingSessionState();
|
|
837
|
+
if (!state.current) {
|
|
838
|
+
const [accessToken, refreshToken, expiresAt] = await Promise.all([
|
|
839
|
+
resolveValue(config.accessToken),
|
|
840
|
+
resolveValue(config.refreshToken),
|
|
841
|
+
config.expiresAt !== void 0 ? resolveValue(config.expiresAt) : Promise.resolve(void 0)
|
|
842
|
+
]);
|
|
843
|
+
state.current = { accessToken, refreshToken, expiresAt };
|
|
844
|
+
}
|
|
845
|
+
if (isExpiringSoon(state.current.expiresAt, Date.now())) {
|
|
846
|
+
const result = await this.refreshRotatingSession();
|
|
847
|
+
return result.accessToken;
|
|
848
|
+
}
|
|
849
|
+
return state.current.accessToken;
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Single-flight refresh: concurrent triggers (N simultaneous `401`s, or a
|
|
853
|
+
* pre-emptive check racing a `401`) share one in-flight promise, so the
|
|
854
|
+
* rotating refresh token is presented exactly once. The promise is
|
|
855
|
+
* cleared on both success and failure — a rejected refresh never stays
|
|
856
|
+
* sticky, and the next trigger always starts a fresh exchange
|
|
857
|
+
* (`architecture/03-auth-and-tokens.md §2`). Callers make one attempt per
|
|
858
|
+
* request and surface the failure; this method does not loop. Shared by
|
|
859
|
+
* both rotating kinds — see the module header's argument for why this is
|
|
860
|
+
* one implementation, not one per kind.
|
|
861
|
+
*/
|
|
862
|
+
async refreshRotatingSession() {
|
|
863
|
+
const config = this.config;
|
|
864
|
+
if (!isRotatingConfig(config)) {
|
|
865
|
+
throw new Error(
|
|
866
|
+
'refreshRotatingSession() is only valid for a rotating ("managerSession" or "agencyAdmin") credential.'
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
const state = this.rotatingSessionState();
|
|
870
|
+
if (state.refreshPromise) {
|
|
871
|
+
return state.refreshPromise;
|
|
872
|
+
}
|
|
873
|
+
const promise = this.performRotatingRefresh(config, state);
|
|
874
|
+
state.refreshPromise = promise;
|
|
875
|
+
try {
|
|
876
|
+
return await promise;
|
|
877
|
+
} finally {
|
|
878
|
+
state.refreshPromise = null;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
async performRotatingRefresh(config, state) {
|
|
882
|
+
const refreshToken = state.current?.refreshToken ?? await resolveValue(config.refreshToken);
|
|
883
|
+
const result = config.refresh !== void 0 ? await config.refresh(refreshToken) : await this.defaultRotatingRefresh(config, state, refreshToken);
|
|
884
|
+
state.current = {
|
|
885
|
+
accessToken: result.accessToken,
|
|
886
|
+
refreshToken: result.refreshToken,
|
|
887
|
+
expiresAt: result.expiresAt
|
|
888
|
+
};
|
|
889
|
+
await config.onRefresh?.(result);
|
|
890
|
+
return result;
|
|
891
|
+
}
|
|
892
|
+
async defaultRotatingRefresh(config, state, refreshToken) {
|
|
893
|
+
if (this.rotatingSessionExchange === void 0) {
|
|
894
|
+
throw new Error(
|
|
895
|
+
'invariant: a rotating credential without a "refresh" override needs the exchange function the entry point constructs it with \u2014 see "./client-entry.ts".'
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
const accessToken = state.current?.accessToken ?? await resolveValue(config.accessToken);
|
|
899
|
+
return this.rotatingSessionExchange(accessToken, refreshToken);
|
|
900
|
+
}
|
|
901
|
+
rotatingSessionState() {
|
|
902
|
+
const state = this.state.rotating;
|
|
903
|
+
if (!state) {
|
|
904
|
+
throw new Error("invariant: rotating-session state missing for a rotating credential.");
|
|
905
|
+
}
|
|
906
|
+
return state;
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* Resets every piece of per-session state in one assignment — teardown
|
|
910
|
+
* that cannot forget a field because the state is rebuilt from scratch,
|
|
911
|
+
* not cleared field by field.
|
|
912
|
+
*/
|
|
913
|
+
reset() {
|
|
914
|
+
this.state = createInitialState(this.config);
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
// src/config.ts
|
|
919
|
+
var ENVIRONMENT_BASE_URLS = {
|
|
920
|
+
live: "https://api.kaafil.com",
|
|
921
|
+
test: "https://api.test.kaafil.com"
|
|
922
|
+
};
|
|
923
|
+
var KaafilConfigError = class extends Error {
|
|
924
|
+
constructor(message) {
|
|
925
|
+
super(message);
|
|
926
|
+
this.name = "KaafilConfigError";
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
function isValidAbsoluteUrl(value) {
|
|
930
|
+
try {
|
|
931
|
+
const url = new URL(value);
|
|
932
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
933
|
+
} catch {
|
|
934
|
+
return false;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
function resolveBaseUrl(environment, baseUrl) {
|
|
938
|
+
if (baseUrl === void 0) {
|
|
939
|
+
return ENVIRONMENT_BASE_URLS[environment];
|
|
940
|
+
}
|
|
941
|
+
if (!isValidAbsoluteUrl(baseUrl)) {
|
|
942
|
+
throw new KaafilConfigError(
|
|
943
|
+
`"baseUrl" must be an absolute http(s) URL; received "${baseUrl}".`
|
|
944
|
+
);
|
|
945
|
+
}
|
|
946
|
+
return baseUrl;
|
|
947
|
+
}
|
|
948
|
+
function assertValidTimeout(timeoutMs) {
|
|
949
|
+
if (timeoutMs === void 0) {
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
953
|
+
throw new KaafilConfigError(`"timeoutMs" must be a positive number; received ${timeoutMs}.`);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
function assertValidMaxAttempts(maxAttempts) {
|
|
957
|
+
if (maxAttempts === void 0) {
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
if (!Number.isInteger(maxAttempts) || maxAttempts <= 0) {
|
|
961
|
+
throw new KaafilConfigError(
|
|
962
|
+
`"maxAttempts" must be a positive integer; received ${maxAttempts}.`
|
|
963
|
+
);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// src/http/retry.ts
|
|
968
|
+
var RETRY_LADDER_MS = [1e3, 5e3, 15e3, 6e4, 3e5, 9e5, 36e5];
|
|
969
|
+
var DEFAULT_MAX_ATTEMPTS = 24;
|
|
970
|
+
function isRetryableFailure(input) {
|
|
971
|
+
if (input.status === null) {
|
|
972
|
+
return true;
|
|
973
|
+
}
|
|
974
|
+
const entry = input.code !== void 0 ? ERROR_CODE_TABLE[input.code] : void 0;
|
|
975
|
+
if (entry !== void 0) {
|
|
976
|
+
return entry.retryability === Retryability.Yes || entry.retryability === Retryability.HonourRetryAfter;
|
|
977
|
+
}
|
|
978
|
+
return input.status === 429 || input.status >= 500 && input.status <= 599;
|
|
979
|
+
}
|
|
980
|
+
function computeRetryDelayMs(attempt, options = {}) {
|
|
981
|
+
if (options.retryAfterSeconds !== void 0) {
|
|
982
|
+
return Math.max(1, Math.floor(options.retryAfterSeconds)) * 1e3;
|
|
983
|
+
}
|
|
984
|
+
const index = Math.min(Math.max(attempt - 1, 0), RETRY_LADDER_MS.length - 1);
|
|
985
|
+
const base = RETRY_LADDER_MS[index];
|
|
986
|
+
if (base === void 0) {
|
|
987
|
+
throw new Error("unreachable: index is clamped to RETRY_LADDER_MS bounds");
|
|
988
|
+
}
|
|
989
|
+
const random = options.random ?? Math.random;
|
|
990
|
+
const half = base / 2;
|
|
991
|
+
return Math.floor(half + random() * half);
|
|
992
|
+
}
|
|
993
|
+
function delayWithAbort(ms, signal) {
|
|
994
|
+
if (signal?.aborted === true) {
|
|
995
|
+
return Promise.reject(signal.reason);
|
|
996
|
+
}
|
|
997
|
+
return new Promise((resolve, reject) => {
|
|
998
|
+
const onAbort = () => {
|
|
999
|
+
clearTimeout(timer);
|
|
1000
|
+
reject(signal?.reason);
|
|
1001
|
+
};
|
|
1002
|
+
const timer = setTimeout(() => {
|
|
1003
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1004
|
+
resolve();
|
|
1005
|
+
}, ms);
|
|
1006
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
var RetryExhaustedError = class extends Error {
|
|
1010
|
+
failure;
|
|
1011
|
+
attempts;
|
|
1012
|
+
constructor(failure, attempts) {
|
|
1013
|
+
super(`retry exhausted after ${attempts} attempt(s), last status ${String(failure.status)}`);
|
|
1014
|
+
this.name = "RetryExhaustedError";
|
|
1015
|
+
this.failure = failure;
|
|
1016
|
+
this.attempts = attempts;
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
async function executeWithRetry(attempt, options = {}) {
|
|
1020
|
+
const unsafeToReplay = options.hasBody === true && options.idempotencyKey === void 0;
|
|
1021
|
+
const maxAttempts = unsafeToReplay ? 1 : options.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
|
|
1022
|
+
const random = options.random ?? Math.random;
|
|
1023
|
+
for (let attemptNumber = 1; attemptNumber <= maxAttempts; attemptNumber += 1) {
|
|
1024
|
+
if (options.signal?.aborted === true) {
|
|
1025
|
+
throw options.signal.reason;
|
|
1026
|
+
}
|
|
1027
|
+
const outcome = await attempt(attemptNumber);
|
|
1028
|
+
if (outcome.ok) {
|
|
1029
|
+
return outcome.value;
|
|
1030
|
+
}
|
|
1031
|
+
const retryable = isRetryableFailure(outcome);
|
|
1032
|
+
if (!retryable || attemptNumber === maxAttempts) {
|
|
1033
|
+
throw new RetryExhaustedError(outcome, attemptNumber);
|
|
1034
|
+
}
|
|
1035
|
+
const delayMs = computeRetryDelayMs(attemptNumber, {
|
|
1036
|
+
...outcome.retryAfterSeconds !== void 0 ? { retryAfterSeconds: outcome.retryAfterSeconds } : {},
|
|
1037
|
+
random
|
|
1038
|
+
});
|
|
1039
|
+
await delayWithAbort(delayMs, options.signal);
|
|
1040
|
+
}
|
|
1041
|
+
throw new Error("unreachable: executeWithRetry loop exited without returning or throwing");
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// src/http/client.ts
|
|
1045
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
1046
|
+
function createHttpClient(config) {
|
|
1047
|
+
const ctx = {
|
|
1048
|
+
baseUrl: config.baseUrl,
|
|
1049
|
+
credentials: config.credentials,
|
|
1050
|
+
timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
1051
|
+
maxAttempts: config.maxAttempts,
|
|
1052
|
+
userAgent: config.userAgent,
|
|
1053
|
+
random: config.random
|
|
1054
|
+
};
|
|
1055
|
+
return {
|
|
1056
|
+
execute: (request) => execute(ctx, request)
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
function renderPath(template, params) {
|
|
1060
|
+
return template.replace(/\{([^}]+)\}/g, (_match, name) => {
|
|
1061
|
+
const raw = params?.[name];
|
|
1062
|
+
if (raw === void 0) {
|
|
1063
|
+
throw new KaafilInvalidRequestError(
|
|
1064
|
+
`Missing path parameter "${name}" for "${template}". Pass it in the call's options.`
|
|
1065
|
+
);
|
|
1066
|
+
}
|
|
1067
|
+
return encodeURIComponent(String(raw));
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
function buildUrl(baseUrl, renderedPath, query) {
|
|
1071
|
+
const normalizedBase = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
1072
|
+
const relativePath = renderedPath.startsWith("/") ? renderedPath.slice(1) : renderedPath;
|
|
1073
|
+
const url = new URL(relativePath, normalizedBase);
|
|
1074
|
+
if (query !== void 0) {
|
|
1075
|
+
for (const [key, value] of Object.entries(query)) {
|
|
1076
|
+
if (value === void 0) {
|
|
1077
|
+
continue;
|
|
1078
|
+
}
|
|
1079
|
+
url.searchParams.set(key, String(value));
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
return url;
|
|
1083
|
+
}
|
|
1084
|
+
var TIMEOUT_REASON = /* @__PURE__ */ Symbol("kaafil-timeout");
|
|
1085
|
+
function combineSignals(callerSignal, timeoutMs) {
|
|
1086
|
+
const controller = new AbortController();
|
|
1087
|
+
const cleanupFns = [];
|
|
1088
|
+
if (callerSignal !== void 0) {
|
|
1089
|
+
if (callerSignal.aborted) {
|
|
1090
|
+
controller.abort(callerSignal.reason);
|
|
1091
|
+
} else {
|
|
1092
|
+
const onAbort = () => controller.abort(callerSignal.reason);
|
|
1093
|
+
callerSignal.addEventListener("abort", onAbort, { once: true });
|
|
1094
|
+
cleanupFns.push(() => callerSignal.removeEventListener("abort", onAbort));
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
const timer = setTimeout(() => controller.abort(TIMEOUT_REASON), timeoutMs);
|
|
1098
|
+
cleanupFns.push(() => clearTimeout(timer));
|
|
1099
|
+
return {
|
|
1100
|
+
signal: controller.signal,
|
|
1101
|
+
isTimeout: () => controller.signal.reason === TIMEOUT_REASON,
|
|
1102
|
+
cleanup: () => {
|
|
1103
|
+
for (const fn of cleanupFns) {
|
|
1104
|
+
fn();
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
async function buildHeaders(ctx, request, idempotencyKey, hasBody) {
|
|
1110
|
+
const acceptedSchemes = OPERATION_SECURITY[request.operationId];
|
|
1111
|
+
const credential = await ctx.credentials.resolveHeaders(request.operationId, acceptedSchemes);
|
|
1112
|
+
const headers = new Headers();
|
|
1113
|
+
headers.set("Accept", "application/json");
|
|
1114
|
+
if (hasBody) {
|
|
1115
|
+
headers.set("Content-Type", "application/json");
|
|
1116
|
+
}
|
|
1117
|
+
for (const [key, value] of Object.entries(credential.headers)) {
|
|
1118
|
+
headers.set(key, value);
|
|
1119
|
+
}
|
|
1120
|
+
if (idempotencyKey !== void 0) {
|
|
1121
|
+
headers.set("Idempotency-Key", idempotencyKey);
|
|
1122
|
+
}
|
|
1123
|
+
if (ctx.userAgent !== void 0) {
|
|
1124
|
+
try {
|
|
1125
|
+
headers.set("User-Agent", ctx.userAgent);
|
|
1126
|
+
} catch {
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
if (request.headers !== void 0) {
|
|
1130
|
+
for (const [key, value] of Object.entries(request.headers)) {
|
|
1131
|
+
headers.set(key, value);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
return headers;
|
|
1135
|
+
}
|
|
1136
|
+
function tryParseJson(text) {
|
|
1137
|
+
try {
|
|
1138
|
+
return JSON.parse(text);
|
|
1139
|
+
} catch {
|
|
1140
|
+
return void 0;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
function isSuccessEnvelope(body) {
|
|
1144
|
+
if (typeof body !== "object" || body === null) {
|
|
1145
|
+
return false;
|
|
1146
|
+
}
|
|
1147
|
+
const record = body;
|
|
1148
|
+
if (record.ok !== true) {
|
|
1149
|
+
return false;
|
|
1150
|
+
}
|
|
1151
|
+
if (typeof record.data !== "object" || record.data === null) {
|
|
1152
|
+
return false;
|
|
1153
|
+
}
|
|
1154
|
+
const meta = record.meta;
|
|
1155
|
+
if (typeof meta !== "object" || meta === null) {
|
|
1156
|
+
return false;
|
|
1157
|
+
}
|
|
1158
|
+
return typeof meta.serverTime === "string";
|
|
1159
|
+
}
|
|
1160
|
+
function buildResponseMeta(status, requestId, meta) {
|
|
1161
|
+
return {
|
|
1162
|
+
status,
|
|
1163
|
+
serverTime: meta.serverTime,
|
|
1164
|
+
requestId,
|
|
1165
|
+
page: meta.page
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
function parseRetryAfterSeconds(headerValue) {
|
|
1169
|
+
if (headerValue === null) {
|
|
1170
|
+
return void 0;
|
|
1171
|
+
}
|
|
1172
|
+
const seconds = Number(headerValue);
|
|
1173
|
+
return Number.isFinite(seconds) && seconds >= 0 ? seconds : void 0;
|
|
1174
|
+
}
|
|
1175
|
+
function attachMeta(data, meta) {
|
|
1176
|
+
return Object.assign(data, { meta });
|
|
1177
|
+
}
|
|
1178
|
+
function describeCrossOriginSuspect(url) {
|
|
1179
|
+
const loc = globalThis.location;
|
|
1180
|
+
if (typeof loc !== "object" || loc === null) {
|
|
1181
|
+
return void 0;
|
|
1182
|
+
}
|
|
1183
|
+
const origin = loc.origin;
|
|
1184
|
+
if (typeof origin !== "string" || origin === url.origin) {
|
|
1185
|
+
return void 0;
|
|
1186
|
+
}
|
|
1187
|
+
return `Request failed while calling a different origin (${url.origin}) than the page's own origin (${origin}). The most likely cause is that the API has not allowlisted this origin for CORS \u2014 but the browser withholds the actual reason from JavaScript when it blocks a cross-origin response, so the SDK cannot confirm this; a genuine network outage produces the same rejection. If this is unexpected, the fix is server-side: add this origin to the API's CORS allowlist.`;
|
|
1188
|
+
}
|
|
1189
|
+
async function sendOnce(ctx, request, idempotencyKey) {
|
|
1190
|
+
const hasBody = request.body !== void 0;
|
|
1191
|
+
const renderedPath = renderPath(request.path, request.pathParams);
|
|
1192
|
+
const url = buildUrl(ctx.baseUrl, renderedPath, request.query);
|
|
1193
|
+
const headers = await buildHeaders(ctx, request, idempotencyKey, hasBody);
|
|
1194
|
+
const combined = combineSignals(request.signal, ctx.timeoutMs);
|
|
1195
|
+
try {
|
|
1196
|
+
const response = await fetch(url, {
|
|
1197
|
+
method: request.method,
|
|
1198
|
+
headers,
|
|
1199
|
+
signal: combined.signal,
|
|
1200
|
+
...hasBody ? { body: JSON.stringify(request.body) } : {}
|
|
1201
|
+
});
|
|
1202
|
+
const requestId = response.headers.get("x-request-id") ?? void 0;
|
|
1203
|
+
const status = response.status;
|
|
1204
|
+
const text = await response.text();
|
|
1205
|
+
const body = text.length > 0 ? tryParseJson(text) : void 0;
|
|
1206
|
+
if (response.ok) {
|
|
1207
|
+
if (!isSuccessEnvelope(body)) {
|
|
1208
|
+
throw new KaafilNetworkError(`Received an unrecognizable success body for HTTP ${status}`, {
|
|
1209
|
+
status,
|
|
1210
|
+
...requestId !== void 0 ? { requestId } : {}
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
return { data: body.data, meta: buildResponseMeta(status, requestId, body.meta) };
|
|
1214
|
+
}
|
|
1215
|
+
const retryAfterSeconds = parseRetryAfterSeconds(response.headers.get("retry-after"));
|
|
1216
|
+
throw fromEnvelope(body, {
|
|
1217
|
+
status,
|
|
1218
|
+
...requestId !== void 0 ? { requestId } : {},
|
|
1219
|
+
...retryAfterSeconds !== void 0 ? { retryAfterSeconds } : {}
|
|
1220
|
+
});
|
|
1221
|
+
} catch (error) {
|
|
1222
|
+
if (isKaafilError(error)) {
|
|
1223
|
+
throw error;
|
|
1224
|
+
}
|
|
1225
|
+
if (combined.signal.aborted) {
|
|
1226
|
+
if (combined.isTimeout()) {
|
|
1227
|
+
throw new KaafilTimeoutError("Request timed out", { cause: error });
|
|
1228
|
+
}
|
|
1229
|
+
throw new KaafilAbortError("Request aborted", { cause: error });
|
|
1230
|
+
}
|
|
1231
|
+
throw new KaafilNetworkError(describeCrossOriginSuspect(url) ?? "Request failed", {
|
|
1232
|
+
cause: error
|
|
1233
|
+
});
|
|
1234
|
+
} finally {
|
|
1235
|
+
combined.cleanup();
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
var MANAGER_TOKENS_REFRESH_PATH = "/api/v1/auth/manager-tokens/refresh";
|
|
1239
|
+
var AGENCY_ADMIN_TOKENS_REFRESH_PATH = "/api/v1/auth/agency-admin-tokens/refresh";
|
|
1240
|
+
function createRotatingSessionRefreshExchange(baseUrl, refreshPath, networkErrorMessage) {
|
|
1241
|
+
return async (accessToken, refreshToken) => {
|
|
1242
|
+
const url = buildUrl(baseUrl, refreshPath, void 0);
|
|
1243
|
+
const headers = new Headers({
|
|
1244
|
+
Accept: "application/json",
|
|
1245
|
+
"Content-Type": "application/json",
|
|
1246
|
+
Authorization: `Bearer ${accessToken}`
|
|
1247
|
+
});
|
|
1248
|
+
let response;
|
|
1249
|
+
try {
|
|
1250
|
+
response = await fetch(url, {
|
|
1251
|
+
method: "POST",
|
|
1252
|
+
headers,
|
|
1253
|
+
body: JSON.stringify({ refreshToken })
|
|
1254
|
+
});
|
|
1255
|
+
} catch (error) {
|
|
1256
|
+
throw new KaafilNetworkError(networkErrorMessage, { cause: error });
|
|
1257
|
+
}
|
|
1258
|
+
const requestId = response.headers.get("x-request-id") ?? void 0;
|
|
1259
|
+
const status = response.status;
|
|
1260
|
+
const text = await response.text();
|
|
1261
|
+
const body = text.length > 0 ? tryParseJson(text) : void 0;
|
|
1262
|
+
if (!response.ok) {
|
|
1263
|
+
throw fromEnvelope(body, {
|
|
1264
|
+
status,
|
|
1265
|
+
...requestId !== void 0 ? { requestId } : {}
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
if (!isSuccessEnvelope(body)) {
|
|
1269
|
+
throw new KaafilNetworkError(`Received an unrecognizable success body for HTTP ${status}`, {
|
|
1270
|
+
status,
|
|
1271
|
+
...requestId !== void 0 ? { requestId } : {}
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
return body.data;
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
function createManagerSessionRefreshExchange(baseUrl) {
|
|
1278
|
+
return createRotatingSessionRefreshExchange(
|
|
1279
|
+
baseUrl,
|
|
1280
|
+
MANAGER_TOKENS_REFRESH_PATH,
|
|
1281
|
+
"Manager-session refresh request failed"
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
function createAgencyAdminSessionRefreshExchange(baseUrl) {
|
|
1285
|
+
return createRotatingSessionRefreshExchange(
|
|
1286
|
+
baseUrl,
|
|
1287
|
+
AGENCY_ADMIN_TOKENS_REFRESH_PATH,
|
|
1288
|
+
"Agency-admin session refresh request failed"
|
|
1289
|
+
);
|
|
1290
|
+
}
|
|
1291
|
+
function toKaafilError(error) {
|
|
1292
|
+
if (isKaafilError(error)) {
|
|
1293
|
+
return error;
|
|
1294
|
+
}
|
|
1295
|
+
return new KaafilNetworkError("Unexpected transport failure", { cause: error });
|
|
1296
|
+
}
|
|
1297
|
+
function toFailureOutcome(error) {
|
|
1298
|
+
return {
|
|
1299
|
+
ok: false,
|
|
1300
|
+
status: error.status ?? null,
|
|
1301
|
+
...error.code !== void 0 ? { code: error.code } : {},
|
|
1302
|
+
...error instanceof KaafilRateLimitedError && error.retryAfterSeconds !== void 0 ? { retryAfterSeconds: error.retryAfterSeconds } : {}
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
async function execute(ctx, request) {
|
|
1306
|
+
const idempotencyKey = OPERATION_ACCEPTS_IDEMPOTENCY_KEY[request.operationId] ? request.idempotencyKey ?? globalThis.crypto.randomUUID() : void 0;
|
|
1307
|
+
let lastError;
|
|
1308
|
+
let refreshAttempted = false;
|
|
1309
|
+
const sendAndClassify = async () => {
|
|
1310
|
+
try {
|
|
1311
|
+
const { data, meta } = await sendOnce(ctx, request, idempotencyKey);
|
|
1312
|
+
return { ok: true, value: attachMeta(data, meta) };
|
|
1313
|
+
} catch (error) {
|
|
1314
|
+
const typed = toKaafilError(error);
|
|
1315
|
+
lastError = typed;
|
|
1316
|
+
return toFailureOutcome(typed);
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
const attempt = async (_attemptNumber) => {
|
|
1320
|
+
const outcome = await sendAndClassify();
|
|
1321
|
+
if (outcome.ok) {
|
|
1322
|
+
return outcome;
|
|
1323
|
+
}
|
|
1324
|
+
const canRefresh = !refreshAttempted && outcome.code === KaafilErrorCode.Unauthenticated && isRotatingCredentialKind(ctx.credentials.kind);
|
|
1325
|
+
if (!canRefresh) {
|
|
1326
|
+
return outcome;
|
|
1327
|
+
}
|
|
1328
|
+
refreshAttempted = true;
|
|
1329
|
+
try {
|
|
1330
|
+
await ctx.credentials.refreshRotatingSession();
|
|
1331
|
+
} catch {
|
|
1332
|
+
return outcome;
|
|
1333
|
+
}
|
|
1334
|
+
return sendAndClassify();
|
|
1335
|
+
};
|
|
1336
|
+
renderPath(request.path, request.pathParams);
|
|
1337
|
+
try {
|
|
1338
|
+
return await executeWithRetry(attempt, {
|
|
1339
|
+
...ctx.maxAttempts !== void 0 ? { maxAttempts: ctx.maxAttempts } : {},
|
|
1340
|
+
...request.signal !== void 0 ? { signal: request.signal } : {},
|
|
1341
|
+
...ctx.random !== void 0 ? { random: ctx.random } : {},
|
|
1342
|
+
...idempotencyKey !== void 0 ? { idempotencyKey } : {},
|
|
1343
|
+
hasBody: request.body !== void 0
|
|
1344
|
+
});
|
|
1345
|
+
} catch (error) {
|
|
1346
|
+
if (error instanceof RetryExhaustedError) {
|
|
1347
|
+
throw lastError ?? error;
|
|
1348
|
+
}
|
|
1349
|
+
if (request.signal?.aborted === true) {
|
|
1350
|
+
throw new KaafilAbortError("Request aborted", { cause: lastError ?? error });
|
|
1351
|
+
}
|
|
1352
|
+
throw error;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
// src/idempotency.ts
|
|
1357
|
+
function newIdempotencyKey() {
|
|
1358
|
+
return globalThis.crypto.randomUUID();
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
// src/resources/journey.ts
|
|
1362
|
+
var DEFAULT_WAIT_UNTIL_READY_TIMEOUT_MS = 6e4;
|
|
1363
|
+
var DEFAULT_WAIT_UNTIL_READY_POLL_INTERVAL_MS = 1e3;
|
|
1364
|
+
function createJourneyResource(client) {
|
|
1365
|
+
const resource = {
|
|
1366
|
+
async get(options) {
|
|
1367
|
+
const { tripRef, signal } = options;
|
|
1368
|
+
return client.execute({
|
|
1369
|
+
method: "GET",
|
|
1370
|
+
operationId: OperationId.ReadJourney,
|
|
1371
|
+
path: "/api/v1/trips/{ref}/journey",
|
|
1372
|
+
pathParams: { ref: tripRef },
|
|
1373
|
+
...signal !== void 0 ? { signal } : {}
|
|
1374
|
+
});
|
|
1375
|
+
},
|
|
1376
|
+
async capabilities(options) {
|
|
1377
|
+
const { tripRef, signal } = options;
|
|
1378
|
+
return client.execute({
|
|
1379
|
+
method: "GET",
|
|
1380
|
+
operationId: OperationId.ReadJourneyCapabilities,
|
|
1381
|
+
path: "/api/v1/trips/{ref}/journey/capabilities",
|
|
1382
|
+
pathParams: { ref: tripRef },
|
|
1383
|
+
...signal !== void 0 ? { signal } : {}
|
|
1384
|
+
});
|
|
1385
|
+
},
|
|
1386
|
+
async rebuild(options) {
|
|
1387
|
+
const { tripRef, idempotencyKey, signal } = options;
|
|
1388
|
+
return client.execute({
|
|
1389
|
+
method: "POST",
|
|
1390
|
+
operationId: OperationId.RebuildJourney,
|
|
1391
|
+
path: "/api/v1/trips/{ref}/journey/rebuild",
|
|
1392
|
+
pathParams: { ref: tripRef },
|
|
1393
|
+
...idempotencyKey !== void 0 ? { idempotencyKey } : {},
|
|
1394
|
+
...signal !== void 0 ? { signal } : {}
|
|
1395
|
+
});
|
|
1396
|
+
},
|
|
1397
|
+
async runStep(options) {
|
|
1398
|
+
const { tripRef, stepId, idempotencyKey, signal } = options;
|
|
1399
|
+
return client.execute({
|
|
1400
|
+
method: "POST",
|
|
1401
|
+
operationId: OperationId.RunJourneyStep,
|
|
1402
|
+
path: "/api/v1/trips/{ref}/journey/steps/{stepId}/run",
|
|
1403
|
+
pathParams: { ref: tripRef, stepId },
|
|
1404
|
+
...idempotencyKey !== void 0 ? { idempotencyKey } : {},
|
|
1405
|
+
...signal !== void 0 ? { signal } : {}
|
|
1406
|
+
});
|
|
1407
|
+
},
|
|
1408
|
+
async waitUntilReady(options) {
|
|
1409
|
+
const {
|
|
1410
|
+
tripRef,
|
|
1411
|
+
timeoutMs = DEFAULT_WAIT_UNTIL_READY_TIMEOUT_MS,
|
|
1412
|
+
pollIntervalMs = DEFAULT_WAIT_UNTIL_READY_POLL_INTERVAL_MS,
|
|
1413
|
+
signal
|
|
1414
|
+
} = options;
|
|
1415
|
+
const deadlineAt = Date.now() + timeoutMs;
|
|
1416
|
+
for (; ; ) {
|
|
1417
|
+
try {
|
|
1418
|
+
return await resource.get({ tripRef, ...signal !== void 0 ? { signal } : {} });
|
|
1419
|
+
} catch (error) {
|
|
1420
|
+
if (!(error instanceof KaafilNotFoundError)) {
|
|
1421
|
+
throw error;
|
|
1422
|
+
}
|
|
1423
|
+
const remainingMs = deadlineAt - Date.now();
|
|
1424
|
+
if (remainingMs <= 0) {
|
|
1425
|
+
throw new KaafilTimeoutError(
|
|
1426
|
+
`journey.waitUntilReady timed out after ${String(timeoutMs)}ms waiting for trip "${tripRef}" to become ready. The most likely cause is that the background worker that consumes the build queue is not running against this engine.`,
|
|
1427
|
+
{ cause: error }
|
|
1428
|
+
);
|
|
1429
|
+
}
|
|
1430
|
+
try {
|
|
1431
|
+
await delayWithAbort(Math.min(pollIntervalMs, remainingMs), signal);
|
|
1432
|
+
} catch (sleepError) {
|
|
1433
|
+
throw new KaafilAbortError("Request aborted", { cause: sleepError });
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
},
|
|
1438
|
+
triggers: {
|
|
1439
|
+
async list(options) {
|
|
1440
|
+
const { agencyRef, signal } = options;
|
|
1441
|
+
return client.execute({
|
|
1442
|
+
method: "GET",
|
|
1443
|
+
operationId: OperationId.ListJourneyTriggers,
|
|
1444
|
+
path: "/api/v1/agencies/{ref}/journey-triggers",
|
|
1445
|
+
pathParams: { ref: agencyRef },
|
|
1446
|
+
...signal !== void 0 ? { signal } : {}
|
|
1447
|
+
});
|
|
1448
|
+
},
|
|
1449
|
+
async patch(options) {
|
|
1450
|
+
const { agencyRef, key, version, idempotencyKey, signal, ...body } = options;
|
|
1451
|
+
return client.execute({
|
|
1452
|
+
method: "PATCH",
|
|
1453
|
+
operationId: OperationId.PatchJourneyTrigger,
|
|
1454
|
+
path: "/api/v1/agencies/{ref}/journey-triggers/{key}",
|
|
1455
|
+
pathParams: { ref: agencyRef, key },
|
|
1456
|
+
body,
|
|
1457
|
+
headers: { "If-Match": String(version) },
|
|
1458
|
+
...idempotencyKey !== void 0 ? { idempotencyKey } : {},
|
|
1459
|
+
...signal !== void 0 ? { signal } : {}
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
};
|
|
1464
|
+
return resource;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
// src/resources/vendors.ts
|
|
1468
|
+
function createVendorsResource(client) {
|
|
1469
|
+
return {
|
|
1470
|
+
async list(options) {
|
|
1471
|
+
const { tripRef, signal } = options;
|
|
1472
|
+
return client.execute({
|
|
1473
|
+
method: "GET",
|
|
1474
|
+
operationId: OperationId.ListTripVendors,
|
|
1475
|
+
path: "/api/v1/trips/{ref}/vendors",
|
|
1476
|
+
pathParams: { ref: tripRef },
|
|
1477
|
+
...signal !== void 0 ? { signal } : {}
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
// src/generated/enums.ts
|
|
1484
|
+
var BookingStatus = {
|
|
1485
|
+
Confirmed: "CONFIRMED",
|
|
1486
|
+
Tentative: "TENTATIVE",
|
|
1487
|
+
Cancelled: "CANCELLED"
|
|
1488
|
+
};
|
|
1489
|
+
var ClaimStatusIngest = {
|
|
1490
|
+
Approved: "APPROVED",
|
|
1491
|
+
Paid: "PAID",
|
|
1492
|
+
Rejected: "REJECTED"
|
|
1493
|
+
};
|
|
1494
|
+
var EventType = {
|
|
1495
|
+
Trip: "TRIP",
|
|
1496
|
+
Trek: "TREK"
|
|
1497
|
+
};
|
|
1498
|
+
var Gender = {
|
|
1499
|
+
Male: "MALE",
|
|
1500
|
+
Female: "FEMALE",
|
|
1501
|
+
Other: "OTHER",
|
|
1502
|
+
Unknown: "UNKNOWN"
|
|
1503
|
+
};
|
|
1504
|
+
var ManagerRole = {
|
|
1505
|
+
Manager: "MANAGER",
|
|
1506
|
+
Coordinator: "COORDINATOR"
|
|
1507
|
+
};
|
|
1508
|
+
var ManifestMode = {
|
|
1509
|
+
Merge: "merge",
|
|
1510
|
+
Replace: "replace"
|
|
1511
|
+
};
|
|
1512
|
+
var PartyKind = {
|
|
1513
|
+
Family: "FAMILY",
|
|
1514
|
+
Couple: "COUPLE",
|
|
1515
|
+
Friends: "FRIENDS",
|
|
1516
|
+
Corporate: "CORPORATE",
|
|
1517
|
+
Other: "OTHER"
|
|
1518
|
+
};
|
|
1519
|
+
var TriggerAnchor = {
|
|
1520
|
+
Start: "START",
|
|
1521
|
+
End: "END"
|
|
1522
|
+
};
|
|
1523
|
+
var TripMode = {
|
|
1524
|
+
Group: "GROUP",
|
|
1525
|
+
Personalized: "PERSONALIZED"
|
|
1526
|
+
};
|
|
1527
|
+
var TripStatus = {
|
|
1528
|
+
Confirmed: "CONFIRMED",
|
|
1529
|
+
InProgress: "IN_PROGRESS",
|
|
1530
|
+
Completed: "COMPLETED",
|
|
1531
|
+
Postponed: "POSTPONED",
|
|
1532
|
+
Cancelled: "CANCELLED"
|
|
1533
|
+
};
|
|
1534
|
+
|
|
1535
|
+
// src/pagination/paginator.ts
|
|
1536
|
+
var KaafilPaginationError = class extends Error {
|
|
1537
|
+
constructor(message) {
|
|
1538
|
+
super(message);
|
|
1539
|
+
this.name = "KaafilPaginationError";
|
|
1540
|
+
}
|
|
1541
|
+
};
|
|
1542
|
+
var KaafilPaginationInFlightError = class _KaafilPaginationInFlightError extends KaafilPaginationError {
|
|
1543
|
+
constructor() {
|
|
1544
|
+
super("next() was called while a previous call on this paginator was still in flight.");
|
|
1545
|
+
this.name = "KaafilPaginationInFlightError";
|
|
1546
|
+
Object.setPrototypeOf(this, _KaafilPaginationInFlightError.prototype);
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
var KaafilPaginationExhaustedError = class _KaafilPaginationExhaustedError extends KaafilPaginationError {
|
|
1550
|
+
constructor() {
|
|
1551
|
+
super("next() was called after this paginator was already exhausted (hasNext is false).");
|
|
1552
|
+
this.name = "KaafilPaginationExhaustedError";
|
|
1553
|
+
Object.setPrototypeOf(this, _KaafilPaginationExhaustedError.prototype);
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
// src/client-entry.ts
|
|
1558
|
+
function openTokenField(input) {
|
|
1559
|
+
switch (input.kind) {
|
|
1560
|
+
case "managerSession":
|
|
1561
|
+
case "agencyAdmin":
|
|
1562
|
+
return ["accessToken", input.accessToken];
|
|
1563
|
+
case "shareToken":
|
|
1564
|
+
return ["token", input.token];
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
function openKindLabel(kind) {
|
|
1568
|
+
switch (kind) {
|
|
1569
|
+
case "managerSession":
|
|
1570
|
+
return "manager session";
|
|
1571
|
+
case "agencyAdmin":
|
|
1572
|
+
return "agency-admin session";
|
|
1573
|
+
case "shareToken":
|
|
1574
|
+
return "share";
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
function assertOpenTokenPresent(input) {
|
|
1578
|
+
const [field, value] = openTokenField(input);
|
|
1579
|
+
if (typeof value === "function") {
|
|
1580
|
+
return;
|
|
1581
|
+
}
|
|
1582
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
1583
|
+
throw new KaafilConfigError(
|
|
1584
|
+
`"${field}" is required to open a ${openKindLabel(input.kind)} and was missing or empty. Pass the value returned by the mint call.`
|
|
1585
|
+
);
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
var KaafilClientNotOpenError = class _KaafilClientNotOpenError extends Error {
|
|
1589
|
+
constructor() {
|
|
1590
|
+
super(
|
|
1591
|
+
'This KaafilClient has no open session \u2014 call "session.open(...)", "admin.open(...)", or "share.open(...)" before using a resource, or after "close()".'
|
|
1592
|
+
);
|
|
1593
|
+
this.name = "KaafilClientNotOpenError";
|
|
1594
|
+
Object.setPrototypeOf(this, _KaafilClientNotOpenError.prototype);
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
var KaafilClientAlreadyOpenError = class _KaafilClientAlreadyOpenError extends Error {
|
|
1598
|
+
constructor() {
|
|
1599
|
+
super('This KaafilClient already has an open session; call "close()" before opening another.');
|
|
1600
|
+
this.name = "KaafilClientAlreadyOpenError";
|
|
1601
|
+
Object.setPrototypeOf(this, _KaafilClientAlreadyOpenError.prototype);
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1604
|
+
var KaafilClient = class {
|
|
1605
|
+
#config;
|
|
1606
|
+
#state = null;
|
|
1607
|
+
constructor(options) {
|
|
1608
|
+
assertValidTimeout(options.timeoutMs);
|
|
1609
|
+
assertValidMaxAttempts(options.maxAttempts);
|
|
1610
|
+
this.#config = {
|
|
1611
|
+
baseUrl: resolveBaseUrl(options.environment, options.baseUrl),
|
|
1612
|
+
timeoutMs: options.timeoutMs,
|
|
1613
|
+
maxAttempts: options.maxAttempts,
|
|
1614
|
+
userAgent: options.userAgent,
|
|
1615
|
+
random: options.random
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
session = {
|
|
1619
|
+
/**
|
|
1620
|
+
* Opens a manager session with the access/refresh pair a server-side
|
|
1621
|
+
* `kaafil.auth.mintManagerToken(...)` call already minted. Rotation
|
|
1622
|
+
* after this point — pre-emptive, and on a `401` — is entirely
|
|
1623
|
+
* automatic: `CredentialResolver` exchanges directly with the engine
|
|
1624
|
+
* (`../auth/credentials.ts`, `../http/client.ts`'s
|
|
1625
|
+
* `createManagerSessionRefreshExchange`). Nothing else is required —
|
|
1626
|
+
* `refresh`/`onRefresh` above are optional hooks, not obligations.
|
|
1627
|
+
*/
|
|
1628
|
+
open: (options) => {
|
|
1629
|
+
this.#open({ kind: "managerSession", ...options });
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
admin = {
|
|
1633
|
+
/**
|
|
1634
|
+
* Opens an agency-admin session with the access/refresh pair a
|
|
1635
|
+
* server-side `kaafil.auth.mintAgencyAdminToken(...)` call already
|
|
1636
|
+
* minted. Rotation after this point — pre-emptive, and on a `401` — is
|
|
1637
|
+
* entirely automatic, the same way `session.open`'s is:
|
|
1638
|
+
* `CredentialResolver` exchanges directly with the engine
|
|
1639
|
+
* (`../auth/credentials.ts`, `../http/client.ts`'s
|
|
1640
|
+
* `createAgencyAdminSessionRefreshExchange`). Nothing else is required
|
|
1641
|
+
* — `refresh`/`onRefresh` above are optional hooks, not obligations.
|
|
1642
|
+
*/
|
|
1643
|
+
open: (options) => {
|
|
1644
|
+
this.#open({ kind: "agencyAdmin", ...options });
|
|
1645
|
+
}
|
|
1646
|
+
};
|
|
1647
|
+
share = {
|
|
1648
|
+
/** Opens a read-only session with a share token minted server-side by
|
|
1649
|
+
* `kaafil.shareTokens.create(...)`. */
|
|
1650
|
+
open: (options) => {
|
|
1651
|
+
this.#open({ kind: "shareToken", ...options });
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
get vendors() {
|
|
1655
|
+
return this.#requireState().vendors;
|
|
1656
|
+
}
|
|
1657
|
+
get journey() {
|
|
1658
|
+
return this.#requireState().journey;
|
|
1659
|
+
}
|
|
1660
|
+
/**
|
|
1661
|
+
* Total teardown. One assignment, no field to forget — see
|
|
1662
|
+
* `KaafilClientState` above. Safe to call whether or not a session is
|
|
1663
|
+
* open; calling any resource method afterward throws
|
|
1664
|
+
* `KaafilClientNotOpenError`, and `session.open`/`share.open` can be
|
|
1665
|
+
* called again immediately after.
|
|
1666
|
+
*/
|
|
1667
|
+
close() {
|
|
1668
|
+
this.#state = null;
|
|
1669
|
+
}
|
|
1670
|
+
/**
|
|
1671
|
+
* Mints an idempotency key outside the normal per-call flow. Every
|
|
1672
|
+
* mutating method already mints and reuses one automatically
|
|
1673
|
+
* (`../http/client.ts`) — this exists for the rare case of pinning a key
|
|
1674
|
+
* ahead of time, to replay the exact same logical operation across a
|
|
1675
|
+
* process restart.
|
|
1676
|
+
*/
|
|
1677
|
+
static newIdempotencyKey() {
|
|
1678
|
+
return newIdempotencyKey();
|
|
1679
|
+
}
|
|
1680
|
+
#open(input) {
|
|
1681
|
+
if (this.#state !== null) {
|
|
1682
|
+
throw new KaafilClientAlreadyOpenError();
|
|
1683
|
+
}
|
|
1684
|
+
assertOpenTokenPresent(input);
|
|
1685
|
+
let credentialConfig;
|
|
1686
|
+
let rotatingSessionExchange;
|
|
1687
|
+
switch (input.kind) {
|
|
1688
|
+
case "managerSession":
|
|
1689
|
+
credentialConfig = {
|
|
1690
|
+
kind: "managerSession",
|
|
1691
|
+
accessToken: input.accessToken,
|
|
1692
|
+
refreshToken: input.refreshToken,
|
|
1693
|
+
...input.expiresAt !== void 0 ? { expiresAt: input.expiresAt } : {},
|
|
1694
|
+
...input.refresh !== void 0 ? { refresh: input.refresh } : {},
|
|
1695
|
+
...input.onRefresh !== void 0 ? { onRefresh: input.onRefresh } : {}
|
|
1696
|
+
};
|
|
1697
|
+
rotatingSessionExchange = createManagerSessionRefreshExchange(this.#config.baseUrl);
|
|
1698
|
+
break;
|
|
1699
|
+
case "agencyAdmin":
|
|
1700
|
+
credentialConfig = {
|
|
1701
|
+
kind: "agencyAdmin",
|
|
1702
|
+
accessToken: input.accessToken,
|
|
1703
|
+
refreshToken: input.refreshToken,
|
|
1704
|
+
...input.expiresAt !== void 0 ? { expiresAt: input.expiresAt } : {},
|
|
1705
|
+
...input.refresh !== void 0 ? { refresh: input.refresh } : {},
|
|
1706
|
+
...input.onRefresh !== void 0 ? { onRefresh: input.onRefresh } : {}
|
|
1707
|
+
};
|
|
1708
|
+
rotatingSessionExchange = createAgencyAdminSessionRefreshExchange(this.#config.baseUrl);
|
|
1709
|
+
break;
|
|
1710
|
+
case "shareToken":
|
|
1711
|
+
credentialConfig = { kind: "shareToken", token: input.token };
|
|
1712
|
+
break;
|
|
1713
|
+
}
|
|
1714
|
+
const credentials = new CredentialResolver(credentialConfig, rotatingSessionExchange);
|
|
1715
|
+
const http = createHttpClient({
|
|
1716
|
+
baseUrl: this.#config.baseUrl,
|
|
1717
|
+
credentials,
|
|
1718
|
+
...this.#config.timeoutMs !== void 0 ? { timeoutMs: this.#config.timeoutMs } : {},
|
|
1719
|
+
...this.#config.maxAttempts !== void 0 ? { maxAttempts: this.#config.maxAttempts } : {},
|
|
1720
|
+
...this.#config.userAgent !== void 0 ? { userAgent: this.#config.userAgent } : {},
|
|
1721
|
+
...this.#config.random !== void 0 ? { random: this.#config.random } : {}
|
|
1722
|
+
});
|
|
1723
|
+
this.#state = {
|
|
1724
|
+
http,
|
|
1725
|
+
vendors: createVendorsResource(http),
|
|
1726
|
+
journey: createJourneyResource(http)
|
|
1727
|
+
};
|
|
1728
|
+
}
|
|
1729
|
+
#requireState() {
|
|
1730
|
+
if (this.#state === null) {
|
|
1731
|
+
throw new KaafilClientNotOpenError();
|
|
1732
|
+
}
|
|
1733
|
+
return this.#state;
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
|
|
1737
|
+
export { BookingStatus, ClaimStatusIngest, ERROR_CODE_TABLE, EventType, Gender, KaafilAbortError, KaafilApiError, KaafilCapabilityUnavailableError, KaafilClient, KaafilClientAlreadyOpenError, KaafilClientNotOpenError, KaafilEntitlementError, KaafilError, KaafilErrorCode, KaafilInvalidRequestError, KaafilLockedError, KaafilNetworkError, KaafilNotFoundError, KaafilNotImplementedError, KaafilPaginationError, KaafilPaginationExhaustedError, KaafilPaginationInFlightError, KaafilRateLimitedError, KaafilReadOnlyRoleError, KaafilShareTokenExpiredError, KaafilShareTokenRevokedError, KaafilTimeoutError, KaafilTransportError, KaafilUnauthenticatedError, KaafilValidationError, KaafilVersionConflictError, ManagerRole, ManifestMode, OutboxClass, PartyKind, Retryability, TriggerAnchor, TripMode, TripStatus, UnsatisfiableSchemeError, isKaafilError, isRetryable };
|
|
1738
|
+
//# sourceMappingURL=client-entry.js.map
|
|
1739
|
+
//# sourceMappingURL=client-entry.js.map
|