@betterstore/react 0.2.1 → 0.2.3
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/CHANGELOG.md +12 -0
- package/dist/components/index.d.ts +0 -1
- package/dist/index.cjs.js +0 -234
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -234
- package/dist/styles.css +1 -0
- package/package.json +1 -1
- package/rollup.config.mjs +6 -3
- package/tailwind.config.cjs +14 -0
- package/dist/components/route-handelers/index.d.ts +0 -1
- package/dist/components/route-handelers/next-js.d.ts +0 -13
- package/tailwind.config.js +0 -8
- /package/{postcss.config.js → postcss.config.cjs} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,4 +2,3 @@ export { useCart } from "./cart/useCart";
|
|
|
2
2
|
export { default as CheckoutEmbed } from "./checkout-embed";
|
|
3
3
|
export { default as PaymentElement } from "./payment-element";
|
|
4
4
|
export { useCheckout } from "./payment-element/useCheckout";
|
|
5
|
-
export { createNextJSHandler } from "./route-handelers";
|
package/dist/index.cjs.js
CHANGED
|
@@ -399,241 +399,7 @@ function PaymentElement({ paymentSecret, checkoutAppearance, onSuccess, onError,
|
|
|
399
399
|
}
|
|
400
400
|
var index = React.memo(PaymentElement);
|
|
401
401
|
|
|
402
|
-
const defaultBetterStoreRoutes = {
|
|
403
|
-
checkout: {
|
|
404
|
-
GET: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
405
|
-
const { searchParams } = new URL(req.url);
|
|
406
|
-
const checkoutId = searchParams.get("checkoutId");
|
|
407
|
-
if (!checkoutId) {
|
|
408
|
-
return new Response("Checkout ID is required", { status: 400 });
|
|
409
|
-
}
|
|
410
|
-
try {
|
|
411
|
-
const checkout = yield betterStore.checkout.retrieve(checkoutId);
|
|
412
|
-
return Response.json(checkout);
|
|
413
|
-
}
|
|
414
|
-
catch (error) {
|
|
415
|
-
return new Response("Failed to fetch checkout", { status: 500 });
|
|
416
|
-
}
|
|
417
|
-
}),
|
|
418
|
-
POST: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
419
|
-
try {
|
|
420
|
-
const body = yield req.json();
|
|
421
|
-
const checkout = yield betterStore.checkout.create(body);
|
|
422
|
-
return Response.json(checkout);
|
|
423
|
-
}
|
|
424
|
-
catch (error) {
|
|
425
|
-
return new Response("Failed to create checkout", { status: 500 });
|
|
426
|
-
}
|
|
427
|
-
}),
|
|
428
|
-
PUT: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
429
|
-
const { searchParams } = new URL(req.url);
|
|
430
|
-
const checkoutId = searchParams.get("checkoutId");
|
|
431
|
-
if (!checkoutId) {
|
|
432
|
-
return new Response("Checkout ID is required", { status: 400 });
|
|
433
|
-
}
|
|
434
|
-
try {
|
|
435
|
-
const body = yield req.json();
|
|
436
|
-
const checkout = yield betterStore.checkout.update(checkoutId, body);
|
|
437
|
-
return Response.json(checkout);
|
|
438
|
-
}
|
|
439
|
-
catch (error) {
|
|
440
|
-
return new Response("Failed to update checkout", { status: 500 });
|
|
441
|
-
}
|
|
442
|
-
}),
|
|
443
|
-
},
|
|
444
|
-
"checkout/shipping": {
|
|
445
|
-
GET: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
446
|
-
const { searchParams } = new URL(req.url);
|
|
447
|
-
const checkoutId = searchParams.get("checkoutId");
|
|
448
|
-
if (!checkoutId) {
|
|
449
|
-
return new Response("Checkout ID is required", { status: 400 });
|
|
450
|
-
}
|
|
451
|
-
try {
|
|
452
|
-
const rates = yield betterStore.checkout.getShippingRates(checkoutId);
|
|
453
|
-
return Response.json(rates);
|
|
454
|
-
}
|
|
455
|
-
catch (error) {
|
|
456
|
-
return new Response("Failed to get shipping rates", { status: 500 });
|
|
457
|
-
}
|
|
458
|
-
}),
|
|
459
|
-
},
|
|
460
|
-
"checkout/payment": {
|
|
461
|
-
POST: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
462
|
-
const { searchParams } = new URL(req.url);
|
|
463
|
-
const checkoutId = searchParams.get("checkoutId");
|
|
464
|
-
if (!checkoutId) {
|
|
465
|
-
return new Response("Checkout ID is required", { status: 400 });
|
|
466
|
-
}
|
|
467
|
-
try {
|
|
468
|
-
const secret = yield betterStore.checkout.generatePaymentSecret(checkoutId);
|
|
469
|
-
return Response.json({ clientSecret: secret });
|
|
470
|
-
}
|
|
471
|
-
catch (error) {
|
|
472
|
-
return new Response("Failed to generate payment secret", {
|
|
473
|
-
status: 500,
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
}),
|
|
477
|
-
},
|
|
478
|
-
customer: {
|
|
479
|
-
GET: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
480
|
-
const { searchParams } = new URL(req.url);
|
|
481
|
-
const idOrEmail = searchParams.get("idOrEmail");
|
|
482
|
-
if (!idOrEmail) {
|
|
483
|
-
return new Response("Customer ID or email is required", {
|
|
484
|
-
status: 400,
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
try {
|
|
488
|
-
const customer = yield betterStore.customer.retrieve(idOrEmail);
|
|
489
|
-
return Response.json(customer);
|
|
490
|
-
}
|
|
491
|
-
catch (error) {
|
|
492
|
-
return new Response("Failed to fetch customer", { status: 500 });
|
|
493
|
-
}
|
|
494
|
-
}),
|
|
495
|
-
POST: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
496
|
-
try {
|
|
497
|
-
const body = yield req.json();
|
|
498
|
-
const customer = yield betterStore.customer.create(body);
|
|
499
|
-
return Response.json(customer);
|
|
500
|
-
}
|
|
501
|
-
catch (error) {
|
|
502
|
-
return new Response("Failed to create customer", { status: 500 });
|
|
503
|
-
}
|
|
504
|
-
}),
|
|
505
|
-
PUT: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
506
|
-
const { searchParams } = new URL(req.url);
|
|
507
|
-
const customerId = searchParams.get("customerId");
|
|
508
|
-
if (!customerId) {
|
|
509
|
-
return new Response("Customer ID is required", { status: 400 });
|
|
510
|
-
}
|
|
511
|
-
try {
|
|
512
|
-
const body = yield req.json();
|
|
513
|
-
const customer = yield betterStore.customer.update(customerId, body);
|
|
514
|
-
return Response.json(customer);
|
|
515
|
-
}
|
|
516
|
-
catch (error) {
|
|
517
|
-
return new Response("Failed to update customer", { status: 500 });
|
|
518
|
-
}
|
|
519
|
-
}),
|
|
520
|
-
DELETE: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
521
|
-
const { searchParams } = new URL(req.url);
|
|
522
|
-
const customerId = searchParams.get("customerId");
|
|
523
|
-
if (!customerId) {
|
|
524
|
-
return new Response("Customer ID is required", { status: 400 });
|
|
525
|
-
}
|
|
526
|
-
try {
|
|
527
|
-
yield betterStore.customer.delete(customerId);
|
|
528
|
-
return new Response(null, { status: 204 });
|
|
529
|
-
}
|
|
530
|
-
catch (error) {
|
|
531
|
-
return new Response("Failed to delete customer", { status: 500 });
|
|
532
|
-
}
|
|
533
|
-
}),
|
|
534
|
-
},
|
|
535
|
-
product: {
|
|
536
|
-
GET: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
537
|
-
const { searchParams } = new URL(req.url);
|
|
538
|
-
const productId = searchParams.get("productId");
|
|
539
|
-
try {
|
|
540
|
-
if (productId) {
|
|
541
|
-
const product = yield betterStore.products.retrieve(productId);
|
|
542
|
-
return Response.json(product);
|
|
543
|
-
}
|
|
544
|
-
else {
|
|
545
|
-
const products = yield betterStore.products.list();
|
|
546
|
-
return Response.json(products);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
catch (error) {
|
|
550
|
-
return new Response("Failed to fetch products", { status: 500 });
|
|
551
|
-
}
|
|
552
|
-
}),
|
|
553
|
-
},
|
|
554
|
-
};
|
|
555
|
-
function createNextJSHandler(betterStore, config = {}) {
|
|
556
|
-
const { allowedOrigins = [] } = config;
|
|
557
|
-
function validateRequest(req) {
|
|
558
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
559
|
-
if (allowedOrigins.length > 0) {
|
|
560
|
-
const origin = req.headers.get("origin");
|
|
561
|
-
if (!origin || !allowedOrigins.includes(origin)) {
|
|
562
|
-
return new Response("Unauthorized", { status: 403 });
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
return null;
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
function getRouteFromPath(pathname) {
|
|
569
|
-
// Remove leading and trailing slashes and 'api' prefix if present
|
|
570
|
-
const cleanPath = pathname.replace(/^\/|\/$/g, "").replace(/^api\//, "");
|
|
571
|
-
// Get the relevant part of the path (everything after betterstore/)
|
|
572
|
-
const relevantPath = cleanPath.split("betterstore/")[1] || "";
|
|
573
|
-
return relevantPath;
|
|
574
|
-
}
|
|
575
|
-
return {
|
|
576
|
-
GET(req) {
|
|
577
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
578
|
-
var _a;
|
|
579
|
-
const validationError = yield validateRequest(req);
|
|
580
|
-
if (validationError)
|
|
581
|
-
return validationError;
|
|
582
|
-
const route = getRouteFromPath(new URL(req.url).pathname);
|
|
583
|
-
const handler = (_a = defaultBetterStoreRoutes[route]) === null || _a === void 0 ? void 0 : _a.GET;
|
|
584
|
-
if (!handler) {
|
|
585
|
-
return new Response(`Route not found: ${route}`, { status: 404 });
|
|
586
|
-
}
|
|
587
|
-
return handler(req, betterStore);
|
|
588
|
-
});
|
|
589
|
-
},
|
|
590
|
-
POST(req) {
|
|
591
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
592
|
-
var _a;
|
|
593
|
-
const validationError = yield validateRequest(req);
|
|
594
|
-
if (validationError)
|
|
595
|
-
return validationError;
|
|
596
|
-
const route = getRouteFromPath(new URL(req.url).pathname);
|
|
597
|
-
const handler = (_a = defaultBetterStoreRoutes[route]) === null || _a === void 0 ? void 0 : _a.POST;
|
|
598
|
-
if (!handler) {
|
|
599
|
-
return new Response(`Route not found: ${route}`, { status: 404 });
|
|
600
|
-
}
|
|
601
|
-
return handler(req, betterStore);
|
|
602
|
-
});
|
|
603
|
-
},
|
|
604
|
-
PUT(req) {
|
|
605
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
606
|
-
var _a;
|
|
607
|
-
const validationError = yield validateRequest(req);
|
|
608
|
-
if (validationError)
|
|
609
|
-
return validationError;
|
|
610
|
-
const route = getRouteFromPath(new URL(req.url).pathname);
|
|
611
|
-
const handler = (_a = defaultBetterStoreRoutes[route]) === null || _a === void 0 ? void 0 : _a.PUT;
|
|
612
|
-
if (!handler) {
|
|
613
|
-
return new Response(`Route not found: ${route}`, { status: 404 });
|
|
614
|
-
}
|
|
615
|
-
return handler(req, betterStore);
|
|
616
|
-
});
|
|
617
|
-
},
|
|
618
|
-
DELETE(req) {
|
|
619
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
620
|
-
var _a;
|
|
621
|
-
const validationError = yield validateRequest(req);
|
|
622
|
-
if (validationError)
|
|
623
|
-
return validationError;
|
|
624
|
-
const route = getRouteFromPath(new URL(req.url).pathname);
|
|
625
|
-
const handler = (_a = defaultBetterStoreRoutes[route]) === null || _a === void 0 ? void 0 : _a.DELETE;
|
|
626
|
-
if (!handler) {
|
|
627
|
-
return new Response(`Route not found: ${route}`, { status: 404 });
|
|
628
|
-
}
|
|
629
|
-
return handler(req, betterStore);
|
|
630
|
-
});
|
|
631
|
-
},
|
|
632
|
-
};
|
|
633
|
-
}
|
|
634
|
-
|
|
635
402
|
exports.CheckoutEmbed = index$1;
|
|
636
403
|
exports.PaymentElement = index;
|
|
637
|
-
exports.createNextJSHandler = createNextJSHandler;
|
|
638
404
|
exports.useCart = useCart;
|
|
639
405
|
exports.useCheckout = useCheckout;
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -397,237 +397,4 @@ function PaymentElement({ paymentSecret, checkoutAppearance, onSuccess, onError,
|
|
|
397
397
|
}
|
|
398
398
|
var index = memo(PaymentElement);
|
|
399
399
|
|
|
400
|
-
|
|
401
|
-
checkout: {
|
|
402
|
-
GET: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
403
|
-
const { searchParams } = new URL(req.url);
|
|
404
|
-
const checkoutId = searchParams.get("checkoutId");
|
|
405
|
-
if (!checkoutId) {
|
|
406
|
-
return new Response("Checkout ID is required", { status: 400 });
|
|
407
|
-
}
|
|
408
|
-
try {
|
|
409
|
-
const checkout = yield betterStore.checkout.retrieve(checkoutId);
|
|
410
|
-
return Response.json(checkout);
|
|
411
|
-
}
|
|
412
|
-
catch (error) {
|
|
413
|
-
return new Response("Failed to fetch checkout", { status: 500 });
|
|
414
|
-
}
|
|
415
|
-
}),
|
|
416
|
-
POST: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
417
|
-
try {
|
|
418
|
-
const body = yield req.json();
|
|
419
|
-
const checkout = yield betterStore.checkout.create(body);
|
|
420
|
-
return Response.json(checkout);
|
|
421
|
-
}
|
|
422
|
-
catch (error) {
|
|
423
|
-
return new Response("Failed to create checkout", { status: 500 });
|
|
424
|
-
}
|
|
425
|
-
}),
|
|
426
|
-
PUT: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
427
|
-
const { searchParams } = new URL(req.url);
|
|
428
|
-
const checkoutId = searchParams.get("checkoutId");
|
|
429
|
-
if (!checkoutId) {
|
|
430
|
-
return new Response("Checkout ID is required", { status: 400 });
|
|
431
|
-
}
|
|
432
|
-
try {
|
|
433
|
-
const body = yield req.json();
|
|
434
|
-
const checkout = yield betterStore.checkout.update(checkoutId, body);
|
|
435
|
-
return Response.json(checkout);
|
|
436
|
-
}
|
|
437
|
-
catch (error) {
|
|
438
|
-
return new Response("Failed to update checkout", { status: 500 });
|
|
439
|
-
}
|
|
440
|
-
}),
|
|
441
|
-
},
|
|
442
|
-
"checkout/shipping": {
|
|
443
|
-
GET: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
444
|
-
const { searchParams } = new URL(req.url);
|
|
445
|
-
const checkoutId = searchParams.get("checkoutId");
|
|
446
|
-
if (!checkoutId) {
|
|
447
|
-
return new Response("Checkout ID is required", { status: 400 });
|
|
448
|
-
}
|
|
449
|
-
try {
|
|
450
|
-
const rates = yield betterStore.checkout.getShippingRates(checkoutId);
|
|
451
|
-
return Response.json(rates);
|
|
452
|
-
}
|
|
453
|
-
catch (error) {
|
|
454
|
-
return new Response("Failed to get shipping rates", { status: 500 });
|
|
455
|
-
}
|
|
456
|
-
}),
|
|
457
|
-
},
|
|
458
|
-
"checkout/payment": {
|
|
459
|
-
POST: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
460
|
-
const { searchParams } = new URL(req.url);
|
|
461
|
-
const checkoutId = searchParams.get("checkoutId");
|
|
462
|
-
if (!checkoutId) {
|
|
463
|
-
return new Response("Checkout ID is required", { status: 400 });
|
|
464
|
-
}
|
|
465
|
-
try {
|
|
466
|
-
const secret = yield betterStore.checkout.generatePaymentSecret(checkoutId);
|
|
467
|
-
return Response.json({ clientSecret: secret });
|
|
468
|
-
}
|
|
469
|
-
catch (error) {
|
|
470
|
-
return new Response("Failed to generate payment secret", {
|
|
471
|
-
status: 500,
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
}),
|
|
475
|
-
},
|
|
476
|
-
customer: {
|
|
477
|
-
GET: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
478
|
-
const { searchParams } = new URL(req.url);
|
|
479
|
-
const idOrEmail = searchParams.get("idOrEmail");
|
|
480
|
-
if (!idOrEmail) {
|
|
481
|
-
return new Response("Customer ID or email is required", {
|
|
482
|
-
status: 400,
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
try {
|
|
486
|
-
const customer = yield betterStore.customer.retrieve(idOrEmail);
|
|
487
|
-
return Response.json(customer);
|
|
488
|
-
}
|
|
489
|
-
catch (error) {
|
|
490
|
-
return new Response("Failed to fetch customer", { status: 500 });
|
|
491
|
-
}
|
|
492
|
-
}),
|
|
493
|
-
POST: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
494
|
-
try {
|
|
495
|
-
const body = yield req.json();
|
|
496
|
-
const customer = yield betterStore.customer.create(body);
|
|
497
|
-
return Response.json(customer);
|
|
498
|
-
}
|
|
499
|
-
catch (error) {
|
|
500
|
-
return new Response("Failed to create customer", { status: 500 });
|
|
501
|
-
}
|
|
502
|
-
}),
|
|
503
|
-
PUT: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
504
|
-
const { searchParams } = new URL(req.url);
|
|
505
|
-
const customerId = searchParams.get("customerId");
|
|
506
|
-
if (!customerId) {
|
|
507
|
-
return new Response("Customer ID is required", { status: 400 });
|
|
508
|
-
}
|
|
509
|
-
try {
|
|
510
|
-
const body = yield req.json();
|
|
511
|
-
const customer = yield betterStore.customer.update(customerId, body);
|
|
512
|
-
return Response.json(customer);
|
|
513
|
-
}
|
|
514
|
-
catch (error) {
|
|
515
|
-
return new Response("Failed to update customer", { status: 500 });
|
|
516
|
-
}
|
|
517
|
-
}),
|
|
518
|
-
DELETE: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
519
|
-
const { searchParams } = new URL(req.url);
|
|
520
|
-
const customerId = searchParams.get("customerId");
|
|
521
|
-
if (!customerId) {
|
|
522
|
-
return new Response("Customer ID is required", { status: 400 });
|
|
523
|
-
}
|
|
524
|
-
try {
|
|
525
|
-
yield betterStore.customer.delete(customerId);
|
|
526
|
-
return new Response(null, { status: 204 });
|
|
527
|
-
}
|
|
528
|
-
catch (error) {
|
|
529
|
-
return new Response("Failed to delete customer", { status: 500 });
|
|
530
|
-
}
|
|
531
|
-
}),
|
|
532
|
-
},
|
|
533
|
-
product: {
|
|
534
|
-
GET: (req, betterStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
535
|
-
const { searchParams } = new URL(req.url);
|
|
536
|
-
const productId = searchParams.get("productId");
|
|
537
|
-
try {
|
|
538
|
-
if (productId) {
|
|
539
|
-
const product = yield betterStore.products.retrieve(productId);
|
|
540
|
-
return Response.json(product);
|
|
541
|
-
}
|
|
542
|
-
else {
|
|
543
|
-
const products = yield betterStore.products.list();
|
|
544
|
-
return Response.json(products);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
catch (error) {
|
|
548
|
-
return new Response("Failed to fetch products", { status: 500 });
|
|
549
|
-
}
|
|
550
|
-
}),
|
|
551
|
-
},
|
|
552
|
-
};
|
|
553
|
-
function createNextJSHandler(betterStore, config = {}) {
|
|
554
|
-
const { allowedOrigins = [] } = config;
|
|
555
|
-
function validateRequest(req) {
|
|
556
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
557
|
-
if (allowedOrigins.length > 0) {
|
|
558
|
-
const origin = req.headers.get("origin");
|
|
559
|
-
if (!origin || !allowedOrigins.includes(origin)) {
|
|
560
|
-
return new Response("Unauthorized", { status: 403 });
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
return null;
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
function getRouteFromPath(pathname) {
|
|
567
|
-
// Remove leading and trailing slashes and 'api' prefix if present
|
|
568
|
-
const cleanPath = pathname.replace(/^\/|\/$/g, "").replace(/^api\//, "");
|
|
569
|
-
// Get the relevant part of the path (everything after betterstore/)
|
|
570
|
-
const relevantPath = cleanPath.split("betterstore/")[1] || "";
|
|
571
|
-
return relevantPath;
|
|
572
|
-
}
|
|
573
|
-
return {
|
|
574
|
-
GET(req) {
|
|
575
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
576
|
-
var _a;
|
|
577
|
-
const validationError = yield validateRequest(req);
|
|
578
|
-
if (validationError)
|
|
579
|
-
return validationError;
|
|
580
|
-
const route = getRouteFromPath(new URL(req.url).pathname);
|
|
581
|
-
const handler = (_a = defaultBetterStoreRoutes[route]) === null || _a === void 0 ? void 0 : _a.GET;
|
|
582
|
-
if (!handler) {
|
|
583
|
-
return new Response(`Route not found: ${route}`, { status: 404 });
|
|
584
|
-
}
|
|
585
|
-
return handler(req, betterStore);
|
|
586
|
-
});
|
|
587
|
-
},
|
|
588
|
-
POST(req) {
|
|
589
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
590
|
-
var _a;
|
|
591
|
-
const validationError = yield validateRequest(req);
|
|
592
|
-
if (validationError)
|
|
593
|
-
return validationError;
|
|
594
|
-
const route = getRouteFromPath(new URL(req.url).pathname);
|
|
595
|
-
const handler = (_a = defaultBetterStoreRoutes[route]) === null || _a === void 0 ? void 0 : _a.POST;
|
|
596
|
-
if (!handler) {
|
|
597
|
-
return new Response(`Route not found: ${route}`, { status: 404 });
|
|
598
|
-
}
|
|
599
|
-
return handler(req, betterStore);
|
|
600
|
-
});
|
|
601
|
-
},
|
|
602
|
-
PUT(req) {
|
|
603
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
604
|
-
var _a;
|
|
605
|
-
const validationError = yield validateRequest(req);
|
|
606
|
-
if (validationError)
|
|
607
|
-
return validationError;
|
|
608
|
-
const route = getRouteFromPath(new URL(req.url).pathname);
|
|
609
|
-
const handler = (_a = defaultBetterStoreRoutes[route]) === null || _a === void 0 ? void 0 : _a.PUT;
|
|
610
|
-
if (!handler) {
|
|
611
|
-
return new Response(`Route not found: ${route}`, { status: 404 });
|
|
612
|
-
}
|
|
613
|
-
return handler(req, betterStore);
|
|
614
|
-
});
|
|
615
|
-
},
|
|
616
|
-
DELETE(req) {
|
|
617
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
618
|
-
var _a;
|
|
619
|
-
const validationError = yield validateRequest(req);
|
|
620
|
-
if (validationError)
|
|
621
|
-
return validationError;
|
|
622
|
-
const route = getRouteFromPath(new URL(req.url).pathname);
|
|
623
|
-
const handler = (_a = defaultBetterStoreRoutes[route]) === null || _a === void 0 ? void 0 : _a.DELETE;
|
|
624
|
-
if (!handler) {
|
|
625
|
-
return new Response(`Route not found: ${route}`, { status: 404 });
|
|
626
|
-
}
|
|
627
|
-
return handler(req, betterStore);
|
|
628
|
-
});
|
|
629
|
-
},
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
export { index$1 as CheckoutEmbed, index as PaymentElement, createNextJSHandler, useCart, useCheckout };
|
|
400
|
+
export { index$1 as CheckoutEmbed, index as PaymentElement, useCart, useCheckout };
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }.absolute{position:absolute}.relative{position:relative}.-right-2{right:-.5rem}.-top-2{top:-.5rem}.mb-6{margin-bottom:1.5rem}.ml-4{margin-left:1rem}.mr-2{margin-right:.5rem}.mt-2{margin-top:.5rem}.flex{display:flex}.grid{display:grid}.h-16{height:4rem}.h-6{height:1.5rem}.h-full{height:100%}.w-16{width:4rem}.w-6{width:1.5rem}.w-full{width:100%}.flex-1{flex:1 1 0%}.items-center{align-items:center}.justify-center{justify-content:center}.justify-between{justify-content:space-between}.gap-4{gap:1rem}.overflow-hidden{overflow:hidden}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:.5rem}.border{border-width:1px}.border-t{border-top-width:1px}.border-zinc-800{--tw-border-opacity:1;border-color:rgb(39 39 42/var(--tw-border-opacity,1))}.bg-black{--tw-bg-opacity:1;background-color:rgb(0 0 0/var(--tw-bg-opacity,1))}.bg-zinc-700{--tw-bg-opacity:1;background-color:rgb(63 63 70/var(--tw-bg-opacity,1))}.bg-zinc-800{--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.bg-zinc-900{--tw-bg-opacity:1;background-color:rgb(24 24 27/var(--tw-bg-opacity,1))}.object-cover{-o-object-fit:cover;object-fit:cover}.p-6{padding:1.5rem}.py-2{padding-bottom:.5rem;padding-top:.5rem}.py-4{padding-bottom:1rem}.pt-4,.py-4{padding-top:1rem}.text-right{text-align:right}.text-2xl{font-size:1.5rem;line-height:2rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.font-bold{font-weight:700}.font-medium{font-weight:500}.text-red-500{--tw-text-opacity:1;color:rgb(239 68 68/var(--tw-text-opacity,1))}.text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.text-zinc-400{--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity,1))}.text-zinc-500{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.outline{outline-style:solid}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}@media (min-width:768px){.md\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}}
|
package/package.json
CHANGED
package/rollup.config.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import commonjs from "@rollup/plugin-commonjs";
|
|
2
2
|
import resolve from "@rollup/plugin-node-resolve";
|
|
3
3
|
import typescript from "@rollup/plugin-typescript";
|
|
4
|
-
import tailwindcss from "@tailwindcss/postcss";
|
|
5
4
|
import autoprefixer from "autoprefixer";
|
|
6
5
|
import postcss from "rollup-plugin-postcss";
|
|
6
|
+
import tailwindcss from "tailwindcss";
|
|
7
7
|
|
|
8
8
|
export default {
|
|
9
9
|
input: "src/index.ts",
|
|
@@ -22,8 +22,11 @@ export default {
|
|
|
22
22
|
commonjs(),
|
|
23
23
|
typescript(),
|
|
24
24
|
postcss({
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
plugins: [tailwindcss(), autoprefixer()],
|
|
26
|
+
extract: "styles.css",
|
|
27
|
+
modules: false,
|
|
28
|
+
minimize: true,
|
|
29
|
+
inject: false,
|
|
27
30
|
}),
|
|
28
31
|
],
|
|
29
32
|
external: [
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @type {import('tailwindcss').Config} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
content: [
|
|
4
|
+
"./src/**/*.{js,jsx,ts,tsx}",
|
|
5
|
+
"./src/components/**/*.{js,jsx,ts,tsx}",
|
|
6
|
+
],
|
|
7
|
+
theme: {
|
|
8
|
+
extend: {},
|
|
9
|
+
},
|
|
10
|
+
plugins: [],
|
|
11
|
+
corePlugins: {
|
|
12
|
+
preflight: false,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createNextJSHandler } from "./next-js";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import BetterStore from "@betterstore/sdk";
|
|
2
|
-
import { type NextRequest } from "next/server";
|
|
3
|
-
type NextjsRouteConfig = {
|
|
4
|
-
allowedOrigins?: string[];
|
|
5
|
-
};
|
|
6
|
-
type BSClient = InstanceType<typeof BetterStore>;
|
|
7
|
-
export declare function createNextJSHandler(betterStore: BSClient, config?: NextjsRouteConfig): {
|
|
8
|
-
GET(req: NextRequest): Promise<Response>;
|
|
9
|
-
POST(req: NextRequest): Promise<Response>;
|
|
10
|
-
PUT(req: NextRequest): Promise<Response>;
|
|
11
|
-
DELETE(req: NextRequest): Promise<Response>;
|
|
12
|
-
};
|
|
13
|
-
export {};
|
package/tailwind.config.js
DELETED
|
File without changes
|