@bacano/sdk 1.2.6 → 1.2.8
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/CATALOG_MANAGEMENT.md +261 -0
- package/CONTENT_ICONS.md +113 -0
- package/CONTENT_TYPE_MANAGEMENT.md +8 -2
- package/README.md +15 -5
- package/STOREFRONT_FORMS.md +38 -0
- package/STOREFRONT_LEADS.md +5 -1
- package/STOREFRONT_PAYMENTS.md +57 -2
- package/STOREFRONT_PERFORMANCE.md +35 -0
- package/catalog-draft-types.d.ts +145 -0
- package/catalog-management-types.d.ts +143 -0
- package/catalog-management.cjs +125 -0
- package/catalog-management.d.ts +37 -0
- package/catalog-management.js +104 -0
- package/content-management-types.d.ts +9 -1
- package/icons.cjs +5515 -0
- package/icons.d.ts +20 -0
- package/icons.js +5496 -0
- package/index.cjs +153 -63
- package/index.js +153 -63
- package/modules/checkout-contact.d.ts +4 -0
- package/package.json +16 -1
- package/react/icon.cjs +5555 -0
- package/react/icon.d.ts +10 -0
- package/react/icon.js +5534 -0
- package/react.cjs +153 -63
- package/react.js +153 -63
- package/skills/bacano-web/SKILL.md +10 -3
- package/skills/bacano-web/references/common.md +18 -0
- package/skills/bacano-web/references/forms.md +2 -0
- package/skills/bacano-web/references/storefront.md +20 -0
- package/skills/bacano-web/scripts/cli.mjs +28 -5
package/index.cjs
CHANGED
|
@@ -3338,6 +3338,78 @@ function hasRecoverableCartSessionError(errors) {
|
|
|
3338
3338
|
);
|
|
3339
3339
|
}
|
|
3340
3340
|
|
|
3341
|
+
// libs/sdk/src/modules/checkout-contact.ts
|
|
3342
|
+
var EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
3343
|
+
var PHONE_PATTERN = /^\+?\d{7,15}$/;
|
|
3344
|
+
function validEmail(value) {
|
|
3345
|
+
if (value.length > 320 || !EMAIL_PATTERN.test(value)) return false;
|
|
3346
|
+
const [local, domain] = value.split("@");
|
|
3347
|
+
if (!local || !domain || local.length > 64 || domain.length > 255 || local.startsWith(".") || local.endsWith(".") || local.includes("..")) {
|
|
3348
|
+
return false;
|
|
3349
|
+
}
|
|
3350
|
+
return domain.split(".").every((label) => /^[a-z\d](?:[a-z\d-]*[a-z\d])?$/i.test(label));
|
|
3351
|
+
}
|
|
3352
|
+
function normalizePhone(value) {
|
|
3353
|
+
return value.trim().replace(/[\s().-]/g, "");
|
|
3354
|
+
}
|
|
3355
|
+
function invalidContact(field) {
|
|
3356
|
+
const messages = {
|
|
3357
|
+
email: "Revisa el correo electr\xF3nico: debe estar completo y sin espacios.",
|
|
3358
|
+
phone: "Revisa el n\xFAmero de tel\xE9fono: usa entre 7 y 15 d\xEDgitos.",
|
|
3359
|
+
contact: "Ingresa un correo electr\xF3nico o un n\xFAmero de tel\xE9fono v\xE1lido."
|
|
3360
|
+
};
|
|
3361
|
+
return new WebsiteError(
|
|
3362
|
+
messages[field],
|
|
3363
|
+
`INVALID_CHECKOUT_${field.toUpperCase()}`
|
|
3364
|
+
);
|
|
3365
|
+
}
|
|
3366
|
+
function normalizeCheckoutContact(contact, mode) {
|
|
3367
|
+
const email = contact.email?.trim() || void 0;
|
|
3368
|
+
const phone = contact.phone ? normalizePhone(contact.phone) : void 0;
|
|
3369
|
+
const cellphone = contact.cellphone ? normalizePhone(contact.cellphone) : void 0;
|
|
3370
|
+
const emailValid = !email || validEmail(email);
|
|
3371
|
+
const phoneValid = !phone || PHONE_PATTERN.test(phone);
|
|
3372
|
+
const cellphoneValid = !cellphone || PHONE_PATTERN.test(cellphone);
|
|
3373
|
+
if (mode === "submit") {
|
|
3374
|
+
if (!emailValid) throw invalidContact("email");
|
|
3375
|
+
if (!phoneValid || !cellphoneValid) throw invalidContact("phone");
|
|
3376
|
+
}
|
|
3377
|
+
const normalized = {
|
|
3378
|
+
...contact,
|
|
3379
|
+
name: contact.name?.trim() || void 0,
|
|
3380
|
+
firstName: contact.firstName?.trim() || void 0,
|
|
3381
|
+
lastName: contact.lastName?.trim() || void 0,
|
|
3382
|
+
email: emailValid ? email : void 0,
|
|
3383
|
+
phone: phoneValid ? phone : void 0,
|
|
3384
|
+
cellphone: cellphoneValid ? cellphone : void 0
|
|
3385
|
+
};
|
|
3386
|
+
if ((normalized.name?.length ?? 0) > 160 || (normalized.firstName?.length ?? 0) > 80 || (normalized.lastName?.length ?? 0) > 80) {
|
|
3387
|
+
throw new WebsiteError(
|
|
3388
|
+
"Revisa los datos de contacto: el nombre es demasiado largo.",
|
|
3389
|
+
"INVALID_CHECKOUT_CONTACT"
|
|
3390
|
+
);
|
|
3391
|
+
}
|
|
3392
|
+
if (!normalized.email && !normalized.phone && !normalized.cellphone) {
|
|
3393
|
+
throw invalidContact(
|
|
3394
|
+
!emailValid ? "email" : !phoneValid || !cellphoneValid ? "phone" : "contact"
|
|
3395
|
+
);
|
|
3396
|
+
}
|
|
3397
|
+
return normalized;
|
|
3398
|
+
}
|
|
3399
|
+
function explainCheckoutRequestError(error) {
|
|
3400
|
+
if (error instanceof GraphQLRequestError && error.graphqlErrors.some(
|
|
3401
|
+
(item) => /invalid request payload|hay un error en los datos del pedido/i.test(
|
|
3402
|
+
item.message
|
|
3403
|
+
)
|
|
3404
|
+
)) {
|
|
3405
|
+
throw new WebsiteError(
|
|
3406
|
+
"Hay un error en los datos del pedido. Rev\xEDsalos e intenta de nuevo.",
|
|
3407
|
+
"INVALID_CHECKOUT_DATA"
|
|
3408
|
+
);
|
|
3409
|
+
}
|
|
3410
|
+
throw error;
|
|
3411
|
+
}
|
|
3412
|
+
|
|
3341
3413
|
// libs/sdk/src/modules/cart.ts
|
|
3342
3414
|
function mapCartItem(raw) {
|
|
3343
3415
|
return {
|
|
@@ -3413,6 +3485,15 @@ function requireCartSession(storage) {
|
|
|
3413
3485
|
return session;
|
|
3414
3486
|
}
|
|
3415
3487
|
function createCartModule(graphqlUrl, getHeaders, getContext, cartSessionStorage) {
|
|
3488
|
+
let pendingCartSessionOperation = Promise.resolve();
|
|
3489
|
+
function enqueueCartSessionOperation(run) {
|
|
3490
|
+
const operation = pendingCartSessionOperation.then(run, run);
|
|
3491
|
+
pendingCartSessionOperation = operation.then(
|
|
3492
|
+
() => void 0,
|
|
3493
|
+
() => void 0
|
|
3494
|
+
);
|
|
3495
|
+
return operation;
|
|
3496
|
+
}
|
|
3416
3497
|
async function fetchCart(orderId, cartToken) {
|
|
3417
3498
|
const data = await executeGraphQL(graphqlUrl, GET_CART, { orderId, cartToken }, getHeaders);
|
|
3418
3499
|
const result = data.websiteGetCart;
|
|
@@ -3435,72 +3516,80 @@ function createCartModule(graphqlUrl, getHeaders, getContext, cartSessionStorage
|
|
|
3435
3516
|
}
|
|
3436
3517
|
return {
|
|
3437
3518
|
async getOrCreate(contact, fulfillmentFamily) {
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
CREATE_CART,
|
|
3449
|
-
{
|
|
3450
|
-
websiteId: ctx.websiteId,
|
|
3451
|
-
cartToken: existing?.cartToken,
|
|
3452
|
-
contact,
|
|
3453
|
-
fulfillmentFamily
|
|
3454
|
-
},
|
|
3455
|
-
getHeaders
|
|
3456
|
-
);
|
|
3457
|
-
const result = data.websiteCreateCart;
|
|
3458
|
-
assertActionSuccess(result, "CART_CREATE_ERROR");
|
|
3459
|
-
cartSessionStorage.set({
|
|
3460
|
-
orderId: result.order_id,
|
|
3461
|
-
cartToken: result.cart_token
|
|
3462
|
-
});
|
|
3463
|
-
return mapCart(result.cart, result.cart_token);
|
|
3464
|
-
},
|
|
3465
|
-
async startCheckout(input) {
|
|
3466
|
-
const ctx = getContext();
|
|
3467
|
-
if (!ctx.chainId) {
|
|
3468
|
-
throw new WebsiteError(
|
|
3469
|
-
"This website has no chain configured. Checkout requires a chain_id.",
|
|
3470
|
-
"NO_CHAIN"
|
|
3471
|
-
);
|
|
3472
|
-
}
|
|
3473
|
-
const requestStartCheckout = async (cartToken) => {
|
|
3519
|
+
return enqueueCartSessionOperation(async () => {
|
|
3520
|
+
const normalizedContact = contact ? normalizeCheckoutContact(contact, "draft") : void 0;
|
|
3521
|
+
const ctx = getContext();
|
|
3522
|
+
if (!ctx.chainId) {
|
|
3523
|
+
throw new WebsiteError(
|
|
3524
|
+
"This website has no chain configured. Cart requires a chain_id.",
|
|
3525
|
+
"NO_CHAIN"
|
|
3526
|
+
);
|
|
3527
|
+
}
|
|
3528
|
+
const existing = cartSessionStorage.get();
|
|
3474
3529
|
const data = await executeGraphQL(
|
|
3475
3530
|
graphqlUrl,
|
|
3476
|
-
|
|
3531
|
+
CREATE_CART,
|
|
3477
3532
|
{
|
|
3478
3533
|
websiteId: ctx.websiteId,
|
|
3479
|
-
cartToken,
|
|
3480
|
-
contact:
|
|
3481
|
-
fulfillmentFamily
|
|
3482
|
-
items: input.items.map((item) => ({
|
|
3483
|
-
product_variant_id: item.productVariantId,
|
|
3484
|
-
quantity: item.quantity
|
|
3485
|
-
})),
|
|
3486
|
-
marketingAttribution: input.marketingAttribution ? serializeWebsiteMarketingAttribution(input.marketingAttribution) : void 0
|
|
3534
|
+
cartToken: existing?.cartToken,
|
|
3535
|
+
contact: normalizedContact,
|
|
3536
|
+
fulfillmentFamily
|
|
3487
3537
|
},
|
|
3488
3538
|
getHeaders
|
|
3489
|
-
);
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
result
|
|
3497
|
-
}
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3539
|
+
).catch(explainCheckoutRequestError);
|
|
3540
|
+
const result = data.websiteCreateCart;
|
|
3541
|
+
assertActionSuccess(result, "CART_CREATE_ERROR");
|
|
3542
|
+
cartSessionStorage.set({
|
|
3543
|
+
orderId: result.order_id,
|
|
3544
|
+
cartToken: result.cart_token
|
|
3545
|
+
});
|
|
3546
|
+
return mapCart(result.cart, result.cart_token);
|
|
3547
|
+
});
|
|
3548
|
+
},
|
|
3549
|
+
async startCheckout(input) {
|
|
3550
|
+
return enqueueCartSessionOperation(async () => {
|
|
3551
|
+
const contact = normalizeCheckoutContact(input.contact, "draft");
|
|
3552
|
+
const ctx = getContext();
|
|
3553
|
+
if (!ctx.chainId) {
|
|
3554
|
+
throw new WebsiteError(
|
|
3555
|
+
"This website has no chain configured. Checkout requires a chain_id.",
|
|
3556
|
+
"NO_CHAIN"
|
|
3557
|
+
);
|
|
3558
|
+
}
|
|
3559
|
+
const requestStartCheckout = async (cartToken) => {
|
|
3560
|
+
const data = await executeGraphQL(
|
|
3561
|
+
graphqlUrl,
|
|
3562
|
+
START_GUEST_CHECKOUT,
|
|
3563
|
+
{
|
|
3564
|
+
websiteId: ctx.websiteId,
|
|
3565
|
+
cartToken,
|
|
3566
|
+
contact,
|
|
3567
|
+
fulfillmentFamily: input.fulfillmentFamily,
|
|
3568
|
+
items: input.items.map((item) => ({
|
|
3569
|
+
product_variant_id: item.productVariantId,
|
|
3570
|
+
quantity: item.quantity
|
|
3571
|
+
})),
|
|
3572
|
+
marketingAttribution: input.marketingAttribution ? serializeWebsiteMarketingAttribution(
|
|
3573
|
+
input.marketingAttribution
|
|
3574
|
+
) : void 0
|
|
3575
|
+
},
|
|
3576
|
+
getHeaders
|
|
3577
|
+
).catch(explainCheckoutRequestError);
|
|
3578
|
+
return data.websiteStartGuestCheckout;
|
|
3579
|
+
};
|
|
3580
|
+
const existing = cartSessionStorage.get();
|
|
3581
|
+
let result = await requestStartCheckout(existing?.cartToken);
|
|
3582
|
+
if (existing && !result.success && hasRecoverableCartSessionError(result.errors)) {
|
|
3583
|
+
cartSessionStorage.clear();
|
|
3584
|
+
result = await requestStartCheckout();
|
|
3585
|
+
}
|
|
3586
|
+
assertActionSuccess(result, "CHECKOUT_START_ERROR");
|
|
3587
|
+
cartSessionStorage.set({
|
|
3588
|
+
orderId: result.order_id,
|
|
3589
|
+
cartToken: result.cart_token
|
|
3590
|
+
});
|
|
3591
|
+
return mapCart(result.cart, result.cart_token);
|
|
3502
3592
|
});
|
|
3503
|
-
return mapCart(result.cart, result.cart_token);
|
|
3504
3593
|
},
|
|
3505
3594
|
async get() {
|
|
3506
3595
|
const session = cartSessionStorage.get();
|
|
@@ -5599,6 +5688,7 @@ function createCheckoutModule(graphqlUrl, getHeaders, getContext, cartSessionSto
|
|
|
5599
5688
|
return mapCouponResult(data.websiteRemoveCoupon);
|
|
5600
5689
|
},
|
|
5601
5690
|
async submit(input) {
|
|
5691
|
+
const contact = normalizeCheckoutContact(input.contact, "submit");
|
|
5602
5692
|
const session = requireCartSession2(cartSessionStorage);
|
|
5603
5693
|
const data = await executeGraphQL(
|
|
5604
5694
|
graphqlUrl,
|
|
@@ -5606,7 +5696,7 @@ function createCheckoutModule(graphqlUrl, getHeaders, getContext, cartSessionSto
|
|
|
5606
5696
|
{
|
|
5607
5697
|
orderId: session.orderId,
|
|
5608
5698
|
cartToken: session.cartToken,
|
|
5609
|
-
contact
|
|
5699
|
+
contact,
|
|
5610
5700
|
fulfillmentFamily: input.fulfillmentFamily,
|
|
5611
5701
|
address: input.address,
|
|
5612
5702
|
shippingQuoteId: input.shippingQuoteId,
|
|
@@ -5626,7 +5716,7 @@ function createCheckoutModule(graphqlUrl, getHeaders, getContext, cartSessionSto
|
|
|
5626
5716
|
} : void 0
|
|
5627
5717
|
},
|
|
5628
5718
|
getHeaders
|
|
5629
|
-
);
|
|
5719
|
+
).catch(explainCheckoutRequestError);
|
|
5630
5720
|
const result = data.websiteCheckout;
|
|
5631
5721
|
if (!result.success && result.errors && result.errors.length > 0) {
|
|
5632
5722
|
throw new CheckoutError(result.errors);
|
|
@@ -5667,7 +5757,7 @@ function createCheckoutModule(graphqlUrl, getHeaders, getContext, cartSessionSto
|
|
|
5667
5757
|
returnUrl: input.returnUrl
|
|
5668
5758
|
},
|
|
5669
5759
|
getHeaders
|
|
5670
|
-
);
|
|
5760
|
+
).catch(explainCheckoutRequestError);
|
|
5671
5761
|
const result = data.websiteCreatePaymentSession;
|
|
5672
5762
|
if (result.success && result.payment_session_id && (result.integration_mode !== "redirect" || !result.redirect_url)) {
|
|
5673
5763
|
throw new WebsiteError(
|
|
@@ -5702,7 +5792,7 @@ function createCheckoutModule(graphqlUrl, getHeaders, getContext, cartSessionSto
|
|
|
5702
5792
|
gatewayTransactionId: input.gatewayTransactionId
|
|
5703
5793
|
},
|
|
5704
5794
|
getHeaders
|
|
5705
|
-
);
|
|
5795
|
+
).catch(explainCheckoutRequestError);
|
|
5706
5796
|
const result = data.websiteReconcilePaymentSession;
|
|
5707
5797
|
return {
|
|
5708
5798
|
success: result.success,
|
package/index.js
CHANGED
|
@@ -3277,6 +3277,78 @@ function hasRecoverableCartSessionError(errors) {
|
|
|
3277
3277
|
);
|
|
3278
3278
|
}
|
|
3279
3279
|
|
|
3280
|
+
// libs/sdk/src/modules/checkout-contact.ts
|
|
3281
|
+
var EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
3282
|
+
var PHONE_PATTERN = /^\+?\d{7,15}$/;
|
|
3283
|
+
function validEmail(value) {
|
|
3284
|
+
if (value.length > 320 || !EMAIL_PATTERN.test(value)) return false;
|
|
3285
|
+
const [local, domain] = value.split("@");
|
|
3286
|
+
if (!local || !domain || local.length > 64 || domain.length > 255 || local.startsWith(".") || local.endsWith(".") || local.includes("..")) {
|
|
3287
|
+
return false;
|
|
3288
|
+
}
|
|
3289
|
+
return domain.split(".").every((label) => /^[a-z\d](?:[a-z\d-]*[a-z\d])?$/i.test(label));
|
|
3290
|
+
}
|
|
3291
|
+
function normalizePhone(value) {
|
|
3292
|
+
return value.trim().replace(/[\s().-]/g, "");
|
|
3293
|
+
}
|
|
3294
|
+
function invalidContact(field) {
|
|
3295
|
+
const messages = {
|
|
3296
|
+
email: "Revisa el correo electr\xF3nico: debe estar completo y sin espacios.",
|
|
3297
|
+
phone: "Revisa el n\xFAmero de tel\xE9fono: usa entre 7 y 15 d\xEDgitos.",
|
|
3298
|
+
contact: "Ingresa un correo electr\xF3nico o un n\xFAmero de tel\xE9fono v\xE1lido."
|
|
3299
|
+
};
|
|
3300
|
+
return new WebsiteError(
|
|
3301
|
+
messages[field],
|
|
3302
|
+
`INVALID_CHECKOUT_${field.toUpperCase()}`
|
|
3303
|
+
);
|
|
3304
|
+
}
|
|
3305
|
+
function normalizeCheckoutContact(contact, mode) {
|
|
3306
|
+
const email = contact.email?.trim() || void 0;
|
|
3307
|
+
const phone = contact.phone ? normalizePhone(contact.phone) : void 0;
|
|
3308
|
+
const cellphone = contact.cellphone ? normalizePhone(contact.cellphone) : void 0;
|
|
3309
|
+
const emailValid = !email || validEmail(email);
|
|
3310
|
+
const phoneValid = !phone || PHONE_PATTERN.test(phone);
|
|
3311
|
+
const cellphoneValid = !cellphone || PHONE_PATTERN.test(cellphone);
|
|
3312
|
+
if (mode === "submit") {
|
|
3313
|
+
if (!emailValid) throw invalidContact("email");
|
|
3314
|
+
if (!phoneValid || !cellphoneValid) throw invalidContact("phone");
|
|
3315
|
+
}
|
|
3316
|
+
const normalized = {
|
|
3317
|
+
...contact,
|
|
3318
|
+
name: contact.name?.trim() || void 0,
|
|
3319
|
+
firstName: contact.firstName?.trim() || void 0,
|
|
3320
|
+
lastName: contact.lastName?.trim() || void 0,
|
|
3321
|
+
email: emailValid ? email : void 0,
|
|
3322
|
+
phone: phoneValid ? phone : void 0,
|
|
3323
|
+
cellphone: cellphoneValid ? cellphone : void 0
|
|
3324
|
+
};
|
|
3325
|
+
if ((normalized.name?.length ?? 0) > 160 || (normalized.firstName?.length ?? 0) > 80 || (normalized.lastName?.length ?? 0) > 80) {
|
|
3326
|
+
throw new WebsiteError(
|
|
3327
|
+
"Revisa los datos de contacto: el nombre es demasiado largo.",
|
|
3328
|
+
"INVALID_CHECKOUT_CONTACT"
|
|
3329
|
+
);
|
|
3330
|
+
}
|
|
3331
|
+
if (!normalized.email && !normalized.phone && !normalized.cellphone) {
|
|
3332
|
+
throw invalidContact(
|
|
3333
|
+
!emailValid ? "email" : !phoneValid || !cellphoneValid ? "phone" : "contact"
|
|
3334
|
+
);
|
|
3335
|
+
}
|
|
3336
|
+
return normalized;
|
|
3337
|
+
}
|
|
3338
|
+
function explainCheckoutRequestError(error) {
|
|
3339
|
+
if (error instanceof GraphQLRequestError && error.graphqlErrors.some(
|
|
3340
|
+
(item) => /invalid request payload|hay un error en los datos del pedido/i.test(
|
|
3341
|
+
item.message
|
|
3342
|
+
)
|
|
3343
|
+
)) {
|
|
3344
|
+
throw new WebsiteError(
|
|
3345
|
+
"Hay un error en los datos del pedido. Rev\xEDsalos e intenta de nuevo.",
|
|
3346
|
+
"INVALID_CHECKOUT_DATA"
|
|
3347
|
+
);
|
|
3348
|
+
}
|
|
3349
|
+
throw error;
|
|
3350
|
+
}
|
|
3351
|
+
|
|
3280
3352
|
// libs/sdk/src/modules/cart.ts
|
|
3281
3353
|
function mapCartItem(raw) {
|
|
3282
3354
|
return {
|
|
@@ -3352,6 +3424,15 @@ function requireCartSession(storage) {
|
|
|
3352
3424
|
return session;
|
|
3353
3425
|
}
|
|
3354
3426
|
function createCartModule(graphqlUrl, getHeaders, getContext, cartSessionStorage) {
|
|
3427
|
+
let pendingCartSessionOperation = Promise.resolve();
|
|
3428
|
+
function enqueueCartSessionOperation(run) {
|
|
3429
|
+
const operation = pendingCartSessionOperation.then(run, run);
|
|
3430
|
+
pendingCartSessionOperation = operation.then(
|
|
3431
|
+
() => void 0,
|
|
3432
|
+
() => void 0
|
|
3433
|
+
);
|
|
3434
|
+
return operation;
|
|
3435
|
+
}
|
|
3355
3436
|
async function fetchCart(orderId, cartToken) {
|
|
3356
3437
|
const data = await executeGraphQL(graphqlUrl, GET_CART, { orderId, cartToken }, getHeaders);
|
|
3357
3438
|
const result = data.websiteGetCart;
|
|
@@ -3374,72 +3455,80 @@ function createCartModule(graphqlUrl, getHeaders, getContext, cartSessionStorage
|
|
|
3374
3455
|
}
|
|
3375
3456
|
return {
|
|
3376
3457
|
async getOrCreate(contact, fulfillmentFamily) {
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
CREATE_CART,
|
|
3388
|
-
{
|
|
3389
|
-
websiteId: ctx.websiteId,
|
|
3390
|
-
cartToken: existing?.cartToken,
|
|
3391
|
-
contact,
|
|
3392
|
-
fulfillmentFamily
|
|
3393
|
-
},
|
|
3394
|
-
getHeaders
|
|
3395
|
-
);
|
|
3396
|
-
const result = data.websiteCreateCart;
|
|
3397
|
-
assertActionSuccess(result, "CART_CREATE_ERROR");
|
|
3398
|
-
cartSessionStorage.set({
|
|
3399
|
-
orderId: result.order_id,
|
|
3400
|
-
cartToken: result.cart_token
|
|
3401
|
-
});
|
|
3402
|
-
return mapCart(result.cart, result.cart_token);
|
|
3403
|
-
},
|
|
3404
|
-
async startCheckout(input) {
|
|
3405
|
-
const ctx = getContext();
|
|
3406
|
-
if (!ctx.chainId) {
|
|
3407
|
-
throw new WebsiteError(
|
|
3408
|
-
"This website has no chain configured. Checkout requires a chain_id.",
|
|
3409
|
-
"NO_CHAIN"
|
|
3410
|
-
);
|
|
3411
|
-
}
|
|
3412
|
-
const requestStartCheckout = async (cartToken) => {
|
|
3458
|
+
return enqueueCartSessionOperation(async () => {
|
|
3459
|
+
const normalizedContact = contact ? normalizeCheckoutContact(contact, "draft") : void 0;
|
|
3460
|
+
const ctx = getContext();
|
|
3461
|
+
if (!ctx.chainId) {
|
|
3462
|
+
throw new WebsiteError(
|
|
3463
|
+
"This website has no chain configured. Cart requires a chain_id.",
|
|
3464
|
+
"NO_CHAIN"
|
|
3465
|
+
);
|
|
3466
|
+
}
|
|
3467
|
+
const existing = cartSessionStorage.get();
|
|
3413
3468
|
const data = await executeGraphQL(
|
|
3414
3469
|
graphqlUrl,
|
|
3415
|
-
|
|
3470
|
+
CREATE_CART,
|
|
3416
3471
|
{
|
|
3417
3472
|
websiteId: ctx.websiteId,
|
|
3418
|
-
cartToken,
|
|
3419
|
-
contact:
|
|
3420
|
-
fulfillmentFamily
|
|
3421
|
-
items: input.items.map((item) => ({
|
|
3422
|
-
product_variant_id: item.productVariantId,
|
|
3423
|
-
quantity: item.quantity
|
|
3424
|
-
})),
|
|
3425
|
-
marketingAttribution: input.marketingAttribution ? serializeWebsiteMarketingAttribution(input.marketingAttribution) : void 0
|
|
3473
|
+
cartToken: existing?.cartToken,
|
|
3474
|
+
contact: normalizedContact,
|
|
3475
|
+
fulfillmentFamily
|
|
3426
3476
|
},
|
|
3427
3477
|
getHeaders
|
|
3428
|
-
);
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
result
|
|
3436
|
-
}
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3478
|
+
).catch(explainCheckoutRequestError);
|
|
3479
|
+
const result = data.websiteCreateCart;
|
|
3480
|
+
assertActionSuccess(result, "CART_CREATE_ERROR");
|
|
3481
|
+
cartSessionStorage.set({
|
|
3482
|
+
orderId: result.order_id,
|
|
3483
|
+
cartToken: result.cart_token
|
|
3484
|
+
});
|
|
3485
|
+
return mapCart(result.cart, result.cart_token);
|
|
3486
|
+
});
|
|
3487
|
+
},
|
|
3488
|
+
async startCheckout(input) {
|
|
3489
|
+
return enqueueCartSessionOperation(async () => {
|
|
3490
|
+
const contact = normalizeCheckoutContact(input.contact, "draft");
|
|
3491
|
+
const ctx = getContext();
|
|
3492
|
+
if (!ctx.chainId) {
|
|
3493
|
+
throw new WebsiteError(
|
|
3494
|
+
"This website has no chain configured. Checkout requires a chain_id.",
|
|
3495
|
+
"NO_CHAIN"
|
|
3496
|
+
);
|
|
3497
|
+
}
|
|
3498
|
+
const requestStartCheckout = async (cartToken) => {
|
|
3499
|
+
const data = await executeGraphQL(
|
|
3500
|
+
graphqlUrl,
|
|
3501
|
+
START_GUEST_CHECKOUT,
|
|
3502
|
+
{
|
|
3503
|
+
websiteId: ctx.websiteId,
|
|
3504
|
+
cartToken,
|
|
3505
|
+
contact,
|
|
3506
|
+
fulfillmentFamily: input.fulfillmentFamily,
|
|
3507
|
+
items: input.items.map((item) => ({
|
|
3508
|
+
product_variant_id: item.productVariantId,
|
|
3509
|
+
quantity: item.quantity
|
|
3510
|
+
})),
|
|
3511
|
+
marketingAttribution: input.marketingAttribution ? serializeWebsiteMarketingAttribution(
|
|
3512
|
+
input.marketingAttribution
|
|
3513
|
+
) : void 0
|
|
3514
|
+
},
|
|
3515
|
+
getHeaders
|
|
3516
|
+
).catch(explainCheckoutRequestError);
|
|
3517
|
+
return data.websiteStartGuestCheckout;
|
|
3518
|
+
};
|
|
3519
|
+
const existing = cartSessionStorage.get();
|
|
3520
|
+
let result = await requestStartCheckout(existing?.cartToken);
|
|
3521
|
+
if (existing && !result.success && hasRecoverableCartSessionError(result.errors)) {
|
|
3522
|
+
cartSessionStorage.clear();
|
|
3523
|
+
result = await requestStartCheckout();
|
|
3524
|
+
}
|
|
3525
|
+
assertActionSuccess(result, "CHECKOUT_START_ERROR");
|
|
3526
|
+
cartSessionStorage.set({
|
|
3527
|
+
orderId: result.order_id,
|
|
3528
|
+
cartToken: result.cart_token
|
|
3529
|
+
});
|
|
3530
|
+
return mapCart(result.cart, result.cart_token);
|
|
3441
3531
|
});
|
|
3442
|
-
return mapCart(result.cart, result.cart_token);
|
|
3443
3532
|
},
|
|
3444
3533
|
async get() {
|
|
3445
3534
|
const session = cartSessionStorage.get();
|
|
@@ -5538,6 +5627,7 @@ function createCheckoutModule(graphqlUrl, getHeaders, getContext, cartSessionSto
|
|
|
5538
5627
|
return mapCouponResult(data.websiteRemoveCoupon);
|
|
5539
5628
|
},
|
|
5540
5629
|
async submit(input) {
|
|
5630
|
+
const contact = normalizeCheckoutContact(input.contact, "submit");
|
|
5541
5631
|
const session = requireCartSession2(cartSessionStorage);
|
|
5542
5632
|
const data = await executeGraphQL(
|
|
5543
5633
|
graphqlUrl,
|
|
@@ -5545,7 +5635,7 @@ function createCheckoutModule(graphqlUrl, getHeaders, getContext, cartSessionSto
|
|
|
5545
5635
|
{
|
|
5546
5636
|
orderId: session.orderId,
|
|
5547
5637
|
cartToken: session.cartToken,
|
|
5548
|
-
contact
|
|
5638
|
+
contact,
|
|
5549
5639
|
fulfillmentFamily: input.fulfillmentFamily,
|
|
5550
5640
|
address: input.address,
|
|
5551
5641
|
shippingQuoteId: input.shippingQuoteId,
|
|
@@ -5565,7 +5655,7 @@ function createCheckoutModule(graphqlUrl, getHeaders, getContext, cartSessionSto
|
|
|
5565
5655
|
} : void 0
|
|
5566
5656
|
},
|
|
5567
5657
|
getHeaders
|
|
5568
|
-
);
|
|
5658
|
+
).catch(explainCheckoutRequestError);
|
|
5569
5659
|
const result = data.websiteCheckout;
|
|
5570
5660
|
if (!result.success && result.errors && result.errors.length > 0) {
|
|
5571
5661
|
throw new CheckoutError(result.errors);
|
|
@@ -5606,7 +5696,7 @@ function createCheckoutModule(graphqlUrl, getHeaders, getContext, cartSessionSto
|
|
|
5606
5696
|
returnUrl: input.returnUrl
|
|
5607
5697
|
},
|
|
5608
5698
|
getHeaders
|
|
5609
|
-
);
|
|
5699
|
+
).catch(explainCheckoutRequestError);
|
|
5610
5700
|
const result = data.websiteCreatePaymentSession;
|
|
5611
5701
|
if (result.success && result.payment_session_id && (result.integration_mode !== "redirect" || !result.redirect_url)) {
|
|
5612
5702
|
throw new WebsiteError(
|
|
@@ -5641,7 +5731,7 @@ function createCheckoutModule(graphqlUrl, getHeaders, getContext, cartSessionSto
|
|
|
5641
5731
|
gatewayTransactionId: input.gatewayTransactionId
|
|
5642
5732
|
},
|
|
5643
5733
|
getHeaders
|
|
5644
|
-
);
|
|
5734
|
+
).catch(explainCheckoutRequestError);
|
|
5645
5735
|
const result = data.websiteReconcilePaymentSession;
|
|
5646
5736
|
return {
|
|
5647
5737
|
success: result.success,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { WebsiteGuestContact } from "../types";
|
|
2
|
+
/** Drafts can use the valid contact channel while the buyer edits the other one. */
|
|
3
|
+
export declare function normalizeCheckoutContact(contact: WebsiteGuestContact, mode: "draft" | "submit"): WebsiteGuestContact;
|
|
4
|
+
export declare function explainCheckoutRequestError(error: unknown): never;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bacano/sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8",
|
|
4
4
|
"description": "TypeScript SDK for building websites on the Bacano ERP",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -23,11 +23,21 @@
|
|
|
23
23
|
"import": "./graphql.js",
|
|
24
24
|
"require": "./graphql.cjs"
|
|
25
25
|
},
|
|
26
|
+
"./icons": {
|
|
27
|
+
"types": "./icons.d.ts",
|
|
28
|
+
"import": "./icons.js",
|
|
29
|
+
"require": "./icons.cjs"
|
|
30
|
+
},
|
|
26
31
|
"./content-management": {
|
|
27
32
|
"types": "./content-management.d.ts",
|
|
28
33
|
"import": "./content-management.js",
|
|
29
34
|
"require": "./content-management.cjs"
|
|
30
35
|
},
|
|
36
|
+
"./catalog-management": {
|
|
37
|
+
"types": "./catalog-management.d.ts",
|
|
38
|
+
"import": "./catalog-management.js",
|
|
39
|
+
"require": "./catalog-management.cjs"
|
|
40
|
+
},
|
|
31
41
|
"./react": {
|
|
32
42
|
"types": "./react.d.ts",
|
|
33
43
|
"import": "./react.js",
|
|
@@ -42,6 +52,11 @@
|
|
|
42
52
|
"types": "./react/forms.d.ts",
|
|
43
53
|
"import": "./react/forms.js",
|
|
44
54
|
"require": "./react/forms.cjs"
|
|
55
|
+
},
|
|
56
|
+
"./react/icon": {
|
|
57
|
+
"types": "./react/icon.d.ts",
|
|
58
|
+
"import": "./react/icon.js",
|
|
59
|
+
"require": "./react/icon.cjs"
|
|
45
60
|
}
|
|
46
61
|
},
|
|
47
62
|
"sideEffects": false,
|