@malawistore/store-sdk 0.1.1 → 0.1.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 +19 -0
- package/README.md +31 -3
- package/dist/index.cjs +108 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -10
- package/dist/index.d.ts +74 -10
- package/dist/index.js +108 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ interface StatusResponse {
|
|
|
32
32
|
interface PageParams {
|
|
33
33
|
/** 1-based page. Wins over `offset` when both are sent. */
|
|
34
34
|
page?: number;
|
|
35
|
-
/** Page size.
|
|
35
|
+
/** Page size. Storefront/shopper lists default to 12; admin user lists default to 20. Capped at 100. */
|
|
36
36
|
limit?: number;
|
|
37
37
|
/** Number of rows to skip. */
|
|
38
38
|
offset?: number;
|
|
@@ -290,6 +290,22 @@ interface AddCartItemInput {
|
|
|
290
290
|
variant_id?: string;
|
|
291
291
|
qty: number;
|
|
292
292
|
}
|
|
293
|
+
type CartSort = "oldest" | "newest" | "name_asc" | "name_desc" | "price_asc" | "price_desc" | "qty_asc" | "qty_desc";
|
|
294
|
+
interface ListCartParams extends PageParams {
|
|
295
|
+
/** Case-insensitive substring over line name and SKU. */
|
|
296
|
+
q?: string;
|
|
297
|
+
product_id?: string;
|
|
298
|
+
variant_id?: string;
|
|
299
|
+
sort?: CartSort;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Raw paged cart envelope returned by `getPage`. `data.subtotal_cents`
|
|
303
|
+
* always covers the whole cart; `meta` counts cart lines.
|
|
304
|
+
*/
|
|
305
|
+
interface CartResponse {
|
|
306
|
+
data: Cart;
|
|
307
|
+
meta: PaginationMeta;
|
|
308
|
+
}
|
|
293
309
|
|
|
294
310
|
interface Stock {
|
|
295
311
|
product_id: string;
|
|
@@ -340,6 +356,20 @@ interface Order {
|
|
|
340
356
|
/** ISO-8601 timestamp. */
|
|
341
357
|
created_at: string;
|
|
342
358
|
}
|
|
359
|
+
type OrderSort = "newest" | "oldest" | "total_asc" | "total_desc";
|
|
360
|
+
interface ListOrdersParams extends PageParams {
|
|
361
|
+
status?: OrderStatus;
|
|
362
|
+
currency?: string;
|
|
363
|
+
/** RFC3339 or YYYY-MM-DD. */
|
|
364
|
+
created_after?: string;
|
|
365
|
+
/** RFC3339 or YYYY-MM-DD; a date-only value includes the whole day. */
|
|
366
|
+
created_before?: string;
|
|
367
|
+
min_total_cents?: number;
|
|
368
|
+
max_total_cents?: number;
|
|
369
|
+
sort?: OrderSort;
|
|
370
|
+
}
|
|
371
|
+
/** Raw paged orders envelope returned by `listPage`. */
|
|
372
|
+
type OrderListResponse = Paginated<Order>;
|
|
343
373
|
|
|
344
374
|
type PaymentStatus = "pending" | "succeeded" | "failed" | "cancelled";
|
|
345
375
|
/**
|
|
@@ -360,6 +390,13 @@ interface Payment {
|
|
|
360
390
|
/** ISO-8601 timestamp. */
|
|
361
391
|
created_at: string;
|
|
362
392
|
}
|
|
393
|
+
/** A Stripe-hosted Checkout page for an order. */
|
|
394
|
+
interface CheckoutSession {
|
|
395
|
+
id: string;
|
|
396
|
+
order_id: string;
|
|
397
|
+
url: string;
|
|
398
|
+
expires_at: number;
|
|
399
|
+
}
|
|
363
400
|
|
|
364
401
|
/** Catalog snapshot embedded in a wishlist item. */
|
|
365
402
|
interface WishlistProduct {
|
|
@@ -376,6 +413,15 @@ interface WishlistItem {
|
|
|
376
413
|
/** ISO-8601 timestamp. */
|
|
377
414
|
added_at: string;
|
|
378
415
|
}
|
|
416
|
+
type WishlistSort = "newest" | "oldest" | "name_asc" | "name_desc" | "price_asc" | "price_desc";
|
|
417
|
+
interface ListWishlistParams extends PageParams {
|
|
418
|
+
/** Case-insensitive substring over product name and slug. */
|
|
419
|
+
q?: string;
|
|
420
|
+
category_id?: string;
|
|
421
|
+
sort?: WishlistSort;
|
|
422
|
+
}
|
|
423
|
+
/** Raw paged wishlist envelope returned by `listPage`. */
|
|
424
|
+
type WishlistListResponse = Paginated<WishlistItem>;
|
|
379
425
|
|
|
380
426
|
interface Review {
|
|
381
427
|
id: string;
|
|
@@ -393,6 +439,16 @@ interface ReviewSummary {
|
|
|
393
439
|
average: number;
|
|
394
440
|
count: number;
|
|
395
441
|
reviews: Review[];
|
|
442
|
+
/** Counters for the filtered review page (average/count are unfiltered). */
|
|
443
|
+
meta: PaginationMeta;
|
|
444
|
+
}
|
|
445
|
+
type ReviewSort = "newest" | "oldest" | "highest" | "lowest";
|
|
446
|
+
interface ListReviewsParams extends PageParams {
|
|
447
|
+
/** Case-insensitive substring over title, body and author. */
|
|
448
|
+
q?: string;
|
|
449
|
+
/** Only this rating (1-5). */
|
|
450
|
+
rating?: number;
|
|
451
|
+
sort?: ReviewSort;
|
|
396
452
|
}
|
|
397
453
|
interface CreateReviewInput {
|
|
398
454
|
/** 1–5. */
|
|
@@ -532,8 +588,10 @@ declare class AuthResource {
|
|
|
532
588
|
declare class CartResource {
|
|
533
589
|
private readonly http;
|
|
534
590
|
constructor(http: HttpClient);
|
|
535
|
-
/** Active cart, created empty on first use. */
|
|
536
|
-
get(): Promise<Cart>;
|
|
591
|
+
/** Active cart, created empty on first use (paging meta is dropped). */
|
|
592
|
+
get(params?: ListCartParams): Promise<Cart>;
|
|
593
|
+
/** Same as `get`, plus the `meta` paging counters. */
|
|
594
|
+
getPage(params?: ListCartParams): Promise<CartResponse>;
|
|
537
595
|
/** Validates against the catalog and snapshots the current price. */
|
|
538
596
|
addItem(input: AddCartItemInput): Promise<Cart>;
|
|
539
597
|
/** `qty: 0` removes the line. */
|
|
@@ -603,8 +661,10 @@ declare class OrdersResource {
|
|
|
603
661
|
* the cart.
|
|
604
662
|
*/
|
|
605
663
|
checkout(): Promise<Order>;
|
|
606
|
-
/** Newest first. */
|
|
607
|
-
list(): Promise<Order[]>;
|
|
664
|
+
/** Newest first (paging meta is dropped). */
|
|
665
|
+
list(params?: ListOrdersParams): Promise<Order[]>;
|
|
666
|
+
/** Same filters as `list`, plus the `meta` paging counters. */
|
|
667
|
+
listPage(params?: ListOrdersParams): Promise<OrderListResponse>;
|
|
608
668
|
get(id: string): Promise<Order>;
|
|
609
669
|
/** Pending orders only; releases the stock hold. */
|
|
610
670
|
cancel(id: string): Promise<Order>;
|
|
@@ -619,6 +679,8 @@ declare class PaymentsResource {
|
|
|
619
679
|
* orders. Send `payment.client_secret` to Stripe.js to confirm the card.
|
|
620
680
|
*/
|
|
621
681
|
createIntent(orderId: string): Promise<Payment>;
|
|
682
|
+
/** Creates a Stripe-hosted Checkout page and returns its URL. */
|
|
683
|
+
createCheckoutSession(orderId: string): Promise<CheckoutSession>;
|
|
622
684
|
}
|
|
623
685
|
|
|
624
686
|
declare class ProductsResource {
|
|
@@ -647,8 +709,8 @@ declare class ProductsResource {
|
|
|
647
709
|
declare class ReviewsResource {
|
|
648
710
|
private readonly http;
|
|
649
711
|
constructor(http: HttpClient);
|
|
650
|
-
/** Public aggregate plus
|
|
651
|
-
summary(productId: string): Promise<ReviewSummary>;
|
|
712
|
+
/** Public aggregate plus one filtered review page (`summary.meta`). */
|
|
713
|
+
summary(productId: string, params?: ListReviewsParams): Promise<ReviewSummary>;
|
|
652
714
|
/** One review per user per product. */
|
|
653
715
|
create(productId: string, input: CreateReviewInput): Promise<Review>;
|
|
654
716
|
/** Edits the caller's own review. */
|
|
@@ -689,8 +751,10 @@ declare class VariantsResource {
|
|
|
689
751
|
declare class WishlistResource {
|
|
690
752
|
private readonly http;
|
|
691
753
|
constructor(http: HttpClient);
|
|
692
|
-
/** Newest first. */
|
|
693
|
-
list(): Promise<WishlistItem[]>;
|
|
754
|
+
/** Newest first (paging meta is dropped). */
|
|
755
|
+
list(params?: ListWishlistParams): Promise<WishlistItem[]>;
|
|
756
|
+
/** Same filters as `list`, plus the `meta` paging counters. */
|
|
757
|
+
listPage(params?: ListWishlistParams): Promise<WishlistListResponse>;
|
|
694
758
|
/** Idempotent: re-hearting succeeds silently. */
|
|
695
759
|
add(productId: string): Promise<WishlistItem>;
|
|
696
760
|
/** `productId`, not the wishlist row ID. */
|
|
@@ -810,4 +874,4 @@ declare function verifyStripeSignature(options: VerifyStripeSignatureOptions): P
|
|
|
810
874
|
*/
|
|
811
875
|
declare function constructStripeEvent<T = Record<string, unknown>>(options: VerifyStripeSignatureOptions): Promise<StripeEvent<T>>;
|
|
812
876
|
|
|
813
|
-
export { type AddCartItemInput, type ApiEnvelope, type ApiErrorCode, type ApiErrorEnvelope, type AuthStatusResponse, type Cart, type CartLine, type Category, type CategoryListResponse, type CategorySort, type ClientErrorCode, type CreateCategoryInput, type CreateProductInput, type CreateReviewInput, type CreateVariantInput, type ErrorCode, type FetchLike, type GetStockParams, type HealthResponse, type ListCategoriesParams, type ListProductsParams, type ListUsersParams, type LoginInput, MalawiStore, MalawiStoreError, type MalawiStoreErrorInit, type MalawiStoreOptions, type Order, type OrderLine, type OrderStatus, type PageParams, type Paginated, type PaginationMeta, type PasswordResetInput, type Payment, type PaymentStatus, type Product, type ProductDetail, type ProductListResponse, type ProductSort, type ProductVariantView, type QueryParams, type QueryScalar, type QueryValue, type RegisterInput, type RequestOptions, type ReserveLineInput, type ReserveStockInput, type RetryOptions, type Review, type ReviewSummary, type Role, type SetRoleInput, type SetStockInput, type StatusResponse, type Stock, type StripeEvent, type TokenPair, type TokenState, type UpdateCategoryInput, type UpdateProductInput, type UpdateReviewInput, type UpdateVariantInput, type UploadData, type UploadFile, type User, type UserListResponse, type UserSort, type Variant, type VerifyEmailInput, type VerifyStripeSignatureOptions, type WishlistItem, type WishlistProduct, buildQuery, constructStripeEvent, createUploadForm, isMalawiStoreError, verifyStripeSignature };
|
|
877
|
+
export { type AddCartItemInput, type ApiEnvelope, type ApiErrorCode, type ApiErrorEnvelope, type AuthStatusResponse, type Cart, type CartLine, type CartResponse, type CartSort, type Category, type CategoryListResponse, type CategorySort, type CheckoutSession, type ClientErrorCode, type CreateCategoryInput, type CreateProductInput, type CreateReviewInput, type CreateVariantInput, type ErrorCode, type FetchLike, type GetStockParams, type HealthResponse, type ListCartParams, type ListCategoriesParams, type ListOrdersParams, type ListProductsParams, type ListReviewsParams, type ListUsersParams, type ListWishlistParams, type LoginInput, MalawiStore, MalawiStoreError, type MalawiStoreErrorInit, type MalawiStoreOptions, type Order, type OrderLine, type OrderListResponse, type OrderSort, type OrderStatus, type PageParams, type Paginated, type PaginationMeta, type PasswordResetInput, type Payment, type PaymentStatus, type Product, type ProductDetail, type ProductListResponse, type ProductSort, type ProductVariantView, type QueryParams, type QueryScalar, type QueryValue, type RegisterInput, type RequestOptions, type ReserveLineInput, type ReserveStockInput, type RetryOptions, type Review, type ReviewSort, type ReviewSummary, type Role, type SetRoleInput, type SetStockInput, type StatusResponse, type Stock, type StripeEvent, type TokenPair, type TokenState, type UpdateCategoryInput, type UpdateProductInput, type UpdateReviewInput, type UpdateVariantInput, type UploadData, type UploadFile, type User, type UserListResponse, type UserSort, type Variant, type VerifyEmailInput, type VerifyStripeSignatureOptions, type WishlistItem, type WishlistListResponse, type WishlistProduct, type WishlistSort, buildQuery, constructStripeEvent, createUploadForm, isMalawiStoreError, verifyStripeSignature };
|
package/dist/index.js
CHANGED
|
@@ -442,9 +442,34 @@ var CartResource = class {
|
|
|
442
442
|
this.http = http;
|
|
443
443
|
}
|
|
444
444
|
http;
|
|
445
|
-
/** Active cart, created empty on first use. */
|
|
446
|
-
get() {
|
|
447
|
-
return this.http.request("GET", "/cart"
|
|
445
|
+
/** Active cart, created empty on first use (paging meta is dropped). */
|
|
446
|
+
get(params = {}) {
|
|
447
|
+
return this.http.request("GET", "/cart", {
|
|
448
|
+
query: {
|
|
449
|
+
q: params.q,
|
|
450
|
+
product_id: params.product_id,
|
|
451
|
+
variant_id: params.variant_id,
|
|
452
|
+
sort: params.sort,
|
|
453
|
+
page: params.page,
|
|
454
|
+
limit: params.limit,
|
|
455
|
+
offset: params.offset
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
/** Same as `get`, plus the `meta` paging counters. */
|
|
460
|
+
getPage(params = {}) {
|
|
461
|
+
return this.http.request("GET", "/cart", {
|
|
462
|
+
query: {
|
|
463
|
+
q: params.q,
|
|
464
|
+
product_id: params.product_id,
|
|
465
|
+
variant_id: params.variant_id,
|
|
466
|
+
sort: params.sort,
|
|
467
|
+
page: params.page,
|
|
468
|
+
limit: params.limit,
|
|
469
|
+
offset: params.offset
|
|
470
|
+
},
|
|
471
|
+
unwrap: false
|
|
472
|
+
});
|
|
448
473
|
}
|
|
449
474
|
/** Validates against the catalog and snapshots the current price. */
|
|
450
475
|
addItem(input) {
|
|
@@ -643,9 +668,40 @@ var OrdersResource = class {
|
|
|
643
668
|
retry: false
|
|
644
669
|
});
|
|
645
670
|
}
|
|
646
|
-
/** Newest first. */
|
|
647
|
-
list() {
|
|
648
|
-
return this.http.request("GET", "/orders"
|
|
671
|
+
/** Newest first (paging meta is dropped). */
|
|
672
|
+
list(params = {}) {
|
|
673
|
+
return this.http.request("GET", "/orders", {
|
|
674
|
+
query: {
|
|
675
|
+
status: params.status,
|
|
676
|
+
currency: params.currency,
|
|
677
|
+
created_after: params.created_after,
|
|
678
|
+
created_before: params.created_before,
|
|
679
|
+
min_total_cents: params.min_total_cents,
|
|
680
|
+
max_total_cents: params.max_total_cents,
|
|
681
|
+
sort: params.sort,
|
|
682
|
+
page: params.page,
|
|
683
|
+
limit: params.limit,
|
|
684
|
+
offset: params.offset
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
/** Same filters as `list`, plus the `meta` paging counters. */
|
|
689
|
+
listPage(params = {}) {
|
|
690
|
+
return this.http.request("GET", "/orders", {
|
|
691
|
+
query: {
|
|
692
|
+
status: params.status,
|
|
693
|
+
currency: params.currency,
|
|
694
|
+
created_after: params.created_after,
|
|
695
|
+
created_before: params.created_before,
|
|
696
|
+
min_total_cents: params.min_total_cents,
|
|
697
|
+
max_total_cents: params.max_total_cents,
|
|
698
|
+
sort: params.sort,
|
|
699
|
+
page: params.page,
|
|
700
|
+
limit: params.limit,
|
|
701
|
+
offset: params.offset
|
|
702
|
+
},
|
|
703
|
+
unwrap: false
|
|
704
|
+
});
|
|
649
705
|
}
|
|
650
706
|
get(id) {
|
|
651
707
|
return this.http.request("GET", `/orders/${segment(id)}`);
|
|
@@ -676,6 +732,13 @@ var PaymentsResource = class {
|
|
|
676
732
|
retry: false
|
|
677
733
|
});
|
|
678
734
|
}
|
|
735
|
+
/** Creates a Stripe-hosted Checkout page and returns its URL. */
|
|
736
|
+
createCheckoutSession(orderId) {
|
|
737
|
+
return this.http.request("POST", "/payments/checkout-sessions", {
|
|
738
|
+
body: { order_id: orderId },
|
|
739
|
+
retry: false
|
|
740
|
+
});
|
|
741
|
+
}
|
|
679
742
|
};
|
|
680
743
|
|
|
681
744
|
// src/resources/products.ts
|
|
@@ -788,12 +851,22 @@ var ReviewsResource = class {
|
|
|
788
851
|
this.http = http;
|
|
789
852
|
}
|
|
790
853
|
http;
|
|
791
|
-
/** Public aggregate plus
|
|
792
|
-
summary(productId) {
|
|
854
|
+
/** Public aggregate plus one filtered review page (`summary.meta`). */
|
|
855
|
+
summary(productId, params = {}) {
|
|
793
856
|
return this.http.request(
|
|
794
857
|
"GET",
|
|
795
858
|
`/products/${segment(productId)}/reviews`,
|
|
796
|
-
{
|
|
859
|
+
{
|
|
860
|
+
query: {
|
|
861
|
+
q: params.q,
|
|
862
|
+
rating: params.rating,
|
|
863
|
+
sort: params.sort,
|
|
864
|
+
page: params.page,
|
|
865
|
+
limit: params.limit,
|
|
866
|
+
offset: params.offset
|
|
867
|
+
},
|
|
868
|
+
skipAuth: true
|
|
869
|
+
}
|
|
797
870
|
);
|
|
798
871
|
}
|
|
799
872
|
/** One review per user per product. */
|
|
@@ -929,9 +1002,32 @@ var WishlistResource = class {
|
|
|
929
1002
|
this.http = http;
|
|
930
1003
|
}
|
|
931
1004
|
http;
|
|
932
|
-
/** Newest first. */
|
|
933
|
-
list() {
|
|
934
|
-
return this.http.request("GET", "/wishlist"
|
|
1005
|
+
/** Newest first (paging meta is dropped). */
|
|
1006
|
+
list(params = {}) {
|
|
1007
|
+
return this.http.request("GET", "/wishlist", {
|
|
1008
|
+
query: {
|
|
1009
|
+
q: params.q,
|
|
1010
|
+
category_id: params.category_id,
|
|
1011
|
+
sort: params.sort,
|
|
1012
|
+
page: params.page,
|
|
1013
|
+
limit: params.limit,
|
|
1014
|
+
offset: params.offset
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
/** Same filters as `list`, plus the `meta` paging counters. */
|
|
1019
|
+
listPage(params = {}) {
|
|
1020
|
+
return this.http.request("GET", "/wishlist", {
|
|
1021
|
+
query: {
|
|
1022
|
+
q: params.q,
|
|
1023
|
+
category_id: params.category_id,
|
|
1024
|
+
sort: params.sort,
|
|
1025
|
+
page: params.page,
|
|
1026
|
+
limit: params.limit,
|
|
1027
|
+
offset: params.offset
|
|
1028
|
+
},
|
|
1029
|
+
unwrap: false
|
|
1030
|
+
});
|
|
935
1031
|
}
|
|
936
1032
|
/** Idempotent: re-hearting succeeds silently. */
|
|
937
1033
|
add(productId) {
|