@cimplify/sdk 0.68.0 → 0.70.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/advanced.d.mts +1 -1
- package/dist/advanced.d.ts +1 -1
- package/dist/advanced.js +20 -20
- package/dist/advanced.mjs +1 -1
- package/dist/{chunk-TAKORJP4.mjs → chunk-6XXVA3IV.mjs} +2 -2
- package/dist/{chunk-WCSAZRNC.js → chunk-BCWPRPK7.js} +10 -0
- package/dist/{chunk-KNPE4WCQ.mjs → chunk-EAVXSFAB.mjs} +1 -1
- package/dist/{chunk-SXGFJEME.js → chunk-I4MP2XZS.js} +73 -7
- package/dist/{chunk-SOV4H6PQ.mjs → chunk-M2CXZQHS.mjs} +10 -0
- package/dist/{chunk-FVGVJ4TC.mjs → chunk-O3ECKVOM.mjs} +73 -7
- package/dist/{chunk-5HAUJBOK.js → chunk-QZQEGRGB.js} +35 -35
- package/dist/{chunk-NGQCWFKF.js → chunk-SC5DUKGD.js} +4 -4
- package/dist/{client-CBE7ksYC.d.mts → client-BRGGjeny.d.mts} +1 -1
- package/dist/{client-Dyo3dvNy.d.mts → client-DRJvXz54.d.mts} +181 -21
- package/dist/{client-DlXfZy7N.d.ts → client-Des_GqmQ.d.ts} +1 -1
- package/dist/{client-CfeQRwhl.d.ts → client-DjQhg6yr.d.ts} +181 -21
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +68 -68
- package/dist/index.mjs +3 -3
- package/dist/mock/cli.mjs +73 -7
- package/dist/mock/library.js +73 -7
- package/dist/mock/library.mjs +73 -7
- package/dist/mock/msw.js +73 -7
- package/dist/mock/msw.mjs +73 -7
- package/dist/react.d.mts +166 -2
- package/dist/react.d.ts +166 -2
- package/dist/react.js +1223 -493
- package/dist/react.mjs +801 -79
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +7 -7
- package/dist/server.mjs +2 -2
- package/dist/styles.css +1 -1
- package/dist/testing/msw.js +2 -2
- package/dist/testing/msw.mjs +1 -1
- package/dist/testing/suite.d.mts +2 -2
- package/dist/testing/suite.d.ts +2 -2
- package/dist/testing/suite.js +23 -23
- package/dist/testing/suite.mjs +4 -4
- package/dist/testing.d.mts +2 -2
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +79 -79
- package/dist/testing.mjs +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -124,7 +124,8 @@ import {
|
|
|
124
124
|
ProductPage,
|
|
125
125
|
CartPage,
|
|
126
126
|
CheckoutPage,
|
|
127
|
-
|
|
127
|
+
AccountDashboardPage,
|
|
128
|
+
AccountOrdersPage,
|
|
128
129
|
useCart,
|
|
129
130
|
useCartDrawer,
|
|
130
131
|
} from "@cimplify/sdk/react";
|
|
@@ -141,7 +142,7 @@ function Root({ children }) {
|
|
|
141
142
|
}
|
|
142
143
|
```
|
|
143
144
|
|
|
144
|
-
90+ components ship — variant-aware product cards, customizers (variant / add-on / bundle / composite / billing-plan / customer-input / scheduling), full pages (`<CataloguePage>`, `<ProductPage>`, `<CartPage>`, `<CheckoutPage>`, `<SearchPage>`, `<
|
|
145
|
+
90+ components ship — variant-aware product cards, customizers (variant / add-on / bundle / composite / billing-plan / customer-input / scheduling), full pages (`<CataloguePage>`, `<ProductPage>`, `<CartPage>`, `<CheckoutPage>`, `<SearchPage>`, `<AccountDashboardPage>`, `<AccountOrdersPage>`), cart drawer with free-shipping progress, primitives (`<Price>`, `<QuantitySelector>`, `<DealBanner>`, `<DeliveryEstimate>`, `<ChatWidget>`).
|
|
145
146
|
|
|
146
147
|
## Server Components (Next.js App Router)
|
|
147
148
|
|
package/dist/advanced.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { k as AuthService,
|
|
1
|
+
export { k as AuthService, C as BusinessService, P as CartOperations, Q as CatalogueQueries, a9 as CheckoutOperations, a9 as CheckoutService, af as CimplifyElement, ag as CimplifyElements, aF as ELEMENT_TYPES, aG as EVENT_TYPES, aJ as ElementEventType, aK as ElementOptions, aL as ElementType, aT as ElementsOptions, a$ as FetchQuoteInput, b7 as FxService, ba as GetProductsOptions, bd as InventoryService, bk as LinkService, bo as LiteService, bv as MESSAGE_TYPES, bY as OrderQueries, cf as PriceQuote, cl as QuoteBundleSelectionInput, cm as QuoteCompositeSelectionInput, cn as QuoteDynamicBuckets, co as QuoteStatus, cp as QuoteUiMessage, cr as RefreshQuoteInput, cs as RefreshQuoteResult, cT as SchedulingService, dw as createElements } from './client-DRJvXz54.mjs';
|
|
2
2
|
import './product-B_kS4Oxa.mjs';
|
|
3
3
|
import './payment-DVS7ZUEp.mjs';
|
|
4
4
|
|
package/dist/advanced.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { k as AuthService,
|
|
1
|
+
export { k as AuthService, C as BusinessService, P as CartOperations, Q as CatalogueQueries, a9 as CheckoutOperations, a9 as CheckoutService, af as CimplifyElement, ag as CimplifyElements, aF as ELEMENT_TYPES, aG as EVENT_TYPES, aJ as ElementEventType, aK as ElementOptions, aL as ElementType, aT as ElementsOptions, a$ as FetchQuoteInput, b7 as FxService, ba as GetProductsOptions, bd as InventoryService, bk as LinkService, bo as LiteService, bv as MESSAGE_TYPES, bY as OrderQueries, cf as PriceQuote, cl as QuoteBundleSelectionInput, cm as QuoteCompositeSelectionInput, cn as QuoteDynamicBuckets, co as QuoteStatus, cp as QuoteUiMessage, cr as RefreshQuoteInput, cs as RefreshQuoteResult, cT as SchedulingService, dw as createElements } from './client-DjQhg6yr.js';
|
|
2
2
|
import './product-B_kS4Oxa.js';
|
|
3
3
|
import './payment-sn-yGL7v.js';
|
|
4
4
|
|
package/dist/advanced.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkBCWPRPK7_js = require('./chunk-BCWPRPK7.js');
|
|
4
4
|
require('./chunk-7Y2O3E4D.js');
|
|
5
5
|
require('./chunk-XA3ZNR75.js');
|
|
6
6
|
require('./chunk-OWW5GUSB.js');
|
|
@@ -9,77 +9,77 @@ require('./chunk-OWW5GUSB.js');
|
|
|
9
9
|
|
|
10
10
|
Object.defineProperty(exports, "AuthService", {
|
|
11
11
|
enumerable: true,
|
|
12
|
-
get: function () { return
|
|
12
|
+
get: function () { return chunkBCWPRPK7_js.AuthService; }
|
|
13
13
|
});
|
|
14
14
|
Object.defineProperty(exports, "BusinessService", {
|
|
15
15
|
enumerable: true,
|
|
16
|
-
get: function () { return
|
|
16
|
+
get: function () { return chunkBCWPRPK7_js.BusinessService; }
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "CartOperations", {
|
|
19
19
|
enumerable: true,
|
|
20
|
-
get: function () { return
|
|
20
|
+
get: function () { return chunkBCWPRPK7_js.CartOperations; }
|
|
21
21
|
});
|
|
22
22
|
Object.defineProperty(exports, "CatalogueQueries", {
|
|
23
23
|
enumerable: true,
|
|
24
|
-
get: function () { return
|
|
24
|
+
get: function () { return chunkBCWPRPK7_js.CatalogueQueries; }
|
|
25
25
|
});
|
|
26
26
|
Object.defineProperty(exports, "CheckoutOperations", {
|
|
27
27
|
enumerable: true,
|
|
28
|
-
get: function () { return
|
|
28
|
+
get: function () { return chunkBCWPRPK7_js.CheckoutService; }
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(exports, "CheckoutService", {
|
|
31
31
|
enumerable: true,
|
|
32
|
-
get: function () { return
|
|
32
|
+
get: function () { return chunkBCWPRPK7_js.CheckoutService; }
|
|
33
33
|
});
|
|
34
34
|
Object.defineProperty(exports, "CimplifyElement", {
|
|
35
35
|
enumerable: true,
|
|
36
|
-
get: function () { return
|
|
36
|
+
get: function () { return chunkBCWPRPK7_js.CimplifyElement; }
|
|
37
37
|
});
|
|
38
38
|
Object.defineProperty(exports, "CimplifyElements", {
|
|
39
39
|
enumerable: true,
|
|
40
|
-
get: function () { return
|
|
40
|
+
get: function () { return chunkBCWPRPK7_js.CimplifyElements; }
|
|
41
41
|
});
|
|
42
42
|
Object.defineProperty(exports, "ELEMENT_TYPES", {
|
|
43
43
|
enumerable: true,
|
|
44
|
-
get: function () { return
|
|
44
|
+
get: function () { return chunkBCWPRPK7_js.ELEMENT_TYPES; }
|
|
45
45
|
});
|
|
46
46
|
Object.defineProperty(exports, "EVENT_TYPES", {
|
|
47
47
|
enumerable: true,
|
|
48
|
-
get: function () { return
|
|
48
|
+
get: function () { return chunkBCWPRPK7_js.EVENT_TYPES; }
|
|
49
49
|
});
|
|
50
50
|
Object.defineProperty(exports, "FxService", {
|
|
51
51
|
enumerable: true,
|
|
52
|
-
get: function () { return
|
|
52
|
+
get: function () { return chunkBCWPRPK7_js.FxService; }
|
|
53
53
|
});
|
|
54
54
|
Object.defineProperty(exports, "InventoryService", {
|
|
55
55
|
enumerable: true,
|
|
56
|
-
get: function () { return
|
|
56
|
+
get: function () { return chunkBCWPRPK7_js.InventoryService; }
|
|
57
57
|
});
|
|
58
58
|
Object.defineProperty(exports, "LinkService", {
|
|
59
59
|
enumerable: true,
|
|
60
|
-
get: function () { return
|
|
60
|
+
get: function () { return chunkBCWPRPK7_js.LinkService; }
|
|
61
61
|
});
|
|
62
62
|
Object.defineProperty(exports, "LiteService", {
|
|
63
63
|
enumerable: true,
|
|
64
|
-
get: function () { return
|
|
64
|
+
get: function () { return chunkBCWPRPK7_js.LiteService; }
|
|
65
65
|
});
|
|
66
66
|
Object.defineProperty(exports, "MESSAGE_TYPES", {
|
|
67
67
|
enumerable: true,
|
|
68
|
-
get: function () { return
|
|
68
|
+
get: function () { return chunkBCWPRPK7_js.MESSAGE_TYPES; }
|
|
69
69
|
});
|
|
70
70
|
Object.defineProperty(exports, "OrderQueries", {
|
|
71
71
|
enumerable: true,
|
|
72
|
-
get: function () { return
|
|
72
|
+
get: function () { return chunkBCWPRPK7_js.OrderQueries; }
|
|
73
73
|
});
|
|
74
74
|
Object.defineProperty(exports, "SchedulingService", {
|
|
75
75
|
enumerable: true,
|
|
76
|
-
get: function () { return
|
|
76
|
+
get: function () { return chunkBCWPRPK7_js.SchedulingService; }
|
|
77
77
|
});
|
|
78
78
|
Object.defineProperty(exports, "createElements", {
|
|
79
79
|
enumerable: true,
|
|
80
|
-
get: function () { return
|
|
80
|
+
get: function () { return chunkBCWPRPK7_js.createElements; }
|
|
81
81
|
});
|
|
82
82
|
Object.defineProperty(exports, "generateIdempotencyKey", {
|
|
83
83
|
enumerable: true,
|
|
84
|
-
get: function () { return
|
|
84
|
+
get: function () { return chunkBCWPRPK7_js.generateIdempotencyKey; }
|
|
85
85
|
});
|
package/dist/advanced.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AuthService, BusinessService, CartOperations, CatalogueQueries, CheckoutService as CheckoutOperations, CheckoutService, CimplifyElement, CimplifyElements, ELEMENT_TYPES, EVENT_TYPES, FxService, InventoryService, LinkService, LiteService, MESSAGE_TYPES, OrderQueries, SchedulingService, createElements, generateIdempotencyKey } from './chunk-
|
|
1
|
+
export { AuthService, BusinessService, CartOperations, CatalogueQueries, CheckoutService as CheckoutOperations, CheckoutService, CimplifyElement, CimplifyElements, ELEMENT_TYPES, EVENT_TYPES, FxService, InventoryService, LinkService, LiteService, MESSAGE_TYPES, OrderQueries, SchedulingService, createElements, generateIdempotencyKey } from './chunk-M2CXZQHS.mjs';
|
|
2
2
|
import './chunk-TD3AY34U.mjs';
|
|
3
3
|
import './chunk-AMZXALF6.mjs';
|
|
4
4
|
import './chunk-3G6RQLXK.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createMockApp } from './chunk-
|
|
2
|
-
import { createCimplifyClient } from './chunk-
|
|
1
|
+
import { createMockApp } from './chunk-O3ECKVOM.mjs';
|
|
2
|
+
import { createCimplifyClient } from './chunk-EAVXSFAB.mjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
var cimplifyRegistry = z.registry();
|
|
@@ -1722,6 +1722,16 @@ var OrderQueries = class {
|
|
|
1722
1722
|
const tokenParam = this.orderTokenParam(orderId);
|
|
1723
1723
|
return safe(this.client.get(`/api/v1/orders/${encodedId}${tokenParam}`));
|
|
1724
1724
|
}
|
|
1725
|
+
/**
|
|
1726
|
+
* Same endpoint as `get`, typed as the enriched display contract
|
|
1727
|
+
* (product names, images, resolved selections, customer inputs, scheduling,
|
|
1728
|
+
* fulfillment). Feed the result through `toAccountOrderView`.
|
|
1729
|
+
*/
|
|
1730
|
+
async getDetail(orderId) {
|
|
1731
|
+
const encodedId = encodeURIComponent(orderId);
|
|
1732
|
+
const tokenParam = this.orderTokenParam(orderId);
|
|
1733
|
+
return safe(this.client.get(`/api/v1/orders/${encodedId}${tokenParam}`));
|
|
1734
|
+
}
|
|
1725
1735
|
async getRecent(limit = 5) {
|
|
1726
1736
|
return this.list({ limit });
|
|
1727
1737
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { safe, generateIdempotencyKey, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-
|
|
1
|
+
import { safe, generateIdempotencyKey, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-M2CXZQHS.mjs';
|
|
2
2
|
import { CimplifyError, ErrorCode, IdempotencyMismatchError, enrichError } from './chunk-AMZXALF6.mjs';
|
|
3
3
|
|
|
4
4
|
// src/activity.ts
|
|
@@ -2341,23 +2341,47 @@ function buildV1(deps) {
|
|
|
2341
2341
|
app.get("/auth/status", (c) => tryRoute(c, () => deps.auth.status(c.var.session.token)));
|
|
2342
2342
|
app.post("/auth/request-otp", async (c) => {
|
|
2343
2343
|
const body = await c.req.json().catch(() => ({}));
|
|
2344
|
-
return tryRoute(c, () =>
|
|
2344
|
+
return tryRoute(c, () => {
|
|
2345
|
+
deps.auth.requestOtp(body.contact ?? "");
|
|
2346
|
+
return {
|
|
2347
|
+
message: `OTP sent to ${body.contact ?? "contact"}`,
|
|
2348
|
+
expires_in: 300,
|
|
2349
|
+
is_new_account: false
|
|
2350
|
+
};
|
|
2351
|
+
});
|
|
2345
2352
|
});
|
|
2346
2353
|
app.post("/auth/verify-otp", async (c) => {
|
|
2347
2354
|
const body = await c.req.json().catch(() => ({}));
|
|
2348
2355
|
return tryRoute(c, () => {
|
|
2349
2356
|
const session = deps.auth.verifyOtp(body.contact ?? "", body.otp_code ?? body.code ?? "");
|
|
2350
2357
|
c.header("x-session-token", session.token);
|
|
2351
|
-
return {
|
|
2358
|
+
return {
|
|
2359
|
+
message: "Successfully authenticated",
|
|
2360
|
+
account_id: session.id,
|
|
2361
|
+
session_token: session.token,
|
|
2362
|
+
refresh_token: session.token,
|
|
2363
|
+
customer: {
|
|
2364
|
+
id: session.customer_id ?? session.id,
|
|
2365
|
+
name: session.customer_name ?? "Test User",
|
|
2366
|
+
email: session.customer_email ?? null,
|
|
2367
|
+
phone: session.customer_phone ?? null,
|
|
2368
|
+
delivery_address: null,
|
|
2369
|
+
created_at: session.created_at,
|
|
2370
|
+
updated_at: session.created_at
|
|
2371
|
+
}
|
|
2372
|
+
};
|
|
2352
2373
|
});
|
|
2353
2374
|
});
|
|
2354
2375
|
app.post("/auth/logout", (c) => {
|
|
2355
2376
|
deps.auth.logout(c.var.session.token);
|
|
2356
|
-
return ok(c, {
|
|
2377
|
+
return ok(c, { message: "Successfully logged out", action: "discard_token" });
|
|
2357
2378
|
});
|
|
2358
2379
|
app.post("/auth/profile", async (c) => {
|
|
2359
2380
|
const body = await c.req.json().catch(() => ({}));
|
|
2360
|
-
return tryRoute(c, () =>
|
|
2381
|
+
return tryRoute(c, () => {
|
|
2382
|
+
deps.auth.updateProfile(c.var.session.token, body);
|
|
2383
|
+
return { success: true, message: "Profile updated successfully" };
|
|
2384
|
+
});
|
|
2361
2385
|
});
|
|
2362
2386
|
app.get("/inventory/products/:product_id/stock", (c) => tryRoute(c, () => deps.inventory.productStock(c.req.param("product_id"))));
|
|
2363
2387
|
app.get("/inventory/variants/:variant_id/stock", (c) => tryRoute(c, () => deps.inventory.variantStock(c.req.param("variant_id"))));
|
|
@@ -2979,7 +3003,12 @@ function buildLink(deps) {
|
|
|
2979
3003
|
const body = await c.req.json().catch(() => ({}));
|
|
2980
3004
|
return tryRoute(c, () => {
|
|
2981
3005
|
deps.auth.requestOtp(body.contact ?? "");
|
|
2982
|
-
return {
|
|
3006
|
+
return {
|
|
3007
|
+
success: true,
|
|
3008
|
+
message: `OTP sent to ${body.contact ?? "contact"}`,
|
|
3009
|
+
expires_in: 300,
|
|
3010
|
+
is_new_account: false
|
|
3011
|
+
};
|
|
2983
3012
|
});
|
|
2984
3013
|
});
|
|
2985
3014
|
app.post("/auth/verify-otp", async (c) => {
|
|
@@ -2997,7 +3026,29 @@ function buildLink(deps) {
|
|
|
2997
3026
|
refresh_token: session.token,
|
|
2998
3027
|
account_id: session.id,
|
|
2999
3028
|
customer_id: customer.customer.id,
|
|
3000
|
-
|
|
3029
|
+
name: customer.customer.name,
|
|
3030
|
+
email: customer.customer.email,
|
|
3031
|
+
phone: customer.customer.phone,
|
|
3032
|
+
message: "Login successful"
|
|
3033
|
+
};
|
|
3034
|
+
});
|
|
3035
|
+
});
|
|
3036
|
+
app.post("/auth/refresh", async (c) => {
|
|
3037
|
+
const body = await c.req.json().catch(() => ({}));
|
|
3038
|
+
return tryRoute(c, () => {
|
|
3039
|
+
const session = deps.auth.ensureSession(body.session_token ?? c.var.session.token);
|
|
3040
|
+
const customer = deps.link.ensureCustomer(session.customer_id ?? session.id);
|
|
3041
|
+
c.header("x-session-token", session.token);
|
|
3042
|
+
return {
|
|
3043
|
+
success: true,
|
|
3044
|
+
session_token: session.token,
|
|
3045
|
+
refresh_token: session.token,
|
|
3046
|
+
account_id: session.id,
|
|
3047
|
+
customer_id: customer.customer.id,
|
|
3048
|
+
name: customer.customer.name,
|
|
3049
|
+
email: customer.customer.email,
|
|
3050
|
+
phone: customer.customer.phone,
|
|
3051
|
+
message: "Session refreshed"
|
|
3001
3052
|
};
|
|
3002
3053
|
});
|
|
3003
3054
|
});
|
|
@@ -3005,9 +3056,24 @@ function buildLink(deps) {
|
|
|
3005
3056
|
"/auth/logout",
|
|
3006
3057
|
(c) => tryRoute(c, () => {
|
|
3007
3058
|
deps.auth.logout(c.var.session.token);
|
|
3008
|
-
return { success: true, message: "Logged out" };
|
|
3059
|
+
return { success: true, message: "Logged out successfully", action: "discard_token" };
|
|
3009
3060
|
})
|
|
3010
3061
|
);
|
|
3062
|
+
app.get("/profile", (c) => tryRoute(c, () => deps.link.getProfile(customerId(c))));
|
|
3063
|
+
app.post("/profile", async (c) => {
|
|
3064
|
+
const body = await c.req.json().catch(() => ({}));
|
|
3065
|
+
return tryRoute(c, () => {
|
|
3066
|
+
const state = deps.link.ensureCustomer(customerId(c));
|
|
3067
|
+
state.customer = {
|
|
3068
|
+
...state.customer,
|
|
3069
|
+
name: body.name ?? state.customer.name,
|
|
3070
|
+
email: body.email ?? state.customer.email,
|
|
3071
|
+
phone: body.phone ?? state.customer.phone,
|
|
3072
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
3073
|
+
};
|
|
3074
|
+
return state.customer;
|
|
3075
|
+
});
|
|
3076
|
+
});
|
|
3011
3077
|
app.get("/data", (c) => tryRoute(c, () => deps.link.getLinkData(customerId(c))));
|
|
3012
3078
|
app.post("/check-status", async (c) => {
|
|
3013
3079
|
const body = await c.req.json().catch(() => ({}));
|
|
@@ -1720,6 +1720,16 @@ var OrderQueries = class {
|
|
|
1720
1720
|
const tokenParam = this.orderTokenParam(orderId);
|
|
1721
1721
|
return safe(this.client.get(`/api/v1/orders/${encodedId}${tokenParam}`));
|
|
1722
1722
|
}
|
|
1723
|
+
/**
|
|
1724
|
+
* Same endpoint as `get`, typed as the enriched display contract
|
|
1725
|
+
* (product names, images, resolved selections, customer inputs, scheduling,
|
|
1726
|
+
* fulfillment). Feed the result through `toAccountOrderView`.
|
|
1727
|
+
*/
|
|
1728
|
+
async getDetail(orderId) {
|
|
1729
|
+
const encodedId = encodeURIComponent(orderId);
|
|
1730
|
+
const tokenParam = this.orderTokenParam(orderId);
|
|
1731
|
+
return safe(this.client.get(`/api/v1/orders/${encodedId}${tokenParam}`));
|
|
1732
|
+
}
|
|
1723
1733
|
async getRecent(limit = 5) {
|
|
1724
1734
|
return this.list({ limit });
|
|
1725
1735
|
}
|
|
@@ -2339,23 +2339,47 @@ function buildV1(deps) {
|
|
|
2339
2339
|
app.get("/auth/status", (c) => tryRoute(c, () => deps.auth.status(c.var.session.token)));
|
|
2340
2340
|
app.post("/auth/request-otp", async (c) => {
|
|
2341
2341
|
const body = await c.req.json().catch(() => ({}));
|
|
2342
|
-
return tryRoute(c, () =>
|
|
2342
|
+
return tryRoute(c, () => {
|
|
2343
|
+
deps.auth.requestOtp(body.contact ?? "");
|
|
2344
|
+
return {
|
|
2345
|
+
message: `OTP sent to ${body.contact ?? "contact"}`,
|
|
2346
|
+
expires_in: 300,
|
|
2347
|
+
is_new_account: false
|
|
2348
|
+
};
|
|
2349
|
+
});
|
|
2343
2350
|
});
|
|
2344
2351
|
app.post("/auth/verify-otp", async (c) => {
|
|
2345
2352
|
const body = await c.req.json().catch(() => ({}));
|
|
2346
2353
|
return tryRoute(c, () => {
|
|
2347
2354
|
const session = deps.auth.verifyOtp(body.contact ?? "", body.otp_code ?? body.code ?? "");
|
|
2348
2355
|
c.header("x-session-token", session.token);
|
|
2349
|
-
return {
|
|
2356
|
+
return {
|
|
2357
|
+
message: "Successfully authenticated",
|
|
2358
|
+
account_id: session.id,
|
|
2359
|
+
session_token: session.token,
|
|
2360
|
+
refresh_token: session.token,
|
|
2361
|
+
customer: {
|
|
2362
|
+
id: session.customer_id ?? session.id,
|
|
2363
|
+
name: session.customer_name ?? "Test User",
|
|
2364
|
+
email: session.customer_email ?? null,
|
|
2365
|
+
phone: session.customer_phone ?? null,
|
|
2366
|
+
delivery_address: null,
|
|
2367
|
+
created_at: session.created_at,
|
|
2368
|
+
updated_at: session.created_at
|
|
2369
|
+
}
|
|
2370
|
+
};
|
|
2350
2371
|
});
|
|
2351
2372
|
});
|
|
2352
2373
|
app.post("/auth/logout", (c) => {
|
|
2353
2374
|
deps.auth.logout(c.var.session.token);
|
|
2354
|
-
return ok(c, {
|
|
2375
|
+
return ok(c, { message: "Successfully logged out", action: "discard_token" });
|
|
2355
2376
|
});
|
|
2356
2377
|
app.post("/auth/profile", async (c) => {
|
|
2357
2378
|
const body = await c.req.json().catch(() => ({}));
|
|
2358
|
-
return tryRoute(c, () =>
|
|
2379
|
+
return tryRoute(c, () => {
|
|
2380
|
+
deps.auth.updateProfile(c.var.session.token, body);
|
|
2381
|
+
return { success: true, message: "Profile updated successfully" };
|
|
2382
|
+
});
|
|
2359
2383
|
});
|
|
2360
2384
|
app.get("/inventory/products/:product_id/stock", (c) => tryRoute(c, () => deps.inventory.productStock(c.req.param("product_id"))));
|
|
2361
2385
|
app.get("/inventory/variants/:variant_id/stock", (c) => tryRoute(c, () => deps.inventory.variantStock(c.req.param("variant_id"))));
|
|
@@ -2977,7 +3001,12 @@ function buildLink(deps) {
|
|
|
2977
3001
|
const body = await c.req.json().catch(() => ({}));
|
|
2978
3002
|
return tryRoute(c, () => {
|
|
2979
3003
|
deps.auth.requestOtp(body.contact ?? "");
|
|
2980
|
-
return {
|
|
3004
|
+
return {
|
|
3005
|
+
success: true,
|
|
3006
|
+
message: `OTP sent to ${body.contact ?? "contact"}`,
|
|
3007
|
+
expires_in: 300,
|
|
3008
|
+
is_new_account: false
|
|
3009
|
+
};
|
|
2981
3010
|
});
|
|
2982
3011
|
});
|
|
2983
3012
|
app.post("/auth/verify-otp", async (c) => {
|
|
@@ -2995,7 +3024,29 @@ function buildLink(deps) {
|
|
|
2995
3024
|
refresh_token: session.token,
|
|
2996
3025
|
account_id: session.id,
|
|
2997
3026
|
customer_id: customer.customer.id,
|
|
2998
|
-
|
|
3027
|
+
name: customer.customer.name,
|
|
3028
|
+
email: customer.customer.email,
|
|
3029
|
+
phone: customer.customer.phone,
|
|
3030
|
+
message: "Login successful"
|
|
3031
|
+
};
|
|
3032
|
+
});
|
|
3033
|
+
});
|
|
3034
|
+
app.post("/auth/refresh", async (c) => {
|
|
3035
|
+
const body = await c.req.json().catch(() => ({}));
|
|
3036
|
+
return tryRoute(c, () => {
|
|
3037
|
+
const session = deps.auth.ensureSession(body.session_token ?? c.var.session.token);
|
|
3038
|
+
const customer = deps.link.ensureCustomer(session.customer_id ?? session.id);
|
|
3039
|
+
c.header("x-session-token", session.token);
|
|
3040
|
+
return {
|
|
3041
|
+
success: true,
|
|
3042
|
+
session_token: session.token,
|
|
3043
|
+
refresh_token: session.token,
|
|
3044
|
+
account_id: session.id,
|
|
3045
|
+
customer_id: customer.customer.id,
|
|
3046
|
+
name: customer.customer.name,
|
|
3047
|
+
email: customer.customer.email,
|
|
3048
|
+
phone: customer.customer.phone,
|
|
3049
|
+
message: "Session refreshed"
|
|
2999
3050
|
};
|
|
3000
3051
|
});
|
|
3001
3052
|
});
|
|
@@ -3003,9 +3054,24 @@ function buildLink(deps) {
|
|
|
3003
3054
|
"/auth/logout",
|
|
3004
3055
|
(c) => tryRoute(c, () => {
|
|
3005
3056
|
deps.auth.logout(c.var.session.token);
|
|
3006
|
-
return { success: true, message: "Logged out" };
|
|
3057
|
+
return { success: true, message: "Logged out successfully", action: "discard_token" };
|
|
3007
3058
|
})
|
|
3008
3059
|
);
|
|
3060
|
+
app.get("/profile", (c) => tryRoute(c, () => deps.link.getProfile(customerId(c))));
|
|
3061
|
+
app.post("/profile", async (c) => {
|
|
3062
|
+
const body = await c.req.json().catch(() => ({}));
|
|
3063
|
+
return tryRoute(c, () => {
|
|
3064
|
+
const state = deps.link.ensureCustomer(customerId(c));
|
|
3065
|
+
state.customer = {
|
|
3066
|
+
...state.customer,
|
|
3067
|
+
name: body.name ?? state.customer.name,
|
|
3068
|
+
email: body.email ?? state.customer.email,
|
|
3069
|
+
phone: body.phone ?? state.customer.phone,
|
|
3070
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
3071
|
+
};
|
|
3072
|
+
return state.customer;
|
|
3073
|
+
});
|
|
3074
|
+
});
|
|
3009
3075
|
app.get("/data", (c) => tryRoute(c, () => deps.link.getLinkData(customerId(c))));
|
|
3010
3076
|
app.post("/check-status", async (c) => {
|
|
3011
3077
|
const body = await c.req.json().catch(() => ({}));
|