@01.software/sdk 0.36.0 → 0.37.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 +71 -6
- package/dist/analytics/react.cjs +33 -9
- package/dist/analytics/react.cjs.map +1 -1
- package/dist/analytics/react.d.cts +1 -1
- package/dist/analytics/react.d.ts +1 -1
- package/dist/analytics/react.js +33 -9
- package/dist/analytics/react.js.map +1 -1
- package/dist/analytics.cjs +30 -8
- package/dist/analytics.cjs.map +1 -1
- package/dist/analytics.d.cts +6 -0
- package/dist/analytics.d.ts +6 -0
- package/dist/analytics.js +30 -8
- package/dist/analytics.js.map +1 -1
- package/dist/client.cjs +94 -114
- 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 +94 -114
- package/dist/client.js.map +1 -1
- package/dist/{collection-client-Bq5Zd7p7.d.ts → collection-client-DyELGUcL.d.ts} +3 -3
- package/dist/{collection-client-Cv0D2w1Q.d.cts → collection-client-zOmnxwdA.d.cts} +3 -3
- package/dist/{const-DVcM7Ac_.d.cts → const-CK_FPaIn.d.cts} +3 -3
- package/dist/{const-BDUKFP9w.d.ts → const-Dqz05oaG.d.ts} +3 -3
- package/dist/{image-BDz2-AaO.d.cts → image-BDjHp03R.d.cts} +13 -9
- package/dist/{image-BDz2-AaO.d.ts → image-BDjHp03R.d.ts} +13 -9
- package/dist/{index-DTSXUYkr.d.ts → index-DRJs7QIh.d.cts} +9 -6
- package/dist/{index-BHDKJ6B3.d.cts → index-DTqoUZk_.d.ts} +9 -6
- package/dist/index.cjs +172 -132
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -9
- package/dist/index.d.ts +10 -9
- package/dist/index.js +172 -132
- package/dist/index.js.map +1 -1
- package/dist/metadata.cjs +5 -3
- package/dist/metadata.cjs.map +1 -1
- package/dist/metadata.js +5 -3
- package/dist/metadata.js.map +1 -1
- package/dist/{payload-types-BCui2Oml.d.cts → payload-types-CREOjFNT.d.cts} +281 -108
- package/dist/{payload-types-BCui2Oml.d.ts → payload-types-CREOjFNT.d.ts} +281 -108
- package/dist/query.cjs +5 -3
- package/dist/query.cjs.map +1 -1
- package/dist/query.d.cts +5 -5
- package/dist/query.d.ts +5 -5
- package/dist/query.js +5 -3
- 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 +84 -69
- 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 +84 -69
- package/dist/server.js.map +1 -1
- package/dist/{types-Dib-zdK6.d.cts → types-BWMUr3Zw.d.cts} +195 -71
- package/dist/{types-CEzLf3PX.d.cts → types-BkZNhuBh.d.cts} +1 -1
- package/dist/{types-3qV6sY7T.d.ts → types-CxzWHspI.d.ts} +1 -1
- package/dist/{types-DK9EnLwJ.d.ts → types-DMvVHdb1.d.ts} +195 -71
- package/dist/ui/canvas.cjs +15 -5
- package/dist/ui/canvas.cjs.map +1 -1
- package/dist/ui/canvas.d.cts +1 -1
- package/dist/ui/canvas.d.ts +1 -1
- package/dist/ui/canvas.js +15 -5
- package/dist/ui/canvas.js.map +1 -1
- package/dist/ui/form.d.cts +1 -1
- package/dist/ui/form.d.ts +1 -1
- package/dist/ui/image.cjs +15 -5
- package/dist/ui/image.cjs.map +1 -1
- package/dist/ui/image.d.cts +1 -1
- package/dist/ui/image.d.ts +1 -1
- package/dist/ui/image.js +15 -5
- package/dist/ui/image.js.map +1 -1
- package/dist/ui/video.d.cts +1 -1
- package/dist/ui/video.d.ts +1 -1
- package/dist/webhook.cjs +5 -1
- package/dist/webhook.cjs.map +1 -1
- package/dist/webhook.d.cts +4 -4
- package/dist/webhook.d.ts +4 -4
- package/dist/webhook.js +5 -1
- package/dist/webhook.js.map +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -772,13 +772,15 @@ var HttpClient = class {
|
|
|
772
772
|
};
|
|
773
773
|
|
|
774
774
|
// src/utils/types.ts
|
|
775
|
-
|
|
775
|
+
function resolveRelation(ref) {
|
|
776
776
|
if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
|
|
777
777
|
return null;
|
|
778
778
|
return ref;
|
|
779
|
-
}
|
|
779
|
+
}
|
|
780
780
|
|
|
781
781
|
// src/core/metadata/index.ts
|
|
782
|
+
var OPEN_GRAPH_IMAGE_SIZE = "1200";
|
|
783
|
+
var LEGACY_OPEN_GRAPH_IMAGE_SIZE = "1536";
|
|
782
784
|
function extractSeo(doc) {
|
|
783
785
|
const seo = doc.seo ?? {};
|
|
784
786
|
const og = seo.openGraph ?? {};
|
|
@@ -822,7 +824,7 @@ function generateMetadata(input, options) {
|
|
|
822
824
|
function resolveMetaImage(ref) {
|
|
823
825
|
const image = resolveRelation(ref);
|
|
824
826
|
if (!image) return null;
|
|
825
|
-
const sized = image.sizes?.[
|
|
827
|
+
const sized = image.sizes?.[OPEN_GRAPH_IMAGE_SIZE] ?? image.sizes?.[LEGACY_OPEN_GRAPH_IMAGE_SIZE];
|
|
826
828
|
const url = sized?.url || image.url;
|
|
827
829
|
if (!url) return null;
|
|
828
830
|
const width = sized?.url ? sized.width : image.width;
|
|
@@ -954,13 +956,16 @@ async function parseApiResponse(response, endpoint) {
|
|
|
954
956
|
return data;
|
|
955
957
|
}
|
|
956
958
|
|
|
957
|
-
// src/core/
|
|
958
|
-
var
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
959
|
+
// src/core/api/customer-scoped-api.ts
|
|
960
|
+
var CustomerScopedApi = class {
|
|
961
|
+
constructor(apiName, options) {
|
|
962
|
+
if (options.requiresCredential !== false && !options.secretKey && !options.customerToken) {
|
|
963
|
+
throw createConfigError(
|
|
964
|
+
`Either secretKey or customerToken is required for ${apiName}.`
|
|
965
|
+
);
|
|
966
|
+
}
|
|
962
967
|
this.publishableKey = requirePublishableKeyForSecret(
|
|
963
|
-
|
|
968
|
+
apiName,
|
|
964
969
|
options.publishableKey,
|
|
965
970
|
options.secretKey
|
|
966
971
|
);
|
|
@@ -970,6 +975,44 @@ var CommunityClient = class {
|
|
|
970
975
|
this.onUnauthorized = options.onUnauthorized;
|
|
971
976
|
this.onRequestId = options.onRequestId;
|
|
972
977
|
}
|
|
978
|
+
async request(endpoint, options) {
|
|
979
|
+
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
980
|
+
try {
|
|
981
|
+
const response = await httpFetch(endpoint, {
|
|
982
|
+
method: options.method,
|
|
983
|
+
apiUrl: this.apiUrl,
|
|
984
|
+
publishableKey: this.publishableKey,
|
|
985
|
+
secretKey: this.secretKey,
|
|
986
|
+
customerToken: token ?? void 0,
|
|
987
|
+
...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
988
|
+
...options.body !== void 0 && {
|
|
989
|
+
body: JSON.stringify(options.body)
|
|
990
|
+
},
|
|
991
|
+
...options.headers && { headers: options.headers }
|
|
992
|
+
});
|
|
993
|
+
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
994
|
+
return parseApiResponse(response, endpoint);
|
|
995
|
+
} catch (err) {
|
|
996
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
997
|
+
this.onRequestId?.(id);
|
|
998
|
+
throw err;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
1002
|
+
|
|
1003
|
+
// src/core/community/community-client.ts
|
|
1004
|
+
var DEFAULT_POST_LIST_SORT = "-lastActivityAt";
|
|
1005
|
+
var DEFAULT_COMMENT_LIST_SORT = "-createdAt";
|
|
1006
|
+
function unwrapPayloadDoc(value) {
|
|
1007
|
+
if (value && typeof value === "object" && "doc" in value) {
|
|
1008
|
+
return value.doc;
|
|
1009
|
+
}
|
|
1010
|
+
return value;
|
|
1011
|
+
}
|
|
1012
|
+
var CommunityClient = class extends CustomerScopedApi {
|
|
1013
|
+
constructor(options) {
|
|
1014
|
+
super("CommunityClient", { ...options, requiresCredential: false });
|
|
1015
|
+
}
|
|
973
1016
|
buildQuery(params) {
|
|
974
1017
|
if (!params) return "";
|
|
975
1018
|
const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
|
|
@@ -1010,27 +1053,14 @@ var CommunityClient = class {
|
|
|
1010
1053
|
return `/api/comments?${urlParams.toString()}`;
|
|
1011
1054
|
}
|
|
1012
1055
|
async execute(endpoint, method, body) {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
publishableKey: this.publishableKey,
|
|
1019
|
-
secretKey: this.secretKey,
|
|
1020
|
-
customerToken: token ?? void 0,
|
|
1021
|
-
...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
1022
|
-
...body !== void 0 && { body: JSON.stringify(body) }
|
|
1023
|
-
});
|
|
1024
|
-
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1025
|
-
return parseApiResponse(response, endpoint);
|
|
1026
|
-
} catch (err) {
|
|
1027
|
-
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1028
|
-
this.onRequestId?.(id);
|
|
1029
|
-
throw err;
|
|
1030
|
-
}
|
|
1056
|
+
return this.request(endpoint, { method, body });
|
|
1057
|
+
}
|
|
1058
|
+
async executeDoc(endpoint, method, body) {
|
|
1059
|
+
const response = await this.execute(endpoint, method, body);
|
|
1060
|
+
return unwrapPayloadDoc(response);
|
|
1031
1061
|
}
|
|
1032
1062
|
createPost(params) {
|
|
1033
|
-
return this.
|
|
1063
|
+
return this.executeDoc("/api/posts", "POST", params);
|
|
1034
1064
|
}
|
|
1035
1065
|
/**
|
|
1036
1066
|
* Public post feed. Server applies the same visibility contract as
|
|
@@ -1087,7 +1117,7 @@ var CommunityClient = class {
|
|
|
1087
1117
|
if (parentId !== void 0) {
|
|
1088
1118
|
body.parent = parentId;
|
|
1089
1119
|
}
|
|
1090
|
-
return this.
|
|
1120
|
+
return this.executeDoc("/api/comments", "POST", body);
|
|
1091
1121
|
}
|
|
1092
1122
|
/**
|
|
1093
1123
|
* List comments for a post.
|
|
@@ -1125,7 +1155,7 @@ var CommunityClient = class {
|
|
|
1125
1155
|
}
|
|
1126
1156
|
updateComment(params) {
|
|
1127
1157
|
const { commentId, body } = params;
|
|
1128
|
-
return this.
|
|
1158
|
+
return this.executeDoc(
|
|
1129
1159
|
`/api/comments/${commentId}`,
|
|
1130
1160
|
"PATCH",
|
|
1131
1161
|
{ body }
|
|
@@ -1156,7 +1186,7 @@ var CommunityClient = class {
|
|
|
1156
1186
|
400
|
|
1157
1187
|
);
|
|
1158
1188
|
}
|
|
1159
|
-
return this.
|
|
1189
|
+
return this.executeDoc("/api/reactions", "POST", {
|
|
1160
1190
|
post: postId,
|
|
1161
1191
|
type: reactionType
|
|
1162
1192
|
});
|
|
@@ -1178,7 +1208,7 @@ var CommunityClient = class {
|
|
|
1178
1208
|
400
|
|
1179
1209
|
);
|
|
1180
1210
|
}
|
|
1181
|
-
return this.
|
|
1211
|
+
return this.executeDoc("/api/reactions", "POST", {
|
|
1182
1212
|
comment: commentId,
|
|
1183
1213
|
type: reactionType
|
|
1184
1214
|
});
|
|
@@ -1210,7 +1240,7 @@ var CommunityClient = class {
|
|
|
1210
1240
|
}
|
|
1211
1241
|
// Bookmarks
|
|
1212
1242
|
addBookmark(params) {
|
|
1213
|
-
return this.
|
|
1243
|
+
return this.executeDoc("/api/bookmarks", "POST", {
|
|
1214
1244
|
post: params.postId
|
|
1215
1245
|
});
|
|
1216
1246
|
}
|
|
@@ -1461,43 +1491,12 @@ var CustomerNamespace = class {
|
|
|
1461
1491
|
};
|
|
1462
1492
|
|
|
1463
1493
|
// src/core/api/cart-api.ts
|
|
1464
|
-
var CartApi = class {
|
|
1494
|
+
var CartApi = class extends CustomerScopedApi {
|
|
1465
1495
|
constructor(options) {
|
|
1466
|
-
|
|
1467
|
-
throw createConfigError(
|
|
1468
|
-
"Either secretKey or customerToken is required for CartApi."
|
|
1469
|
-
);
|
|
1470
|
-
}
|
|
1471
|
-
this.publishableKey = requirePublishableKeyForSecret(
|
|
1472
|
-
"CartApi",
|
|
1473
|
-
options.publishableKey,
|
|
1474
|
-
options.secretKey
|
|
1475
|
-
);
|
|
1476
|
-
this.secretKey = options.secretKey;
|
|
1477
|
-
this.apiUrl = options.apiUrl;
|
|
1478
|
-
this.customerToken = options.customerToken;
|
|
1479
|
-
this.onUnauthorized = options.onUnauthorized;
|
|
1480
|
-
this.onRequestId = options.onRequestId;
|
|
1496
|
+
super("CartApi", options);
|
|
1481
1497
|
}
|
|
1482
1498
|
async execute(endpoint, method, body) {
|
|
1483
|
-
|
|
1484
|
-
try {
|
|
1485
|
-
const response = await httpFetch(endpoint, {
|
|
1486
|
-
method,
|
|
1487
|
-
apiUrl: this.apiUrl,
|
|
1488
|
-
publishableKey: this.publishableKey,
|
|
1489
|
-
secretKey: this.secretKey,
|
|
1490
|
-
customerToken: token ?? void 0,
|
|
1491
|
-
...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
1492
|
-
...body !== void 0 && { body: JSON.stringify(body) }
|
|
1493
|
-
});
|
|
1494
|
-
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1495
|
-
return parseApiResponse(response, endpoint);
|
|
1496
|
-
} catch (err) {
|
|
1497
|
-
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1498
|
-
this.onRequestId?.(id);
|
|
1499
|
-
throw err;
|
|
1500
|
-
}
|
|
1499
|
+
return this.request(endpoint, { method, body });
|
|
1501
1500
|
}
|
|
1502
1501
|
getCart(cartId) {
|
|
1503
1502
|
return this.execute(`/api/carts/${cartId}`, "GET");
|
|
@@ -1564,6 +1563,18 @@ function splitIdempotencyKey(params) {
|
|
|
1564
1563
|
}
|
|
1565
1564
|
|
|
1566
1565
|
// src/core/commerce/commerce-client.ts
|
|
1566
|
+
var BrowserCommerceApi = class extends CustomerScopedApi {
|
|
1567
|
+
post(endpoint, body, requestOptions) {
|
|
1568
|
+
return this.request(endpoint, {
|
|
1569
|
+
method: "POST",
|
|
1570
|
+
body,
|
|
1571
|
+
headers: requestOptions?.headers
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
get(endpoint) {
|
|
1575
|
+
return this.request(endpoint, { method: "GET" });
|
|
1576
|
+
}
|
|
1577
|
+
};
|
|
1567
1578
|
var CommerceClient = class {
|
|
1568
1579
|
constructor(options) {
|
|
1569
1580
|
const cartApi = new CartApi({
|
|
@@ -1573,52 +1584,21 @@ var CommerceClient = class {
|
|
|
1573
1584
|
onUnauthorized: options.onUnauthorized,
|
|
1574
1585
|
onRequestId: options.onRequestId
|
|
1575
1586
|
});
|
|
1576
|
-
const
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
customerToken: token ?? void 0,
|
|
1584
|
-
...token && options.onUnauthorized && { onUnauthorized: options.onUnauthorized },
|
|
1585
|
-
body: JSON.stringify(body),
|
|
1586
|
-
...requestOptions?.headers && { headers: requestOptions.headers }
|
|
1587
|
-
});
|
|
1588
|
-
options.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1589
|
-
return parseApiResponse(response, endpoint);
|
|
1590
|
-
} catch (err) {
|
|
1591
|
-
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1592
|
-
options.onRequestId?.(id);
|
|
1593
|
-
throw err;
|
|
1594
|
-
}
|
|
1595
|
-
};
|
|
1596
|
-
const executeGet = async (endpoint) => {
|
|
1597
|
-
const token = options.customerToken();
|
|
1598
|
-
try {
|
|
1599
|
-
const response = await httpFetch(endpoint, {
|
|
1600
|
-
method: "GET",
|
|
1601
|
-
apiUrl: options.apiUrl,
|
|
1602
|
-
publishableKey: options.publishableKey,
|
|
1603
|
-
customerToken: token ?? void 0,
|
|
1604
|
-
...token && options.onUnauthorized && { onUnauthorized: options.onUnauthorized }
|
|
1605
|
-
});
|
|
1606
|
-
options.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1607
|
-
return parseApiResponse(response, endpoint);
|
|
1608
|
-
} catch (err) {
|
|
1609
|
-
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1610
|
-
options.onRequestId?.(id);
|
|
1611
|
-
throw err;
|
|
1612
|
-
}
|
|
1613
|
-
};
|
|
1587
|
+
const api = new BrowserCommerceApi("CommerceClient", {
|
|
1588
|
+
publishableKey: options.publishableKey,
|
|
1589
|
+
apiUrl: options.apiUrl,
|
|
1590
|
+
customerToken: options.customerToken,
|
|
1591
|
+
onUnauthorized: options.onUnauthorized,
|
|
1592
|
+
onRequestId: options.onRequestId
|
|
1593
|
+
});
|
|
1614
1594
|
this.product = {
|
|
1615
|
-
stockCheck: (params) =>
|
|
1616
|
-
stockSnapshot: (params) =>
|
|
1617
|
-
listingGroups: (params) =>
|
|
1618
|
-
listingGroupsCatalog: (params) =>
|
|
1595
|
+
stockCheck: (params) => api.post("/api/products/stock-check", params),
|
|
1596
|
+
stockSnapshot: (params) => api.get(stockSnapshotQuery(params)),
|
|
1597
|
+
listingGroups: (params) => api.get(listingGroupsQuery(params)),
|
|
1598
|
+
listingGroupsCatalog: (params) => api.get(listingGroupsCatalogQuery(params)),
|
|
1619
1599
|
detail: async (params) => {
|
|
1620
1600
|
try {
|
|
1621
|
-
const product = await
|
|
1601
|
+
const product = await api.get(productDetailQuery(params));
|
|
1622
1602
|
return { found: true, product };
|
|
1623
1603
|
} catch (err) {
|
|
1624
1604
|
const notFoundResult = productDetailResultFromError(err);
|
|
@@ -1628,7 +1608,7 @@ var CommerceClient = class {
|
|
|
1628
1608
|
},
|
|
1629
1609
|
detailCatalog: async (params) => {
|
|
1630
1610
|
try {
|
|
1631
|
-
const product = await
|
|
1611
|
+
const product = await api.get(
|
|
1632
1612
|
productDetailCatalogQuery(params)
|
|
1633
1613
|
);
|
|
1634
1614
|
return { found: true, product };
|
|
@@ -1651,7 +1631,7 @@ var CommerceClient = class {
|
|
|
1651
1631
|
this.orders = {
|
|
1652
1632
|
checkout: (params) => {
|
|
1653
1633
|
const { body, idempotencyKey } = splitIdempotencyKey(params);
|
|
1654
|
-
return
|
|
1634
|
+
return api.post(
|
|
1655
1635
|
"/api/orders/checkout",
|
|
1656
1636
|
body,
|
|
1657
1637
|
idempotencyRequestOptions(idempotencyKey)
|
|
@@ -1660,10 +1640,10 @@ var CommerceClient = class {
|
|
|
1660
1640
|
listMine: (params) => options.customerAuth.getMyOrders(params)
|
|
1661
1641
|
};
|
|
1662
1642
|
this.discounts = {
|
|
1663
|
-
validate: (params) =>
|
|
1643
|
+
validate: (params) => api.post("/api/discounts/validate", params)
|
|
1664
1644
|
};
|
|
1665
1645
|
this.shipping = {
|
|
1666
|
-
calculate: (params) =>
|
|
1646
|
+
calculate: (params) => api.post("/api/shipping-policies/calculate", params)
|
|
1667
1647
|
};
|
|
1668
1648
|
}
|
|
1669
1649
|
};
|