feeef 0.5.38-dev.2 → 0.5.38-dev.4
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/build/index.js +897 -42
- package/build/index.js.map +1 -1
- package/build/src/core/entities/city.d.ts +17 -0
- package/build/src/core/entities/country.d.ts +17 -0
- package/build/src/core/entities/currency.d.ts +21 -0
- package/build/src/core/entities/order.d.ts +1 -0
- package/build/src/core/entities/product.d.ts +1 -0
- package/build/src/core/entities/shipping_price.d.ts +120 -0
- package/build/src/core/entities/state.d.ts +17 -0
- package/build/src/core/entities/store.d.ts +1 -0
- package/build/src/core/entities/user.d.ts +155 -0
- package/build/src/feeef/feeef.d.ts +30 -0
- package/build/src/feeef/repositories/cities.d.ts +78 -0
- package/build/src/feeef/repositories/countries.d.ts +20 -0
- package/build/src/feeef/repositories/currencies.d.ts +20 -0
- package/build/src/feeef/repositories/shipping_prices.d.ts +28 -0
- package/build/src/feeef/repositories/states.d.ts +62 -0
- package/build/src/feeef/repositories/transfers.d.ts +38 -0
- package/build/src/feeef/repositories/users.d.ts +124 -12
- package/build/src/feeef/services/cart.d.ts +46 -5
- package/build/src/index.d.ts +10 -0
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -190,9 +190,27 @@ var StoreRepository = class extends ModelRepository {
|
|
|
190
190
|
// src/feeef/repositories/users.ts
|
|
191
191
|
var UserRepository = class extends ModelRepository {
|
|
192
192
|
/**
|
|
193
|
-
* Represents the authentication response.
|
|
193
|
+
* Represents the current authentication response.
|
|
194
|
+
* Set automatically after signin, signup, or signinWithToken.
|
|
194
195
|
*/
|
|
195
|
-
|
|
196
|
+
_auth = null;
|
|
197
|
+
/**
|
|
198
|
+
* Gets the current authentication response.
|
|
199
|
+
*/
|
|
200
|
+
get auth() {
|
|
201
|
+
return this._auth;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Sets the authentication response and updates the Authorization header.
|
|
205
|
+
*/
|
|
206
|
+
set auth(value) {
|
|
207
|
+
this._auth = value;
|
|
208
|
+
if (value?.token?.token) {
|
|
209
|
+
this.client.defaults.headers.common["Authorization"] = `Bearer ${value.token.token}`;
|
|
210
|
+
} else {
|
|
211
|
+
delete this.client.defaults.headers.common["Authorization"];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
196
214
|
/**
|
|
197
215
|
* Constructs a new UserRepository instance.
|
|
198
216
|
* @param client - The AxiosInstance used for making HTTP requests.
|
|
@@ -202,43 +220,264 @@ var UserRepository = class extends ModelRepository {
|
|
|
202
220
|
}
|
|
203
221
|
/**
|
|
204
222
|
* Signs in a user with the provided credentials.
|
|
205
|
-
* @param credentials - The user credentials.
|
|
223
|
+
* @param credentials - The user credentials (email, password, optional fcmToken).
|
|
206
224
|
* @returns A promise that resolves to the authentication response.
|
|
207
225
|
*/
|
|
208
226
|
async signin(credentials) {
|
|
209
|
-
const
|
|
210
|
-
const res = await this.client.post(`/${this.resource}/auth/signin`, output);
|
|
227
|
+
const res = await this.client.post(`/${this.resource}/auth/signin`, credentials);
|
|
211
228
|
this.auth = res.data;
|
|
212
|
-
return
|
|
229
|
+
return this.auth;
|
|
213
230
|
}
|
|
214
231
|
/**
|
|
215
232
|
* Signs up a new user with the provided credentials.
|
|
216
|
-
* @param credentials - The user credentials.
|
|
233
|
+
* @param credentials - The user signup credentials.
|
|
217
234
|
* @returns A promise that resolves to the authentication response.
|
|
218
235
|
*/
|
|
219
236
|
async signup(credentials) {
|
|
220
|
-
const
|
|
221
|
-
const res = await this.client.post(`/${this.resource}/auth/signup`, output);
|
|
237
|
+
const res = await this.client.post(`/${this.resource}/auth/signup`, credentials);
|
|
222
238
|
this.auth = res.data;
|
|
223
|
-
return
|
|
239
|
+
return this.auth;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Signs in a user with an existing token.
|
|
243
|
+
* Useful for restoring authentication state from localStorage.
|
|
244
|
+
* @param token - The authentication token.
|
|
245
|
+
* @param fcmToken - Optional FCM token for push notifications.
|
|
246
|
+
* @returns A promise that resolves to the authentication response.
|
|
247
|
+
*/
|
|
248
|
+
async signinWithToken(token, fcmToken) {
|
|
249
|
+
this.client.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
250
|
+
const res = await this.client.get(`/${this.resource}/auth`);
|
|
251
|
+
if (fcmToken) {
|
|
252
|
+
try {
|
|
253
|
+
await this.client.post(`/${this.resource}/auth/fcm-token`, { fcmToken });
|
|
254
|
+
} catch (e) {
|
|
255
|
+
console.warn("Failed to update FCM token:", e);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
this.auth = {
|
|
259
|
+
user: res.data.user,
|
|
260
|
+
token: { ...res.data.token, token }
|
|
261
|
+
};
|
|
262
|
+
return this.auth;
|
|
224
263
|
}
|
|
225
264
|
/**
|
|
226
265
|
* Signs out the currently authenticated user.
|
|
266
|
+
* Deletes the token on the server and clears local auth state.
|
|
227
267
|
* @returns A promise that resolves when the user is signed out.
|
|
228
268
|
*/
|
|
229
269
|
async signout() {
|
|
270
|
+
if (this.auth) {
|
|
271
|
+
try {
|
|
272
|
+
await this.client.post(`/${this.resource}/auth/signout`);
|
|
273
|
+
} catch (e) {
|
|
274
|
+
console.warn("Signout request failed:", e);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
230
277
|
this.auth = null;
|
|
231
278
|
}
|
|
232
279
|
/**
|
|
233
|
-
*
|
|
280
|
+
* Gets the currently authenticated user.
|
|
281
|
+
* @returns A promise that resolves to the authentication response with current user.
|
|
282
|
+
*/
|
|
283
|
+
async me() {
|
|
284
|
+
const res = await this.client.get(`/${this.resource}/auth`);
|
|
285
|
+
this.auth = res.data;
|
|
286
|
+
return this.auth;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Updates the authenticated user's profile.
|
|
234
290
|
* @param data - The updated user data.
|
|
235
291
|
* @returns A promise that resolves to the updated user entity.
|
|
236
292
|
*/
|
|
237
293
|
async updateMe(data) {
|
|
238
|
-
const
|
|
239
|
-
|
|
294
|
+
const res = await this.client.put(`/${this.resource}/auth`, data);
|
|
295
|
+
if (this.auth) {
|
|
296
|
+
this.auth = {
|
|
297
|
+
...this.auth,
|
|
298
|
+
user: res.data
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
return res.data;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Sends a password reset email to the user.
|
|
305
|
+
* @param email - The user's email address.
|
|
306
|
+
* @returns A promise that resolves when the email is sent.
|
|
307
|
+
*/
|
|
308
|
+
async sendResetPasswordEmail(email) {
|
|
309
|
+
await this.client.post(`/${this.resource}/auth/reset-password`, null, {
|
|
310
|
+
params: { email }
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Resets the password using a token from the reset email.
|
|
315
|
+
* @param uid - The user ID.
|
|
316
|
+
* @param token - The reset token from the email.
|
|
317
|
+
* @returns A promise that resolves when the password is reset.
|
|
318
|
+
*/
|
|
319
|
+
async resetPasswordWithToken(uid, token) {
|
|
320
|
+
await this.client.get(`/${this.resource}/auth/reset-password`, {
|
|
321
|
+
params: { uid, token }
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Gets all access tokens for the authenticated user.
|
|
326
|
+
* @returns A promise that resolves to an array of access tokens.
|
|
327
|
+
*/
|
|
328
|
+
async tokens() {
|
|
329
|
+
const res = await this.client.get(`/${this.resource}/auth/tokens`);
|
|
330
|
+
return res.data;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Signs in with Google OAuth.
|
|
334
|
+
* @param options - The OAuth code and optional FCM token.
|
|
335
|
+
* @returns A promise that resolves to the authentication response.
|
|
336
|
+
*/
|
|
337
|
+
async signinWithGoogle(options) {
|
|
338
|
+
const res = await this.client.post("/social/google/callback", {
|
|
339
|
+
code: options.code,
|
|
340
|
+
fcmToken: options.fcmToken
|
|
341
|
+
});
|
|
342
|
+
this.auth = res.data;
|
|
343
|
+
return this.auth;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Signs in with GitHub OAuth.
|
|
347
|
+
* @param options - The OAuth code and optional FCM token.
|
|
348
|
+
* @returns A promise that resolves to the authentication response.
|
|
349
|
+
*/
|
|
350
|
+
async signinWithGitHub(options) {
|
|
351
|
+
const res = await this.client.post("/social/github/callback", {
|
|
352
|
+
code: options.code,
|
|
353
|
+
fcmToken: options.fcmToken
|
|
354
|
+
});
|
|
355
|
+
this.auth = res.data;
|
|
356
|
+
return this.auth;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Signs in with Apple OAuth.
|
|
360
|
+
* @param options - The OAuth code and optional FCM token.
|
|
361
|
+
* @returns A promise that resolves to the authentication response.
|
|
362
|
+
*/
|
|
363
|
+
async signinWithApple(options) {
|
|
364
|
+
const res = await this.client.post("/social/apple/callback", {
|
|
365
|
+
code: options.code,
|
|
366
|
+
fcmToken: options.fcmToken
|
|
367
|
+
});
|
|
368
|
+
this.auth = res.data;
|
|
369
|
+
return this.auth;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Links a social account to the current user.
|
|
373
|
+
* @param options - The provider and OAuth code.
|
|
374
|
+
* @returns A promise that resolves to the updated user entity.
|
|
375
|
+
*/
|
|
376
|
+
async linkSocialAccount(options) {
|
|
377
|
+
const res = await this.client.post(`/social/${options.provider}/link/callback`, {
|
|
378
|
+
code: options.code
|
|
379
|
+
});
|
|
380
|
+
if (this.auth && this.auth.user.id === res.data.user.id) {
|
|
381
|
+
this.auth = {
|
|
382
|
+
...this.auth,
|
|
383
|
+
user: res.data.user
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
return res.data.user;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Unlinks a social account from the current user.
|
|
390
|
+
* @param provider - The social provider to unlink.
|
|
391
|
+
* @returns A promise that resolves to the updated user entity.
|
|
392
|
+
*/
|
|
393
|
+
async unlinkSocialAccount(provider) {
|
|
394
|
+
const res = await this.client.post("/social/unlink", { provider });
|
|
395
|
+
if (this.auth && this.auth.user.id === res.data.user.id) {
|
|
396
|
+
this.auth = {
|
|
397
|
+
...this.auth,
|
|
398
|
+
user: res.data.user
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
return res.data.user;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Transfers money from the authenticated user to another user.
|
|
405
|
+
* @param options - Transfer options including recipient and amount.
|
|
406
|
+
* @returns A promise that resolves to the transfer response with updated users.
|
|
407
|
+
*/
|
|
408
|
+
async transferMoney(options) {
|
|
409
|
+
const res = await this.client.post(`/${this.resource}/auth/transfer`, options);
|
|
410
|
+
if (this.auth && this.auth.user.id === res.data.sender.id) {
|
|
411
|
+
this.auth = {
|
|
412
|
+
...this.auth,
|
|
413
|
+
user: res.data.sender
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
return res.data;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Starts passkey registration.
|
|
420
|
+
* @param options - Optional device name for the passkey.
|
|
421
|
+
* @returns A promise that resolves to the registration challenge data.
|
|
422
|
+
*/
|
|
423
|
+
async startPasskeyRegistration(options) {
|
|
424
|
+
const res = await this.client.post("/passkeys/register/start", {
|
|
425
|
+
deviceName: options?.deviceName
|
|
426
|
+
});
|
|
240
427
|
return res.data;
|
|
241
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* Finishes passkey registration.
|
|
431
|
+
* @param options - The registration response from the authenticator.
|
|
432
|
+
* @returns A promise that resolves to the authentication response.
|
|
433
|
+
*/
|
|
434
|
+
async finishPasskeyRegistration(options) {
|
|
435
|
+
const res = await this.client.post("/passkeys/register/finish", {
|
|
436
|
+
response: options.registrationResponse,
|
|
437
|
+
deviceName: options.deviceName
|
|
438
|
+
});
|
|
439
|
+
this.auth = res.data;
|
|
440
|
+
return this.auth;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Starts passkey authentication.
|
|
444
|
+
* @param options - Optional email to identify the user.
|
|
445
|
+
* @returns A promise that resolves to the authentication challenge data.
|
|
446
|
+
*/
|
|
447
|
+
async startPasskeyAuthentication(options) {
|
|
448
|
+
const res = await this.client.post("/passkeys/authenticate/start", {
|
|
449
|
+
email: options?.email
|
|
450
|
+
});
|
|
451
|
+
return res.data;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Finishes passkey authentication.
|
|
455
|
+
* @param options - The authentication response from the authenticator.
|
|
456
|
+
* @returns A promise that resolves to the authentication response.
|
|
457
|
+
*/
|
|
458
|
+
async finishPasskeyAuthentication(options) {
|
|
459
|
+
const res = await this.client.post("/passkeys/authenticate/finish", {
|
|
460
|
+
response: options.authenticationResponse
|
|
461
|
+
});
|
|
462
|
+
this.auth = res.data;
|
|
463
|
+
return this.auth;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Lists all passkeys for the authenticated user.
|
|
467
|
+
* @returns A promise that resolves to an array of passkeys.
|
|
468
|
+
*/
|
|
469
|
+
async listPasskeys() {
|
|
470
|
+
const res = await this.client.get("/passkeys");
|
|
471
|
+
return res.data.passkeys || [];
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Deletes a passkey.
|
|
475
|
+
* @param passkeyId - The ID of the passkey to delete.
|
|
476
|
+
* @returns A promise that resolves when the passkey is deleted.
|
|
477
|
+
*/
|
|
478
|
+
async deletePasskey(passkeyId) {
|
|
479
|
+
await this.client.delete(`/passkeys/${passkeyId}`);
|
|
480
|
+
}
|
|
242
481
|
};
|
|
243
482
|
|
|
244
483
|
// src/feeef/repositories/deposits.ts
|
|
@@ -304,6 +543,17 @@ var DepositRepository = class extends ModelRepository {
|
|
|
304
543
|
}
|
|
305
544
|
};
|
|
306
545
|
|
|
546
|
+
// src/feeef/repositories/transfers.ts
|
|
547
|
+
var TransferRepository = class extends ModelRepository {
|
|
548
|
+
/**
|
|
549
|
+
* Constructs a new TransferRepository instance
|
|
550
|
+
* @param client - The AxiosInstance used for making HTTP requests
|
|
551
|
+
*/
|
|
552
|
+
constructor(client) {
|
|
553
|
+
super("transfers", client);
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
|
|
307
557
|
// src/feeef/repositories/categories.ts
|
|
308
558
|
var CategoryRepository = class extends ModelRepository {
|
|
309
559
|
/**
|
|
@@ -315,6 +565,297 @@ var CategoryRepository = class extends ModelRepository {
|
|
|
315
565
|
}
|
|
316
566
|
};
|
|
317
567
|
|
|
568
|
+
// src/feeef/repositories/countries.ts
|
|
569
|
+
var CountryRepository = class extends ModelRepository {
|
|
570
|
+
/**
|
|
571
|
+
* Constructs a new CountryRepository instance.
|
|
572
|
+
* @param client The AxiosInstance used for making HTTP requests.
|
|
573
|
+
*/
|
|
574
|
+
constructor(client) {
|
|
575
|
+
super("countries", client);
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Finds a country by its code (ID is the country code).
|
|
579
|
+
* @param code - The country code (ISO 3166-1 alpha-2).
|
|
580
|
+
* @param params - Optional query parameters.
|
|
581
|
+
* @returns A Promise that resolves to the found Country entity.
|
|
582
|
+
*/
|
|
583
|
+
async findByCode(code, params) {
|
|
584
|
+
return this.find({ id: code.toUpperCase(), params });
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
// src/feeef/repositories/states.ts
|
|
589
|
+
var StateRepository = class extends ModelRepository {
|
|
590
|
+
/**
|
|
591
|
+
* Constructs a new StateRepository instance.
|
|
592
|
+
* @param client The AxiosInstance used for making HTTP requests.
|
|
593
|
+
*/
|
|
594
|
+
constructor(client) {
|
|
595
|
+
super("states", client);
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Lists states, optionally filtered by country code.
|
|
599
|
+
* @param options - The options for listing states, including countryCode filter.
|
|
600
|
+
* @returns A Promise that resolves to a list of State entities.
|
|
601
|
+
*/
|
|
602
|
+
async list(options) {
|
|
603
|
+
const { countryCode, ...listOptions } = options || {};
|
|
604
|
+
const params = {
|
|
605
|
+
...listOptions.params,
|
|
606
|
+
...countryCode && { country_code: countryCode }
|
|
607
|
+
};
|
|
608
|
+
return super.list({ ...listOptions, params });
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Lists states for a specific country (nested route).
|
|
612
|
+
* @param countryCode - The country code.
|
|
613
|
+
* @param options - Optional list options.
|
|
614
|
+
* @returns A Promise that resolves to a list of State entities.
|
|
615
|
+
*/
|
|
616
|
+
async listByCountry(countryCode, options) {
|
|
617
|
+
const res = await this.client.get(`/countries/${countryCode}/states`, {
|
|
618
|
+
params: {
|
|
619
|
+
page: options?.page,
|
|
620
|
+
offset: options?.offset,
|
|
621
|
+
limit: options?.limit,
|
|
622
|
+
...options?.params
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
if (Array.isArray(res.data)) {
|
|
626
|
+
return { data: res.data };
|
|
627
|
+
} else {
|
|
628
|
+
return {
|
|
629
|
+
data: res.data.data,
|
|
630
|
+
total: res.data.meta.total,
|
|
631
|
+
page: res.data.meta.currentPage,
|
|
632
|
+
limit: res.data.meta.perPage
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Finds a state by country code and state code.
|
|
638
|
+
* @param countryCode - The country code.
|
|
639
|
+
* @param stateCode - The state code.
|
|
640
|
+
* @param params - Optional query parameters.
|
|
641
|
+
* @returns A Promise that resolves to the found State entity.
|
|
642
|
+
*/
|
|
643
|
+
async findByCode(countryCode, stateCode, params) {
|
|
644
|
+
const res = await this.client.get(`/countries/${countryCode}/states/${stateCode}`, { params });
|
|
645
|
+
return res.data;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Creates a new state (nested under country).
|
|
649
|
+
* @param countryCode - The country code.
|
|
650
|
+
* @param data - The state data.
|
|
651
|
+
* @param params - Optional query parameters.
|
|
652
|
+
* @returns A Promise that resolves to the created State entity.
|
|
653
|
+
*/
|
|
654
|
+
async createByCountry(countryCode, data, params) {
|
|
655
|
+
const res = await this.client.post(`/countries/${countryCode}/states`, data, { params });
|
|
656
|
+
return res.data;
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Updates a state (nested under country).
|
|
660
|
+
* @param countryCode - The country code.
|
|
661
|
+
* @param stateCode - The state code.
|
|
662
|
+
* @param data - The update data.
|
|
663
|
+
* @param params - Optional query parameters.
|
|
664
|
+
* @returns A Promise that resolves to the updated State entity.
|
|
665
|
+
*/
|
|
666
|
+
async updateByCountry(countryCode, stateCode, data, params) {
|
|
667
|
+
const res = await this.client.put(`/countries/${countryCode}/states/${stateCode}`, data, {
|
|
668
|
+
params
|
|
669
|
+
});
|
|
670
|
+
return res.data;
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Deletes a state (nested under country).
|
|
674
|
+
* @param countryCode - The country code.
|
|
675
|
+
* @param stateCode - The state code.
|
|
676
|
+
* @param params - Optional query parameters.
|
|
677
|
+
* @returns A Promise that resolves when the state is deleted.
|
|
678
|
+
*/
|
|
679
|
+
async deleteByCountry(countryCode, stateCode, params) {
|
|
680
|
+
await this.client.delete(`/countries/${countryCode}/states/${stateCode}`, { params });
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
// src/feeef/repositories/cities.ts
|
|
685
|
+
var CityRepository = class extends ModelRepository {
|
|
686
|
+
/**
|
|
687
|
+
* Constructs a new CityRepository instance.
|
|
688
|
+
* @param client The AxiosInstance used for making HTTP requests.
|
|
689
|
+
*/
|
|
690
|
+
constructor(client) {
|
|
691
|
+
super("cities", client);
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Lists cities, optionally filtered by country code and/or state code.
|
|
695
|
+
* @param options - The options for listing cities, including filters.
|
|
696
|
+
* @returns A Promise that resolves to a list of City entities.
|
|
697
|
+
*/
|
|
698
|
+
async list(options) {
|
|
699
|
+
const { countryCode, stateCode, ...listOptions } = options || {};
|
|
700
|
+
const params = {
|
|
701
|
+
...listOptions.params,
|
|
702
|
+
...countryCode && { country_code: countryCode },
|
|
703
|
+
...stateCode && { state_code: stateCode }
|
|
704
|
+
};
|
|
705
|
+
return super.list({ ...listOptions, params });
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Lists cities for a specific country and state (nested route).
|
|
709
|
+
* @param countryCode - The country code.
|
|
710
|
+
* @param stateCode - The state code.
|
|
711
|
+
* @param options - Optional list options.
|
|
712
|
+
* @returns A Promise that resolves to a list of City entities.
|
|
713
|
+
*/
|
|
714
|
+
async listByState(countryCode, stateCode, options) {
|
|
715
|
+
const res = await this.client.get(`/countries/${countryCode}/states/${stateCode}/cities`, {
|
|
716
|
+
params: {
|
|
717
|
+
page: options?.page,
|
|
718
|
+
offset: options?.offset,
|
|
719
|
+
limit: options?.limit,
|
|
720
|
+
...options?.params
|
|
721
|
+
}
|
|
722
|
+
});
|
|
723
|
+
if (Array.isArray(res.data)) {
|
|
724
|
+
return { data: res.data };
|
|
725
|
+
} else {
|
|
726
|
+
return {
|
|
727
|
+
data: res.data.data,
|
|
728
|
+
total: res.data.meta.total,
|
|
729
|
+
page: res.data.meta.currentPage,
|
|
730
|
+
limit: res.data.meta.perPage
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Finds a city by country code, state code, and city name.
|
|
736
|
+
* @param countryCode - The country code.
|
|
737
|
+
* @param stateCode - The state code.
|
|
738
|
+
* @param cityName - The city name.
|
|
739
|
+
* @param params - Optional query parameters.
|
|
740
|
+
* @returns A Promise that resolves to the found City entity.
|
|
741
|
+
*/
|
|
742
|
+
async findByName(countryCode, stateCode, cityName, params) {
|
|
743
|
+
const res = await this.client.get(
|
|
744
|
+
`/countries/${countryCode}/states/${stateCode}/cities/${cityName}`,
|
|
745
|
+
{ params }
|
|
746
|
+
);
|
|
747
|
+
return res.data;
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Creates a new city (nested under country/state).
|
|
751
|
+
* @param countryCode - The country code.
|
|
752
|
+
* @param stateCode - The state code.
|
|
753
|
+
* @param data - The city data.
|
|
754
|
+
* @param params - Optional query parameters.
|
|
755
|
+
* @returns A Promise that resolves to the created City entity.
|
|
756
|
+
*/
|
|
757
|
+
async createByState(countryCode, stateCode, data, params) {
|
|
758
|
+
const res = await this.client.post(
|
|
759
|
+
`/countries/${countryCode}/states/${stateCode}/cities`,
|
|
760
|
+
data,
|
|
761
|
+
{ params }
|
|
762
|
+
);
|
|
763
|
+
return res.data;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Updates a city (nested under country/state).
|
|
767
|
+
* @param countryCode - The country code.
|
|
768
|
+
* @param stateCode - The state code.
|
|
769
|
+
* @param cityName - The city name.
|
|
770
|
+
* @param data - The update data.
|
|
771
|
+
* @param params - Optional query parameters.
|
|
772
|
+
* @returns A Promise that resolves to the updated City entity.
|
|
773
|
+
*/
|
|
774
|
+
async updateByState(countryCode, stateCode, cityName, data, params) {
|
|
775
|
+
const res = await this.client.put(
|
|
776
|
+
`/countries/${countryCode}/states/${stateCode}/cities/${cityName}`,
|
|
777
|
+
data,
|
|
778
|
+
{ params }
|
|
779
|
+
);
|
|
780
|
+
return res.data;
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Deletes a city (nested under country/state).
|
|
784
|
+
* @param countryCode - The country code.
|
|
785
|
+
* @param stateCode - The state code.
|
|
786
|
+
* @param cityName - The city name.
|
|
787
|
+
* @param params - Optional query parameters.
|
|
788
|
+
* @returns A Promise that resolves when the city is deleted.
|
|
789
|
+
*/
|
|
790
|
+
async deleteByState(countryCode, stateCode, cityName, params) {
|
|
791
|
+
await this.client.delete(`/countries/${countryCode}/states/${stateCode}/cities/${cityName}`, {
|
|
792
|
+
params
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Searches cities by name (autocomplete).
|
|
797
|
+
* @param query - The search query.
|
|
798
|
+
* @param options - Optional filters (countryCode, stateCode).
|
|
799
|
+
* @returns A Promise that resolves to a list of matching City entities.
|
|
800
|
+
*/
|
|
801
|
+
async search(query, options) {
|
|
802
|
+
const params = { q: query };
|
|
803
|
+
if (options?.countryCode) params.country_code = options.countryCode;
|
|
804
|
+
if (options?.stateCode) params.state_code = options.stateCode;
|
|
805
|
+
const res = await this.client.get("/cities/search", { params });
|
|
806
|
+
return res.data;
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
// src/feeef/repositories/currencies.ts
|
|
811
|
+
var CurrencyRepository = class extends ModelRepository {
|
|
812
|
+
/**
|
|
813
|
+
* Constructs a new CurrencyRepository instance.
|
|
814
|
+
* @param client The AxiosInstance used for making HTTP requests.
|
|
815
|
+
*/
|
|
816
|
+
constructor(client) {
|
|
817
|
+
super("currencies", client);
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Finds a currency by its code (ID is the currency code).
|
|
821
|
+
* @param code - The currency code (ISO 4217, e.g., USD, EUR).
|
|
822
|
+
* @param params - Optional query parameters.
|
|
823
|
+
* @returns A Promise that resolves to the found Currency entity.
|
|
824
|
+
*/
|
|
825
|
+
async findByCode(code, params) {
|
|
826
|
+
return this.find({ id: code.toUpperCase(), params });
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
// src/feeef/repositories/shipping_prices.ts
|
|
831
|
+
var ShippingPriceRepository = class extends ModelRepository {
|
|
832
|
+
/**
|
|
833
|
+
* Constructs a new ShippingPriceRepository instance.
|
|
834
|
+
* @param client The AxiosInstance used for making HTTP requests.
|
|
835
|
+
*/
|
|
836
|
+
constructor(client) {
|
|
837
|
+
super("shipping_prices", client);
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Creates a new ShippingPrice entity.
|
|
841
|
+
* @param options The options for creating the ShippingPrice entity.
|
|
842
|
+
* @returns A Promise that resolves to the created ShippingPrice entity.
|
|
843
|
+
*/
|
|
844
|
+
async create(options) {
|
|
845
|
+
const output = options.data;
|
|
846
|
+
return super.create({ ...options, data: output });
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Finds a ShippingPrice by store ID.
|
|
850
|
+
* @param storeId The store ID to search for.
|
|
851
|
+
* @returns A Promise that resolves to the ShippingPrice entities for the store.
|
|
852
|
+
*/
|
|
853
|
+
async listByStore(storeId) {
|
|
854
|
+
const response = await this.list({ params: { storeId } });
|
|
855
|
+
return response.data;
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
|
|
318
859
|
// src/core/entities/order.ts
|
|
319
860
|
var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
|
|
320
861
|
OrderStatus2["draft"] = "draft";
|
|
@@ -376,6 +917,44 @@ var ShippingMethodPolicy = /* @__PURE__ */ ((ShippingMethodPolicy2) => {
|
|
|
376
917
|
return ShippingMethodPolicy2;
|
|
377
918
|
})(ShippingMethodPolicy || {});
|
|
378
919
|
|
|
920
|
+
// src/core/entities/shipping_price.ts
|
|
921
|
+
var ShippingPriceStatus = /* @__PURE__ */ ((ShippingPriceStatus2) => {
|
|
922
|
+
ShippingPriceStatus2["draft"] = "draft";
|
|
923
|
+
ShippingPriceStatus2["published"] = "published";
|
|
924
|
+
return ShippingPriceStatus2;
|
|
925
|
+
})(ShippingPriceStatus || {});
|
|
926
|
+
function getShippingPrice(prices, countryCode, stateCode, type) {
|
|
927
|
+
const countryRates = prices[countryCode];
|
|
928
|
+
if (!countryRates) return null;
|
|
929
|
+
const stateRates = countryRates[stateCode];
|
|
930
|
+
if (!stateRates) return null;
|
|
931
|
+
return stateRates[type] ?? null;
|
|
932
|
+
}
|
|
933
|
+
function isShippingAvailable(prices, countryCode, stateCode) {
|
|
934
|
+
const countryRates = prices[countryCode];
|
|
935
|
+
if (!countryRates) return false;
|
|
936
|
+
const stateRates = countryRates[stateCode];
|
|
937
|
+
if (!stateRates) return false;
|
|
938
|
+
return stateRates.home !== null || stateRates.desk !== null || stateRates.pickup !== null;
|
|
939
|
+
}
|
|
940
|
+
function getAvailableShippingTypes(prices, countryCode, stateCode) {
|
|
941
|
+
const countryRates = prices[countryCode];
|
|
942
|
+
if (!countryRates) return [];
|
|
943
|
+
const stateRates = countryRates[stateCode];
|
|
944
|
+
if (!stateRates) return [];
|
|
945
|
+
const available = [];
|
|
946
|
+
if (stateRates.home !== null) {
|
|
947
|
+
available.push({ type: "home", price: stateRates.home });
|
|
948
|
+
}
|
|
949
|
+
if (stateRates.desk !== null) {
|
|
950
|
+
available.push({ type: "desk", price: stateRates.desk });
|
|
951
|
+
}
|
|
952
|
+
if (stateRates.pickup !== null) {
|
|
953
|
+
available.push({ type: "pickup", price: stateRates.pickup });
|
|
954
|
+
}
|
|
955
|
+
return available;
|
|
956
|
+
}
|
|
957
|
+
|
|
379
958
|
// src/feeef/services/service.ts
|
|
380
959
|
var NotifiableService = class {
|
|
381
960
|
// Array of listeners (functions) to notify when changes occur
|
|
@@ -422,6 +1001,10 @@ var CartService = class extends NotifiableService {
|
|
|
422
1001
|
items = [];
|
|
423
1002
|
// Array to support multiple items with same product but different variants
|
|
424
1003
|
shippingMethod = null;
|
|
1004
|
+
shippingPrice = null;
|
|
1005
|
+
// New shipping price system
|
|
1006
|
+
store = null;
|
|
1007
|
+
// Store entity for accessing shippingPriceId
|
|
425
1008
|
shippingAddress = {
|
|
426
1009
|
name: null,
|
|
427
1010
|
phone: null,
|
|
@@ -773,6 +1356,7 @@ var CartService = class extends NotifiableService {
|
|
|
773
1356
|
const store = method?.defaultShippingRates ? method : null;
|
|
774
1357
|
const shippingMethod = method?.rates ? method : null;
|
|
775
1358
|
if (store) {
|
|
1359
|
+
this.store = store;
|
|
776
1360
|
this.shippingMethod = {
|
|
777
1361
|
id: store.id,
|
|
778
1362
|
name: store.name,
|
|
@@ -804,25 +1388,231 @@ var CartService = class extends NotifiableService {
|
|
|
804
1388
|
throw new Error("Invalid shipping method");
|
|
805
1389
|
}
|
|
806
1390
|
}
|
|
807
|
-
// getAvailableShippingTypes
|
|
808
1391
|
/**
|
|
809
|
-
*
|
|
1392
|
+
* Sets the shipping price (new system).
|
|
1393
|
+
* @param shippingPrice - The shipping price entity.
|
|
1394
|
+
* @param notify - Whether to notify listeners.
|
|
1395
|
+
*/
|
|
1396
|
+
setShippingPrice(shippingPrice, notify = true) {
|
|
1397
|
+
this.shippingPrice = shippingPrice;
|
|
1398
|
+
if (notify) {
|
|
1399
|
+
this.notify();
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Sets the store entity.
|
|
1404
|
+
* @param store - The store entity.
|
|
1405
|
+
* @param notify - Whether to notify listeners.
|
|
1406
|
+
*/
|
|
1407
|
+
setStore(store, notify = true) {
|
|
1408
|
+
this.store = store;
|
|
1409
|
+
if (notify) {
|
|
1410
|
+
this.notify();
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* Maps ShippingType enum to ShippingPriceType string.
|
|
1415
|
+
* @param shippingType - The shipping type enum.
|
|
1416
|
+
* @returns The corresponding shipping price type.
|
|
1417
|
+
*/
|
|
1418
|
+
mapShippingTypeToPriceType(shippingType) {
|
|
1419
|
+
switch (shippingType) {
|
|
1420
|
+
case "home" /* home */:
|
|
1421
|
+
return "home";
|
|
1422
|
+
case "pickup" /* pickup */:
|
|
1423
|
+
return "pickup";
|
|
1424
|
+
case "store" /* store */:
|
|
1425
|
+
return "desk";
|
|
1426
|
+
default:
|
|
1427
|
+
return "home";
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* Resolves shipping price using the priority chain.
|
|
1432
|
+
* Priority: 1. Product shippingPriceId, 2. Store shippingPriceId, 3. Product shippingMethodId, 4. Store defaultShippingRates
|
|
810
1433
|
*
|
|
811
|
-
*
|
|
812
|
-
*
|
|
813
|
-
*
|
|
1434
|
+
* Note: Shipping prices must be loaded and set via setShippingPrice() for the new system to work.
|
|
1435
|
+
* If shipping prices are not loaded, the method falls back to the legacy system.
|
|
1436
|
+
*
|
|
1437
|
+
* @param countryCode - ISO 3166-1 alpha-2 country code (optional, required for new system)
|
|
1438
|
+
* @param stateCode - State/province code
|
|
1439
|
+
* @param shippingType - The shipping type
|
|
1440
|
+
* @returns The shipping price or null if not available
|
|
1441
|
+
*/
|
|
1442
|
+
resolveShippingPrice(countryCode, stateCode, shippingType) {
|
|
1443
|
+
if (!stateCode) return null;
|
|
1444
|
+
const priceType = this.mapShippingTypeToPriceType(shippingType);
|
|
1445
|
+
const allProducts = [...this.items];
|
|
1446
|
+
if (this.currentItem && !this.hasItem(this.currentItem)) {
|
|
1447
|
+
allProducts.push(this.currentItem);
|
|
1448
|
+
}
|
|
1449
|
+
console.log("[resolveShippingPrice]", {
|
|
1450
|
+
countryCode,
|
|
1451
|
+
stateCode,
|
|
1452
|
+
shippingType,
|
|
1453
|
+
priceType,
|
|
1454
|
+
hasShippingPrice: !!this.shippingPrice,
|
|
1455
|
+
shippingPriceId: this.shippingPrice?.id,
|
|
1456
|
+
allProductsCount: allProducts.length
|
|
1457
|
+
});
|
|
1458
|
+
if (countryCode && this.shippingPrice) {
|
|
1459
|
+
const productShippingPriceIds = allProducts.map((item) => item.product.shippingPriceId).filter((id) => id !== null);
|
|
1460
|
+
console.log("[resolveShippingPrice] Product shippingPriceIds:", productShippingPriceIds);
|
|
1461
|
+
if (productShippingPriceIds.length > 0) {
|
|
1462
|
+
const uniqueIds = new Set(productShippingPriceIds);
|
|
1463
|
+
if (uniqueIds.size === 1 && this.shippingPrice.id === productShippingPriceIds[0]) {
|
|
1464
|
+
console.log(
|
|
1465
|
+
"[resolveShippingPrice] Using product shippingPriceId:",
|
|
1466
|
+
productShippingPriceIds[0]
|
|
1467
|
+
);
|
|
1468
|
+
const price = getShippingPrice(
|
|
1469
|
+
this.shippingPrice.prices,
|
|
1470
|
+
countryCode,
|
|
1471
|
+
stateCode,
|
|
1472
|
+
priceType
|
|
1473
|
+
);
|
|
1474
|
+
console.log("[resolveShippingPrice] Product price result:", price);
|
|
1475
|
+
if (price !== null) {
|
|
1476
|
+
return price;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
if (countryCode && this.store?.shippingPriceId && this.shippingPrice && this.shippingPrice.id === this.store.shippingPriceId) {
|
|
1482
|
+
console.log("[resolveShippingPrice] Using store shippingPriceId:", this.store.shippingPriceId);
|
|
1483
|
+
const price = getShippingPrice(
|
|
1484
|
+
this.shippingPrice.prices,
|
|
1485
|
+
countryCode,
|
|
1486
|
+
stateCode,
|
|
1487
|
+
priceType
|
|
1488
|
+
);
|
|
1489
|
+
console.log("[resolveShippingPrice] Store price result:", price);
|
|
1490
|
+
if (price !== null) {
|
|
1491
|
+
return price;
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
const productShippingMethodIds = allProducts.map((item) => item.product.shippingMethodId).filter((id) => id !== null);
|
|
1495
|
+
if (productShippingMethodIds.length > 0) {
|
|
1496
|
+
const uniqueIds = new Set(productShippingMethodIds);
|
|
1497
|
+
if (uniqueIds.size === 1 && this.shippingMethod && this.shippingMethod.id === productShippingMethodIds[0]) {
|
|
1498
|
+
const legacyPrice = this.getShippingPriceForTypeLegacy(shippingType);
|
|
1499
|
+
if (legacyPrice !== null) {
|
|
1500
|
+
return legacyPrice;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
if (this.shippingMethod?.rates) {
|
|
1505
|
+
console.log("[resolveShippingPrice] Falling back to legacy system");
|
|
1506
|
+
const legacyPrice = this.getShippingPriceForTypeLegacy(shippingType);
|
|
1507
|
+
console.log("[resolveShippingPrice] Legacy price result:", legacyPrice);
|
|
1508
|
+
return legacyPrice;
|
|
1509
|
+
}
|
|
1510
|
+
console.log("[resolveShippingPrice] No shipping price found, returning null");
|
|
1511
|
+
return null;
|
|
1512
|
+
}
|
|
1513
|
+
/**
|
|
1514
|
+
* Gets shipping price using legacy system (array-based rates).
|
|
1515
|
+
* @param type - The shipping type
|
|
1516
|
+
* @returns The shipping price or null if not available
|
|
1517
|
+
*/
|
|
1518
|
+
getShippingPriceForTypeLegacy(type) {
|
|
1519
|
+
if (!this.shippingMethod?.rates || !this.shippingAddress.state) return null;
|
|
1520
|
+
const stateIndex = Number.parseInt(this.shippingAddress.state, 10) - 1;
|
|
1521
|
+
const rates = this.shippingMethod.rates[stateIndex];
|
|
1522
|
+
if (!rates) return null;
|
|
1523
|
+
switch (type) {
|
|
1524
|
+
case "pickup" /* pickup */:
|
|
1525
|
+
return rates[0];
|
|
1526
|
+
case "home" /* home */:
|
|
1527
|
+
return rates[1];
|
|
1528
|
+
case "store" /* store */:
|
|
1529
|
+
return rates[2];
|
|
1530
|
+
default:
|
|
1531
|
+
return null;
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Retrieves the available shipping types using the priority chain.
|
|
1536
|
+
* Priority: 1. Product shippingPriceId, 2. Store shippingPriceId, 3. Product shippingMethodId, 4. Store defaultShippingRates
|
|
1537
|
+
*
|
|
1538
|
+
* Note: Shipping prices must be loaded and set via setShippingPrice() for the new system to work.
|
|
1539
|
+
* If shipping prices are not loaded, the method falls back to the legacy system.
|
|
814
1540
|
*
|
|
815
1541
|
* @returns An array of available shipping types.
|
|
816
1542
|
*/
|
|
817
1543
|
getAvailableShippingTypes() {
|
|
1544
|
+
if (!this.shippingAddress.state) return [];
|
|
1545
|
+
let countryCode;
|
|
1546
|
+
if (this.shippingAddress.country && this.shippingAddress.country.toLowerCase() !== "dz") {
|
|
1547
|
+
countryCode = this.shippingAddress.country.toUpperCase();
|
|
1548
|
+
} else if (this.store?.configs?.selectedCountry) {
|
|
1549
|
+
countryCode = this.store.configs.selectedCountry.toUpperCase();
|
|
1550
|
+
} else {
|
|
1551
|
+
countryCode = void 0;
|
|
1552
|
+
}
|
|
1553
|
+
const allProducts = [...this.items];
|
|
1554
|
+
if (this.currentItem && !this.hasItem(this.currentItem)) {
|
|
1555
|
+
allProducts.push(this.currentItem);
|
|
1556
|
+
}
|
|
1557
|
+
if (countryCode && this.shippingPrice) {
|
|
1558
|
+
const productShippingPriceIds = allProducts.map((item) => item.product.shippingPriceId).filter((id) => id !== null);
|
|
1559
|
+
if (productShippingPriceIds.length > 0) {
|
|
1560
|
+
const uniqueIds = new Set(productShippingPriceIds);
|
|
1561
|
+
if (uniqueIds.size === 1 && this.shippingPrice.id === productShippingPriceIds[0]) {
|
|
1562
|
+
const available = getAvailableShippingTypes(
|
|
1563
|
+
this.shippingPrice.prices,
|
|
1564
|
+
countryCode,
|
|
1565
|
+
this.shippingAddress.state
|
|
1566
|
+
);
|
|
1567
|
+
if (available.length > 0) {
|
|
1568
|
+
return available.map((a) => {
|
|
1569
|
+
switch (a.type) {
|
|
1570
|
+
case "home":
|
|
1571
|
+
return "home" /* home */;
|
|
1572
|
+
case "pickup":
|
|
1573
|
+
return "pickup" /* pickup */;
|
|
1574
|
+
case "desk":
|
|
1575
|
+
return "store" /* store */;
|
|
1576
|
+
default:
|
|
1577
|
+
return "home" /* home */;
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
if (countryCode && this.store?.shippingPriceId && this.shippingPrice && this.shippingPrice.id === this.store.shippingPriceId) {
|
|
1585
|
+
const available = getAvailableShippingTypes(
|
|
1586
|
+
this.shippingPrice.prices,
|
|
1587
|
+
countryCode,
|
|
1588
|
+
this.shippingAddress.state
|
|
1589
|
+
);
|
|
1590
|
+
if (available.length > 0) {
|
|
1591
|
+
return available.map((a) => {
|
|
1592
|
+
switch (a.type) {
|
|
1593
|
+
case "home":
|
|
1594
|
+
return "home" /* home */;
|
|
1595
|
+
case "pickup":
|
|
1596
|
+
return "pickup" /* pickup */;
|
|
1597
|
+
case "desk":
|
|
1598
|
+
return "store" /* store */;
|
|
1599
|
+
default:
|
|
1600
|
+
return "home" /* home */;
|
|
1601
|
+
}
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
818
1605
|
if (!this.shippingMethod?.rates) return [];
|
|
819
|
-
|
|
820
|
-
|
|
1606
|
+
const state = Number.parseInt(this.shippingAddress.state, 10);
|
|
1607
|
+
const stateRates = this.shippingMethod.rates[state - 1];
|
|
821
1608
|
if (!stateRates) return [];
|
|
822
|
-
|
|
823
|
-
if (stateRates[0]
|
|
824
|
-
|
|
825
|
-
if (stateRates[
|
|
1609
|
+
const availableTypes = [];
|
|
1610
|
+
if (stateRates[0] !== null && stateRates[0] !== void 0)
|
|
1611
|
+
availableTypes.push("pickup" /* pickup */);
|
|
1612
|
+
if (stateRates[1] !== null && stateRates[1] !== void 0)
|
|
1613
|
+
availableTypes.push("home" /* home */);
|
|
1614
|
+
if (stateRates[2] !== null && stateRates[2] !== void 0)
|
|
1615
|
+
availableTypes.push("store" /* store */);
|
|
826
1616
|
return availableTypes;
|
|
827
1617
|
}
|
|
828
1618
|
/**
|
|
@@ -856,43 +1646,71 @@ var CartService = class extends NotifiableService {
|
|
|
856
1646
|
* @returns The shipping price or 0 if not applicable.
|
|
857
1647
|
*/
|
|
858
1648
|
getShippingPrice() {
|
|
859
|
-
|
|
1649
|
+
const allItems = [...this.items];
|
|
1650
|
+
if (this.currentItem && !this.hasItem(this.currentItem)) {
|
|
1651
|
+
allItems.push(this.currentItem);
|
|
1652
|
+
}
|
|
1653
|
+
for (const item of allItems) {
|
|
860
1654
|
if (item.offer?.freeShipping) return 0;
|
|
861
1655
|
}
|
|
862
1656
|
if (!this.shippingMethod) return 0;
|
|
863
1657
|
if (!this.shippingAddress.state) return this.shippingMethod.price ?? 0;
|
|
864
1658
|
const shippings = this.getAvailableShippingTypes();
|
|
865
1659
|
const currentOne = this.getShippingPriceForType(this.shippingAddress.type);
|
|
866
|
-
if (currentOne) {
|
|
1660
|
+
if (currentOne !== null) {
|
|
867
1661
|
return currentOne;
|
|
868
1662
|
}
|
|
869
1663
|
for (const type of shippings) {
|
|
870
|
-
|
|
871
|
-
|
|
1664
|
+
const price = this.getShippingPriceForType(type);
|
|
1665
|
+
if (price !== null) {
|
|
1666
|
+
return price;
|
|
872
1667
|
}
|
|
873
1668
|
}
|
|
874
1669
|
return 0;
|
|
875
1670
|
}
|
|
876
1671
|
/**
|
|
877
|
-
* Gets the shipping price for a specific shipping type using the
|
|
1672
|
+
* Gets the shipping price for a specific shipping type using the priority chain.
|
|
1673
|
+
* Priority: 1. Product shippingPriceId, 2. Store shippingPriceId, 3. Product shippingMethodId, 4. Store defaultShippingRates
|
|
878
1674
|
* @param type - The shipping type to check (pickup, home, store)
|
|
879
1675
|
* @returns The shipping price for the specified type, or null if not available
|
|
880
1676
|
*/
|
|
881
1677
|
getShippingPriceForType(type) {
|
|
882
|
-
if (!this.
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
default:
|
|
894
|
-
return null;
|
|
1678
|
+
if (!this.shippingAddress.state) {
|
|
1679
|
+
console.log("[getShippingPriceForType] No state, returning null");
|
|
1680
|
+
return null;
|
|
1681
|
+
}
|
|
1682
|
+
let countryCode;
|
|
1683
|
+
if (this.shippingAddress.country && this.shippingAddress.country.toLowerCase() !== "dz") {
|
|
1684
|
+
countryCode = this.shippingAddress.country.toUpperCase();
|
|
1685
|
+
} else if (this.store?.configs?.selectedCountry) {
|
|
1686
|
+
countryCode = this.store.configs.selectedCountry.toUpperCase();
|
|
1687
|
+
} else {
|
|
1688
|
+
countryCode = void 0;
|
|
895
1689
|
}
|
|
1690
|
+
console.log("[getShippingPriceForType]", {
|
|
1691
|
+
type,
|
|
1692
|
+
state: this.shippingAddress.state,
|
|
1693
|
+
country: this.shippingAddress.country,
|
|
1694
|
+
countryCode,
|
|
1695
|
+
storeSelectedCountry: this.store?.configs?.selectedCountry,
|
|
1696
|
+
hasShippingPrice: !!this.shippingPrice,
|
|
1697
|
+
shippingPriceId: this.shippingPrice?.id
|
|
1698
|
+
});
|
|
1699
|
+
if (countryCode) {
|
|
1700
|
+
const newSystemPrice = this.resolveShippingPrice(
|
|
1701
|
+
countryCode,
|
|
1702
|
+
this.shippingAddress.state,
|
|
1703
|
+
type
|
|
1704
|
+
);
|
|
1705
|
+
if (newSystemPrice !== null) {
|
|
1706
|
+
console.log("[getShippingPriceForType] New system price:", newSystemPrice);
|
|
1707
|
+
return newSystemPrice;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
console.log("[getShippingPriceForType] Falling back to legacy system");
|
|
1711
|
+
const legacyPrice = this.getShippingPriceForTypeLegacy(type);
|
|
1712
|
+
console.log("[getShippingPriceForType] Legacy price:", legacyPrice);
|
|
1713
|
+
return legacyPrice;
|
|
896
1714
|
}
|
|
897
1715
|
/**
|
|
898
1716
|
* Calculates the total cost of the cart including shipping.
|
|
@@ -1007,10 +1825,34 @@ var FeeeF = class {
|
|
|
1007
1825
|
* The repository for managing deposits.
|
|
1008
1826
|
*/
|
|
1009
1827
|
deposits;
|
|
1828
|
+
/**
|
|
1829
|
+
* The repository for managing transfers.
|
|
1830
|
+
*/
|
|
1831
|
+
transfers;
|
|
1010
1832
|
/**
|
|
1011
1833
|
* The repository for managing categories.
|
|
1012
1834
|
*/
|
|
1013
1835
|
categories;
|
|
1836
|
+
/**
|
|
1837
|
+
* The repository for managing countries.
|
|
1838
|
+
*/
|
|
1839
|
+
countries;
|
|
1840
|
+
/**
|
|
1841
|
+
* The repository for managing states.
|
|
1842
|
+
*/
|
|
1843
|
+
states;
|
|
1844
|
+
/**
|
|
1845
|
+
* The repository for managing cities.
|
|
1846
|
+
*/
|
|
1847
|
+
cities;
|
|
1848
|
+
/**
|
|
1849
|
+
* The repository for managing currencies.
|
|
1850
|
+
*/
|
|
1851
|
+
currencies;
|
|
1852
|
+
/**
|
|
1853
|
+
* The repository for managing shipping prices.
|
|
1854
|
+
*/
|
|
1855
|
+
shippingPrices;
|
|
1014
1856
|
/**
|
|
1015
1857
|
* The cart service for managing the cart.
|
|
1016
1858
|
*/
|
|
@@ -1038,7 +1880,13 @@ var FeeeF = class {
|
|
|
1038
1880
|
this.users = new UserRepository(this.client);
|
|
1039
1881
|
this.orders = new OrderRepository(this.client);
|
|
1040
1882
|
this.deposits = new DepositRepository(this.client);
|
|
1883
|
+
this.transfers = new TransferRepository(this.client);
|
|
1041
1884
|
this.categories = new CategoryRepository(this.client);
|
|
1885
|
+
this.countries = new CountryRepository(this.client);
|
|
1886
|
+
this.states = new StateRepository(this.client);
|
|
1887
|
+
this.cities = new CityRepository(this.client);
|
|
1888
|
+
this.currencies = new CurrencyRepository(this.client);
|
|
1889
|
+
this.shippingPrices = new ShippingPriceRepository(this.client);
|
|
1042
1890
|
this.cart = new CartService();
|
|
1043
1891
|
this.actions = new ActionsService(this.client);
|
|
1044
1892
|
}
|
|
@@ -1413,12 +2261,16 @@ export {
|
|
|
1413
2261
|
ProductVariantView,
|
|
1414
2262
|
ShippingMethodPolicy,
|
|
1415
2263
|
ShippingMethodStatus,
|
|
2264
|
+
ShippingPriceRepository,
|
|
2265
|
+
ShippingPriceStatus,
|
|
1416
2266
|
ShippingType,
|
|
1417
2267
|
StoreActionType,
|
|
1418
2268
|
StoreMemberRole,
|
|
1419
2269
|
StoreSubscriptionStatus,
|
|
1420
2270
|
StoreSubscriptionType,
|
|
1421
2271
|
TiktokPixelEvent,
|
|
2272
|
+
TransferRepository,
|
|
2273
|
+
UserRepository,
|
|
1422
2274
|
VariantOptionType,
|
|
1423
2275
|
WebhookEvent,
|
|
1424
2276
|
convertDartColorToCssNumber,
|
|
@@ -1441,6 +2293,9 @@ export {
|
|
|
1441
2293
|
generatePublicStoreIntegrationTiktokPixel,
|
|
1442
2294
|
generatePublicStoreIntegrationWebhooks,
|
|
1443
2295
|
generatePublicStoreIntegrations,
|
|
2296
|
+
getAvailableShippingTypes,
|
|
2297
|
+
getShippingPrice,
|
|
2298
|
+
isShippingAvailable,
|
|
1444
2299
|
tryFixPhoneNumber,
|
|
1445
2300
|
validatePhoneNumber
|
|
1446
2301
|
};
|