@01.software/sdk 0.37.0 → 0.38.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 +75 -53
- package/dist/client.cjs +67 -104
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +6 -6
- package/dist/client.d.ts +6 -6
- package/dist/client.js +67 -104
- package/dist/client.js.map +1 -1
- package/dist/{collection-client-zOmnxwdA.d.cts → collection-client-B0J9wMNE.d.cts} +5 -5
- package/dist/{collection-client-DyELGUcL.d.ts → collection-client-BroIWHY1.d.ts} +5 -5
- package/dist/const-6XHz_jej.d.ts +32 -0
- package/dist/const-B5KT72c7.d.cts +32 -0
- package/dist/{index-DRJs7QIh.d.cts → index-BOLQxveo.d.cts} +3 -3
- package/dist/{index-DTqoUZk_.d.ts → index-CSwR2HSg.d.ts} +3 -3
- package/dist/index.cjs +95 -123
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +95 -123
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-CREOjFNT.d.cts → payload-types-m3jjhxk9.d.cts} +418 -106
- package/dist/{payload-types-CREOjFNT.d.ts → payload-types-m3jjhxk9.d.ts} +418 -106
- package/dist/query.cjs +3 -1035
- package/dist/query.cjs.map +1 -1
- package/dist/query.d.cts +13 -13
- package/dist/query.d.ts +13 -13
- package/dist/query.js +3 -1035
- package/dist/query.js.map +1 -1
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/server.cjs +42 -21
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +7 -7
- package/dist/server.d.ts +7 -7
- package/dist/server.js +42 -21
- package/dist/server.js.map +1 -1
- package/dist/{types-DMvVHdb1.d.ts → types-CIGscmus.d.cts} +1455 -1208
- package/dist/{types-CxzWHspI.d.ts → types-Cmrd1ezc.d.ts} +1 -15
- package/dist/{types-BkZNhuBh.d.cts → types-D0ubzQw0.d.cts} +1 -15
- package/dist/{types-BWMUr3Zw.d.cts → types-D2xYdz4P.d.ts} +1455 -1208
- package/dist/ui/form.d.cts +1 -1
- package/dist/ui/form.d.ts +1 -1
- package/dist/ui/video.d.cts +1 -1
- package/dist/ui/video.d.ts +1 -1
- package/dist/webhook.d.cts +4 -4
- package/dist/webhook.d.ts +4 -4
- package/package.json +3 -3
- package/dist/const-CK_FPaIn.d.cts +0 -32
- package/dist/const-Dqz05oaG.d.ts +0 -32
package/README.md
CHANGED
|
@@ -140,8 +140,16 @@ const serverQuery = createServerQueryHooks(server)
|
|
|
140
140
|
const order = await server.commerce.orders.create({
|
|
141
141
|
orderNumber: generateOrderNumber(),
|
|
142
142
|
customerSnapshot: { email: 'user@example.com' },
|
|
143
|
-
shippingAddress: {
|
|
144
|
-
|
|
143
|
+
shippingAddress: {
|
|
144
|
+
recipientName: 'John',
|
|
145
|
+
phone: '010-1234-5678',
|
|
146
|
+
postalCode: '12345',
|
|
147
|
+
address: 'Seoul',
|
|
148
|
+
detailAddress: 'Apt 101',
|
|
149
|
+
},
|
|
150
|
+
items: [
|
|
151
|
+
{ product: productId, variant: variantId, option: optionId, quantity: 1 },
|
|
152
|
+
],
|
|
145
153
|
totalAmount: 10000,
|
|
146
154
|
pgPaymentId: 'provider-payment-id', // optional (omit for free orders)
|
|
147
155
|
discountCode: 'WELCOME10', // optional
|
|
@@ -219,14 +227,13 @@ catalog/stock split instead of reading `variant.stock` from a cached
|
|
|
219
227
|
`detail()` response (inventory in that payload can lag for the catalog TTL).
|
|
220
228
|
|
|
221
229
|
```typescript
|
|
222
|
-
import {
|
|
223
|
-
createClient,
|
|
224
|
-
mergeProductDetailWithStock,
|
|
225
|
-
} from '@01.software/sdk'
|
|
230
|
+
import { createClient, mergeProductDetailWithStock } from '@01.software/sdk'
|
|
226
231
|
|
|
227
232
|
const client = createClient({ publishableKey: '<publishable-key>' })
|
|
228
233
|
|
|
229
|
-
const catalog = await client.commerce.product.detailCatalog({
|
|
234
|
+
const catalog = await client.commerce.product.detailCatalog({
|
|
235
|
+
slug: 'every-peach-tee',
|
|
236
|
+
})
|
|
230
237
|
if (!catalog.found) return notFound()
|
|
231
238
|
|
|
232
239
|
const variantIds = catalog.product.variants.map((v) => v.id)
|
|
@@ -273,9 +280,7 @@ const cards: ProductListingCard[] = response.docs.map((item) =>
|
|
|
273
280
|
`PRODUCT_PLP_FIND_OPTIONS` to raise the default Payload join limit of 10:
|
|
274
281
|
|
|
275
282
|
```typescript
|
|
276
|
-
import {
|
|
277
|
-
PRODUCT_PLP_FIND_OPTIONS,
|
|
278
|
-
} from '@01.software/sdk'
|
|
283
|
+
import { PRODUCT_PLP_FIND_OPTIONS } from '@01.software/sdk'
|
|
279
284
|
|
|
280
285
|
const { docs } = await client.collections.from('products').find({
|
|
281
286
|
...PRODUCT_PLP_FIND_OPTIONS,
|
|
@@ -393,9 +398,13 @@ By default, partial selections (for example color only) leave
|
|
|
393
398
|
`selectedOrFirstAvailableVariant` behavior with `fillDefaults: true`:
|
|
394
399
|
|
|
395
400
|
```typescript
|
|
396
|
-
const resolution = resolveProductSelection(
|
|
397
|
-
|
|
398
|
-
|
|
401
|
+
const resolution = resolveProductSelection(
|
|
402
|
+
product,
|
|
403
|
+
codec.parse('?opt.color=ivory'),
|
|
404
|
+
{
|
|
405
|
+
fillDefaults: true,
|
|
406
|
+
},
|
|
407
|
+
)
|
|
399
408
|
// resolution.selectedVariant is concrete; unselected options are filled
|
|
400
409
|
// using the same available-by-order rules as listing selectionHintVariant.
|
|
401
410
|
```
|
|
@@ -495,7 +504,10 @@ the card should deep-link a complete hint variant.
|
|
|
495
504
|
|
|
496
505
|
```ts
|
|
497
506
|
import { createClient } from '@01.software/sdk'
|
|
498
|
-
import {
|
|
507
|
+
import {
|
|
508
|
+
createQueryHooks,
|
|
509
|
+
getStorefrontQueryClient,
|
|
510
|
+
} from '@01.software/sdk/query'
|
|
499
511
|
|
|
500
512
|
const client = createClient({ publishableKey: '...' })
|
|
501
513
|
const query = createQueryHooks(client, getStorefrontQueryClient())
|
|
@@ -507,11 +519,12 @@ Most consumers should use the helper APIs above (`commerce.product.detail`, etc.
|
|
|
507
519
|
|
|
508
520
|
### `depth` — how deep to populate relationship fields
|
|
509
521
|
|
|
510
|
-
`depth` is the primary control for populating relationships like `category`, `images`, `brand`.
|
|
522
|
+
`depth` is the primary control for populating relationships like `category`, `images`, `brand`. Browser publishable-key raw collection reads are constrained to `depth: 0` with `joins: false`; relationship-rich storefront reads should use shaped helpers such as `commerce.product.detail()` / `listingGroupsCatalog()`, or a `createServerClient()` raw query when server credentials are appropriate. Browser SDK raw reads add those safe defaults automatically.
|
|
511
523
|
|
|
512
524
|
```typescript
|
|
513
525
|
const product = await client.collections.from('products').findById(id, {
|
|
514
|
-
depth:
|
|
526
|
+
depth: 0,
|
|
527
|
+
joins: false,
|
|
515
528
|
})
|
|
516
529
|
```
|
|
517
530
|
|
|
@@ -520,7 +533,7 @@ const product = await client.collections.from('products').findById(id, {
|
|
|
520
533
|
`populate` controls which fields are returned per collection. It does NOT decide which relationships to populate — that is `depth`.
|
|
521
534
|
|
|
522
535
|
```typescript
|
|
523
|
-
await
|
|
536
|
+
await server.collections.from('products').find({
|
|
524
537
|
depth: 2,
|
|
525
538
|
populate: {
|
|
526
539
|
categories: { title: true, slug: true },
|
|
@@ -531,11 +544,11 @@ await client.collections.from('products').find({
|
|
|
531
544
|
|
|
532
545
|
### `joins` — Payload join-field reverse-relations
|
|
533
546
|
|
|
534
|
-
`joins` is the correct control for Payload `type: 'join'` virtual reverse-relation fields. In this platform's
|
|
547
|
+
`joins` is the correct control for Payload `type: 'join'` virtual reverse-relation fields. In this platform's SDK schema, browser-public relations such as `products.variants`, `products.options`, and `article-authors.articles`, plus server-auth relations such as `customers.orders`, `customers.addresses`, `posts.comments`, and `orders.{items,transactions,fulfillments,returns}`, are all join fields — you must use `joins` (not `depth`/`populate`) to control their pagination, sorting, filtering, and count. Internal backing joins such as product collection memberships are intentionally omitted from SDK collection types.
|
|
535
548
|
|
|
536
549
|
```typescript
|
|
537
550
|
// Canonical product detail query — variants/options are join fields on Products
|
|
538
|
-
await
|
|
551
|
+
await server.collections.from('products').find({
|
|
539
552
|
where: { slug: { equals } },
|
|
540
553
|
joins: {
|
|
541
554
|
variants: { limit: 50, sort: '_order' },
|
|
@@ -546,12 +559,15 @@ await client.collections.from('products').find({
|
|
|
546
559
|
|
|
547
560
|
// Disable all join-field population for a lightweight list query
|
|
548
561
|
await client.collections.from('products').find({
|
|
562
|
+
depth: 0,
|
|
549
563
|
joins: false,
|
|
550
564
|
})
|
|
551
565
|
```
|
|
552
566
|
|
|
553
567
|
Each join field defaults to **limit 10** when `joins` is omitted. `depth` does not raise that cap — storefront PLPs that call `products.find()` with only `depth` and then `buildProductListingGroupsByOption()` can silently drop color swatches. Prefer `listingGroupsCatalog()` for PLP cards, or spread `PRODUCT_PLP_FIND_OPTIONS` for raw product queries (see [PLP join-safe queries](#product-listing-pages-plp--join-safe-queries) above).
|
|
554
568
|
|
|
569
|
+
Publishable-key browser raw reads must keep `joins: false`; join-expanded public storefront reads belong behind shaped helpers. Use `createServerClient()` for raw `joins` queries that need server credentials.
|
|
570
|
+
|
|
555
571
|
`joins` does NOT populate normal relationship fields. Keys that do not match a `type: 'join'` field on the queried collection are silently ignored — e.g. `joins: { category: {} }` on Products is a no-op because `category` is not a join field there. For normal relationships use `depth` (and optionally `populate`).
|
|
556
572
|
|
|
557
573
|
### Filtering by relation
|
|
@@ -651,7 +667,7 @@ const { docs, totalDocs, hasNextPage } = await client.collections
|
|
|
651
667
|
page: 1,
|
|
652
668
|
sort: '-createdAt',
|
|
653
669
|
where: { status: { equals: 'published' } },
|
|
654
|
-
depth:
|
|
670
|
+
depth: 0,
|
|
655
671
|
select: { title: true, slug: true },
|
|
656
672
|
})
|
|
657
673
|
|
|
@@ -661,8 +677,8 @@ const { docs } = await client.collections.from('products').find({
|
|
|
661
677
|
joins: false, // disable joins for lightweight list
|
|
662
678
|
})
|
|
663
679
|
|
|
664
|
-
// Override relationship populate
|
|
665
|
-
const product = await
|
|
680
|
+
// Override relationship populate and join expansion (server credentials only)
|
|
681
|
+
const product = await server.collections.from('products').findById(id, {
|
|
666
682
|
populate: { brands: { name: true, logo: true } },
|
|
667
683
|
joins: { variants: { limit: 50 } },
|
|
668
684
|
})
|
|
@@ -708,7 +724,7 @@ import { extractSeo, generateMetadata } from '@01.software/sdk/metadata'
|
|
|
708
724
|
const { docs } = await client.collections.from('products').find({
|
|
709
725
|
where: { slug: { equals: 'my-product' } },
|
|
710
726
|
limit: 1,
|
|
711
|
-
depth:
|
|
727
|
+
depth: 0,
|
|
712
728
|
})
|
|
713
729
|
const metadata = docs[0]
|
|
714
730
|
? generateMetadata(extractSeo(docs[0]), { siteName: 'My Store' })
|
|
@@ -893,7 +909,7 @@ await client.customer.auth.changePassword(currentPassword, newPassword)
|
|
|
893
909
|
|
|
894
910
|
### Commerce Orders (ServerClient-only writes)
|
|
895
911
|
|
|
896
|
-
Available on ServerClient via `server.commerce.orders.*`.
|
|
912
|
+
Available on ServerClient via `server.commerce.orders.*`. `checkout` and `listMine` are also on Client and return sanitized customer-facing order DTOs. Use `server.collections.from('orders')` for raw operational order documents.
|
|
897
913
|
|
|
898
914
|
```typescript
|
|
899
915
|
// Orders
|
|
@@ -927,6 +943,8 @@ await server.commerce.orders.confirmPayment({
|
|
|
927
943
|
|
|
928
944
|
// Low-level transaction annotation / compatibility path. Prefer confirmPayment()
|
|
929
945
|
// for normal provider-verified paid transitions.
|
|
946
|
+
// status: 'failed' records a retryable PG failure on the Transaction only; the
|
|
947
|
+
// Order stays pending until verified payment succeeds or the merchant cancels it.
|
|
930
948
|
await server.commerce.orders.updateTransaction({ pgPaymentId, status, paymentMethod, receiptUrl })
|
|
931
949
|
|
|
932
950
|
// Returns
|
|
@@ -978,11 +996,11 @@ not send removed legacy media inputs (`optionValue.thumbnail`,
|
|
|
978
996
|
`optionValue.images`, `variant.thumbnail`); use `swatch.mediaItemId` and
|
|
979
997
|
variant `images[]`. Unknown keys are not part of the published upsert contract.
|
|
980
998
|
|
|
981
|
-
| Payload
|
|
982
|
-
|
|
|
983
|
-
| Create
|
|
984
|
-
| Edit graph
|
|
985
|
-
| Edit (legacy) | `product: { id }` + graph only
|
|
999
|
+
| Payload | Valid | Invalid |
|
|
1000
|
+
| ------------- | -------------------------------------- | ------------------------------------------------------------------------ |
|
|
1001
|
+
| Create | `product: { title, ... }` + graph | `productId` on create; missing `product.title` |
|
|
1002
|
+
| Edit graph | `productId` + `graphRevision?` + graph | `product.title` / SEO on upsert; conflicting `productId` vs `product.id` |
|
|
1003
|
+
| Edit (legacy) | `product: { id }` + graph only | `product: { id, title }` on edit |
|
|
986
1004
|
|
|
987
1005
|
```typescript
|
|
988
1006
|
const result = await server.commerce.product.upsert({
|
|
@@ -1076,7 +1094,7 @@ for (const item of results) {
|
|
|
1076
1094
|
|
|
1077
1095
|
### Commerce Cart
|
|
1078
1096
|
|
|
1079
|
-
Available on both Client and ServerClient via `commerce.cart.*`.
|
|
1097
|
+
Available on both Client and ServerClient via `commerce.cart.*`. These helpers return sanitized customer-facing cart DTOs; use `server.collections.from('carts' | 'cart-items')` for raw operational cart documents.
|
|
1080
1098
|
|
|
1081
1099
|
```typescript
|
|
1082
1100
|
// Add item to cart
|
|
@@ -1094,7 +1112,7 @@ await client.commerce.cart.updateItem({ cartItemId, quantity })
|
|
|
1094
1112
|
// Remove item from cart
|
|
1095
1113
|
await client.commerce.cart.removeItem({ cartItemId })
|
|
1096
1114
|
|
|
1097
|
-
// Other cart operations
|
|
1115
|
+
// Other cart operations return sanitized customer-facing cart DTOs.
|
|
1098
1116
|
await client.commerce.cart.get(cartId)
|
|
1099
1117
|
await client.commerce.cart.applyDiscount({ cartId, discountCode })
|
|
1100
1118
|
await client.commerce.cart.removeDiscount({ cartId })
|
|
@@ -1170,7 +1188,10 @@ const customerAuthHandler = createCustomerAuthWebhookHandler({
|
|
|
1170
1188
|
// Semantic order-change events keep operation as "update" for compatibility.
|
|
1171
1189
|
// Use isOrderChangedWebhookEvent when you need to distinguish manual ordering
|
|
1172
1190
|
// from content field edits.
|
|
1173
|
-
import {
|
|
1191
|
+
import {
|
|
1192
|
+
handleWebhook,
|
|
1193
|
+
isOrderChangedWebhookEvent,
|
|
1194
|
+
} from '@01.software/sdk/webhook'
|
|
1174
1195
|
|
|
1175
1196
|
function getWebhookSecret(): string {
|
|
1176
1197
|
const secret = process.env.WEBHOOK_SECRET
|
|
@@ -1203,31 +1224,32 @@ join-order surface and does not emit a semantic order-change webhook.
|
|
|
1203
1224
|
|
|
1204
1225
|
## Supported Collections
|
|
1205
1226
|
|
|
1206
|
-
Source of truth: `packages/sdk/src/core/collection/const.ts` (`COLLECTIONS`:
|
|
1227
|
+
Source of truth: `packages/sdk/src/core/collection/const.ts` (`COLLECTIONS`: 53).
|
|
1207
1228
|
|
|
1208
|
-
| Category |
|
|
1229
|
+
| Category | Browser-public generic collections |
|
|
1209
1230
|
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
1210
|
-
| Tenant | `tenants`, `tenant-metadata
|
|
1211
|
-
| Products | `products`, `product-variants`, `product-options`, `product-option-values`, `product-categories`, `product-tags`, `product-collections`, `brands
|
|
1212
|
-
|
|
|
1213
|
-
| Customers | `customers`, `customer-profiles`, `customer-addresses` |
|
|
1214
|
-
| Carts | `carts`, `cart-items` |
|
|
1231
|
+
| Tenant | `tenants`, `tenant-metadata` |
|
|
1232
|
+
| Products | `products`, `product-variants`, `product-options`, `product-option-values`, `product-categories`, `product-tags`, `product-collections`, `brands` |
|
|
1233
|
+
| Customers | `customer-profiles` |
|
|
1215
1234
|
| Commerce | `discounts`, `shipping-policies`, `shipping-zones` |
|
|
1216
1235
|
| Content | `documents`, `document-categories`, `document-types`, `articles`, `article-authors`, `article-categories`, `article-tags`, `links`, `link-categories`, `link-tags` |
|
|
1217
1236
|
| Playlists / Tracks | `playlists`, `playlist-categories`, `playlist-tags`, `tracks`, `track-categories`, `track-tags` |
|
|
1218
1237
|
| Galleries | `galleries`, `gallery-categories`, `gallery-tags`, `gallery-items` |
|
|
1219
1238
|
| Canvas | `canvases`, `canvas-node-types`, `canvas-edge-types`, `canvas-categories`, `canvas-tags`, `canvas-nodes`, `canvas-edges` |
|
|
1220
|
-
| Videos | `
|
|
1221
|
-
|
|
|
1222
|
-
|
|
|
1223
|
-
| Forms | `forms`, `form-submissions` |
|
|
1224
|
-
| Community | `posts`, `comments`, `reactions`, `reaction-types`, `bookmarks`, `post-categories`, `customer-profile-lists` |
|
|
1239
|
+
| Videos | `video-categories`, `video-tags` |
|
|
1240
|
+
| Forms | `forms` |
|
|
1241
|
+
| Community | `reaction-types`, `post-categories`, `post-tags`, `customer-profile-lists` |
|
|
1225
1242
|
| Events | `event-calendars`, `events`, `event-categories`, `event-occurrences`, `event-tags` |
|
|
1226
1243
|
|
|
1227
|
-
Server-only collections
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1244
|
+
Server-only collections include raw media/logo records, customer and order
|
|
1245
|
+
operational records, raw cart/cart-item records, form submissions, raw community documents
|
|
1246
|
+
(`posts`, `comments`, `reactions`, `bookmarks`), live stream provider records,
|
|
1247
|
+
segmentation records, and moderation records. They remain available from
|
|
1248
|
+
`createServerClient().collections` with secret/PAT credentials. Shaped
|
|
1249
|
+
browser/customer helpers such as `commerce.cart.*`,
|
|
1250
|
+
`commerce.orders.listMine()`, and `commerce.orders.checkout()` remain available
|
|
1251
|
+
where customer-facing DTOs are needed, but raw slugs are intentionally absent
|
|
1252
|
+
from browser collection discovery.
|
|
1231
1253
|
|
|
1232
1254
|
## Utilities
|
|
1233
1255
|
|
|
@@ -1362,11 +1384,11 @@ API keys created without explicit scopes use the default `['read', 'write']`. Co
|
|
|
1362
1384
|
`swatch` (`type`, `color`, `mediaItemId`). Legacy public fields are removed
|
|
1363
1385
|
from SDK input/output helpers and from listing/detail contracts.
|
|
1364
1386
|
|
|
1365
|
-
| Surface
|
|
1366
|
-
|
|
|
1367
|
-
| Upsert option value
|
|
1368
|
-
| Listing groups
|
|
1369
|
-
| Product detail option value | `swatchColor`, `thumbnail`, `images`
|
|
1387
|
+
| Surface | Removed | Replacement |
|
|
1388
|
+
| --------------------------- | --------------------------------------------------------------------- | --------------------------------------------------- |
|
|
1389
|
+
| Upsert option value | `swatchColor`, `thumbnail`, `images` | `swatch.type`, `swatch.color`, `swatch.mediaItemId` |
|
|
1390
|
+
| Listing groups | `optionValueSwatchColor`, `optionValueThumbnail`, `optionValueImages` | `optionValueSwatch` |
|
|
1391
|
+
| Product detail option value | `swatchColor`, `thumbnail`, `images` | `swatch` |
|
|
1370
1392
|
|
|
1371
1393
|
Migration steps:
|
|
1372
1394
|
|
package/dist/client.cjs
CHANGED
|
@@ -771,73 +771,14 @@ var HttpClient = class {
|
|
|
771
771
|
}
|
|
772
772
|
};
|
|
773
773
|
|
|
774
|
-
// src/
|
|
775
|
-
function
|
|
776
|
-
if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
|
|
777
|
-
return null;
|
|
778
|
-
return ref;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
// src/core/metadata/index.ts
|
|
782
|
-
var OPEN_GRAPH_IMAGE_SIZE = "1200";
|
|
783
|
-
var LEGACY_OPEN_GRAPH_IMAGE_SIZE = "1536";
|
|
784
|
-
function extractSeo(doc) {
|
|
785
|
-
const seo = doc.seo ?? {};
|
|
786
|
-
const og = seo.openGraph ?? {};
|
|
787
|
-
return {
|
|
788
|
-
title: seo.title ?? doc.title ?? null,
|
|
789
|
-
description: seo.description ?? null,
|
|
790
|
-
noIndex: seo.noIndex ?? null,
|
|
791
|
-
canonical: seo.canonical ?? null,
|
|
792
|
-
openGraph: {
|
|
793
|
-
title: og.title ?? null,
|
|
794
|
-
description: og.description ?? null,
|
|
795
|
-
image: og.image ?? null
|
|
796
|
-
}
|
|
797
|
-
};
|
|
798
|
-
}
|
|
799
|
-
function generateMetadata(input, options) {
|
|
800
|
-
const title = input.title ?? void 0;
|
|
801
|
-
const description = input.description ?? void 0;
|
|
802
|
-
const ogTitle = input.openGraph?.title ?? title;
|
|
803
|
-
const ogDescription = input.openGraph?.description ?? description;
|
|
804
|
-
const image = resolveMetaImage(input.openGraph?.image);
|
|
805
|
-
return {
|
|
806
|
-
title,
|
|
807
|
-
description,
|
|
808
|
-
...input.noIndex && { robots: { index: false, follow: false } },
|
|
809
|
-
...input.canonical && { alternates: { canonical: input.canonical } },
|
|
810
|
-
openGraph: {
|
|
811
|
-
...ogTitle && { title: ogTitle },
|
|
812
|
-
...ogDescription && { description: ogDescription },
|
|
813
|
-
...options?.siteName && { siteName: options.siteName },
|
|
814
|
-
...image && { images: [image] }
|
|
815
|
-
},
|
|
816
|
-
twitter: {
|
|
817
|
-
card: image ? "summary_large_image" : "summary",
|
|
818
|
-
...ogTitle && { title: ogTitle },
|
|
819
|
-
...ogDescription && { description: ogDescription },
|
|
820
|
-
...image && { images: [image.url] }
|
|
821
|
-
}
|
|
822
|
-
};
|
|
823
|
-
}
|
|
824
|
-
function resolveMetaImage(ref) {
|
|
825
|
-
const image = resolveRelation(ref);
|
|
826
|
-
if (!image) return null;
|
|
827
|
-
const sized = image.sizes?.[OPEN_GRAPH_IMAGE_SIZE] ?? image.sizes?.[LEGACY_OPEN_GRAPH_IMAGE_SIZE];
|
|
828
|
-
const url = sized?.url || image.url;
|
|
829
|
-
if (!url) return null;
|
|
830
|
-
const width = sized?.url ? sized.width : image.width;
|
|
831
|
-
const height = sized?.url ? sized.height : image.height;
|
|
774
|
+
// src/core/collection/query-builder.ts
|
|
775
|
+
function withDefaultPublicReadOptions(options) {
|
|
832
776
|
return {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
...image.alt && { alt: image.alt }
|
|
777
|
+
...options,
|
|
778
|
+
depth: options?.depth ?? 0,
|
|
779
|
+
joins: options?.joins ?? false
|
|
837
780
|
};
|
|
838
781
|
}
|
|
839
|
-
|
|
840
|
-
// src/core/collection/query-builder.ts
|
|
841
782
|
var ReadOnlyCollectionQueryBuilder = class {
|
|
842
783
|
constructor(api, collection) {
|
|
843
784
|
this.api = api;
|
|
@@ -846,13 +787,13 @@ var ReadOnlyCollectionQueryBuilder = class {
|
|
|
846
787
|
async find(options) {
|
|
847
788
|
return this.api.requestFind(
|
|
848
789
|
`/api/${String(this.collection)}`,
|
|
849
|
-
options
|
|
790
|
+
withDefaultPublicReadOptions(options)
|
|
850
791
|
);
|
|
851
792
|
}
|
|
852
793
|
async findById(id, options) {
|
|
853
794
|
return this.api.requestFindById(
|
|
854
795
|
`/api/${String(this.collection)}/${String(id)}`,
|
|
855
|
-
options
|
|
796
|
+
withDefaultPublicReadOptions(options)
|
|
856
797
|
);
|
|
857
798
|
}
|
|
858
799
|
async count(options) {
|
|
@@ -861,22 +802,6 @@ var ReadOnlyCollectionQueryBuilder = class {
|
|
|
861
802
|
options
|
|
862
803
|
);
|
|
863
804
|
}
|
|
864
|
-
async findMetadata(options, metadataOptions) {
|
|
865
|
-
const { docs } = await this.find({ ...options, limit: 1, depth: 1 });
|
|
866
|
-
const doc = docs[0];
|
|
867
|
-
if (!doc) return null;
|
|
868
|
-
return generateMetadata(
|
|
869
|
-
extractSeo(doc),
|
|
870
|
-
metadataOptions
|
|
871
|
-
);
|
|
872
|
-
}
|
|
873
|
-
async findMetadataById(id, metadataOptions) {
|
|
874
|
-
const doc = await this.findById(id, { depth: 1 });
|
|
875
|
-
return generateMetadata(
|
|
876
|
-
extractSeo(doc),
|
|
877
|
-
metadataOptions
|
|
878
|
-
);
|
|
879
|
-
}
|
|
880
805
|
};
|
|
881
806
|
|
|
882
807
|
// src/core/collection/collection-client.ts
|
|
@@ -892,6 +817,21 @@ var ReadOnlyCollectionClient = class extends HttpClient {
|
|
|
892
817
|
});
|
|
893
818
|
return this.parseFindResponse(response);
|
|
894
819
|
}
|
|
820
|
+
async requestFindEndpoint(endpoint, data) {
|
|
821
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
822
|
+
...this.defaultOptions,
|
|
823
|
+
method: "POST",
|
|
824
|
+
body: data ? JSON.stringify(data) : void 0
|
|
825
|
+
});
|
|
826
|
+
return this.parseFindResponse(response);
|
|
827
|
+
}
|
|
828
|
+
async requestFindEndpointGet(endpoint) {
|
|
829
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
830
|
+
...this.defaultOptions,
|
|
831
|
+
method: "GET"
|
|
832
|
+
});
|
|
833
|
+
return this.parseFindResponse(response);
|
|
834
|
+
}
|
|
895
835
|
async requestFindById(endpoint, options) {
|
|
896
836
|
const url = this.buildUrl(endpoint, options);
|
|
897
837
|
const response = await this.fetchWithTracking(url, {
|
|
@@ -1022,7 +962,8 @@ var CommunityClient = class extends CustomerScopedApi {
|
|
|
1022
962
|
const urlParams = new URLSearchParams();
|
|
1023
963
|
const sort = params?.sort ?? DEFAULT_POST_LIST_SORT;
|
|
1024
964
|
urlParams.set("sort", sort);
|
|
1025
|
-
if (params?.limit !== void 0)
|
|
965
|
+
if (params?.limit !== void 0)
|
|
966
|
+
urlParams.set("limit", String(params.limit));
|
|
1026
967
|
if (params?.page !== void 0) urlParams.set("page", String(params.page));
|
|
1027
968
|
if (params?.categoryId !== void 0) {
|
|
1028
969
|
urlParams.set("where[categories][in]", params.categoryId);
|
|
@@ -1030,7 +971,7 @@ var CommunityClient = class extends CustomerScopedApi {
|
|
|
1030
971
|
if (params?.tagId !== void 0) {
|
|
1031
972
|
urlParams.set("where[tags][in]", params.tagId);
|
|
1032
973
|
}
|
|
1033
|
-
return `/api/posts?${urlParams.toString()}`;
|
|
974
|
+
return `/api/posts/public?${urlParams.toString()}`;
|
|
1034
975
|
}
|
|
1035
976
|
buildCommentsListQuery(params) {
|
|
1036
977
|
const urlParams = new URLSearchParams();
|
|
@@ -1050,7 +991,7 @@ var CommunityClient = class extends CustomerScopedApi {
|
|
|
1050
991
|
}
|
|
1051
992
|
if (params.limit !== void 0) urlParams.set("limit", String(params.limit));
|
|
1052
993
|
if (params.page !== void 0) urlParams.set("page", String(params.page));
|
|
1053
|
-
return `/api/comments?${urlParams.toString()}`;
|
|
994
|
+
return `/api/comments/public?${urlParams.toString()}`;
|
|
1054
995
|
}
|
|
1055
996
|
async execute(endpoint, method, body) {
|
|
1056
997
|
return this.request(endpoint, { method, body });
|
|
@@ -1060,7 +1001,11 @@ var CommunityClient = class extends CustomerScopedApi {
|
|
|
1060
1001
|
return unwrapPayloadDoc(response);
|
|
1061
1002
|
}
|
|
1062
1003
|
createPost(params) {
|
|
1063
|
-
return this.executeDoc(
|
|
1004
|
+
return this.executeDoc(
|
|
1005
|
+
"/api/posts",
|
|
1006
|
+
"POST",
|
|
1007
|
+
params
|
|
1008
|
+
);
|
|
1064
1009
|
}
|
|
1065
1010
|
/**
|
|
1066
1011
|
* Public post feed. Server applies the same visibility contract as
|
|
@@ -1117,7 +1062,11 @@ var CommunityClient = class extends CustomerScopedApi {
|
|
|
1117
1062
|
if (parentId !== void 0) {
|
|
1118
1063
|
body.parent = parentId;
|
|
1119
1064
|
}
|
|
1120
|
-
return this.executeDoc(
|
|
1065
|
+
return this.executeDoc(
|
|
1066
|
+
"/api/comments",
|
|
1067
|
+
"POST",
|
|
1068
|
+
body
|
|
1069
|
+
);
|
|
1121
1070
|
}
|
|
1122
1071
|
/**
|
|
1123
1072
|
* List comments for a post.
|
|
@@ -1186,10 +1135,14 @@ var CommunityClient = class extends CustomerScopedApi {
|
|
|
1186
1135
|
400
|
|
1187
1136
|
);
|
|
1188
1137
|
}
|
|
1189
|
-
return this.executeDoc(
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1138
|
+
return this.executeDoc(
|
|
1139
|
+
"/api/reactions",
|
|
1140
|
+
"POST",
|
|
1141
|
+
{
|
|
1142
|
+
post: postId,
|
|
1143
|
+
type: reactionType
|
|
1144
|
+
}
|
|
1145
|
+
);
|
|
1193
1146
|
}
|
|
1194
1147
|
removeReaction(params) {
|
|
1195
1148
|
const { postId, type } = params;
|
|
@@ -1208,10 +1161,14 @@ var CommunityClient = class extends CustomerScopedApi {
|
|
|
1208
1161
|
400
|
|
1209
1162
|
);
|
|
1210
1163
|
}
|
|
1211
|
-
return this.executeDoc(
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1164
|
+
return this.executeDoc(
|
|
1165
|
+
"/api/reactions",
|
|
1166
|
+
"POST",
|
|
1167
|
+
{
|
|
1168
|
+
comment: commentId,
|
|
1169
|
+
type: reactionType
|
|
1170
|
+
}
|
|
1171
|
+
);
|
|
1215
1172
|
}
|
|
1216
1173
|
removeCommentReaction(params) {
|
|
1217
1174
|
const { commentId, type } = params;
|
|
@@ -1240,9 +1197,13 @@ var CommunityClient = class extends CustomerScopedApi {
|
|
|
1240
1197
|
}
|
|
1241
1198
|
// Bookmarks
|
|
1242
1199
|
addBookmark(params) {
|
|
1243
|
-
return this.executeDoc(
|
|
1244
|
-
|
|
1245
|
-
|
|
1200
|
+
return this.executeDoc(
|
|
1201
|
+
"/api/bookmarks",
|
|
1202
|
+
"POST",
|
|
1203
|
+
{
|
|
1204
|
+
post: params.postId
|
|
1205
|
+
}
|
|
1206
|
+
);
|
|
1246
1207
|
}
|
|
1247
1208
|
removeBookmark(params) {
|
|
1248
1209
|
return this.execute(
|
|
@@ -1258,10 +1219,7 @@ var CommunityClient = class extends CustomerScopedApi {
|
|
|
1258
1219
|
}
|
|
1259
1220
|
// Profiles
|
|
1260
1221
|
listProfileLists(params) {
|
|
1261
|
-
return this.execute(
|
|
1262
|
-
`/api/customer-profile-lists${this.buildQuery(params)}`,
|
|
1263
|
-
"GET"
|
|
1264
|
-
);
|
|
1222
|
+
return this.execute(`/api/customer-profile-lists${this.buildQuery(params)}`, "GET");
|
|
1265
1223
|
}
|
|
1266
1224
|
async getProfileList(params) {
|
|
1267
1225
|
const query = "slug" in params ? `?where[slug][equals]=${encodeURIComponent(params.slug)}&limit=1` : `?where[id][equals]=${encodeURIComponent(params.id)}&limit=1`;
|
|
@@ -1499,7 +1457,10 @@ var CartApi = class extends CustomerScopedApi {
|
|
|
1499
1457
|
return this.request(endpoint, { method, body });
|
|
1500
1458
|
}
|
|
1501
1459
|
getCart(cartId) {
|
|
1502
|
-
return this.execute(
|
|
1460
|
+
return this.execute(
|
|
1461
|
+
`/api/carts/${cartId}?depth=0&joins=false`,
|
|
1462
|
+
"GET"
|
|
1463
|
+
);
|
|
1503
1464
|
}
|
|
1504
1465
|
addItem(params) {
|
|
1505
1466
|
return this.execute("/api/carts/add-item", "POST", params);
|
|
@@ -1595,7 +1556,9 @@ var CommerceClient = class {
|
|
|
1595
1556
|
stockCheck: (params) => api.post("/api/products/stock-check", params),
|
|
1596
1557
|
stockSnapshot: (params) => api.get(stockSnapshotQuery(params)),
|
|
1597
1558
|
listingGroups: (params) => api.get(listingGroupsQuery(params)),
|
|
1598
|
-
listingGroupsCatalog: (params) => api.get(
|
|
1559
|
+
listingGroupsCatalog: (params) => api.get(
|
|
1560
|
+
listingGroupsCatalogQuery(params)
|
|
1561
|
+
),
|
|
1599
1562
|
detail: async (params) => {
|
|
1600
1563
|
try {
|
|
1601
1564
|
const product = await api.get(productDetailQuery(params));
|