@bosonprotocol/core-sdk 1.35.1-alpha.1 → 1.36.0-alpha.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.
Files changed (39) hide show
  1. package/dist/cjs/core-sdk.d.ts.map +1 -1
  2. package/dist/cjs/core-sdk.js.map +1 -1
  3. package/dist/cjs/metadata/mixin.d.ts +7 -0
  4. package/dist/cjs/metadata/mixin.d.ts.map +1 -1
  5. package/dist/cjs/metadata/mixin.js +10 -0
  6. package/dist/cjs/metadata/mixin.js.map +1 -1
  7. package/dist/cjs/metadata/subgraph.d.ts +5 -1
  8. package/dist/cjs/metadata/subgraph.d.ts.map +1 -1
  9. package/dist/cjs/metadata/subgraph.js +71 -10
  10. package/dist/cjs/metadata/subgraph.js.map +1 -1
  11. package/dist/cjs/subgraph.d.ts +26358 -4612
  12. package/dist/cjs/subgraph.d.ts.map +1 -1
  13. package/dist/cjs/subgraph.js +344 -3
  14. package/dist/cjs/subgraph.js.map +1 -1
  15. package/dist/cjs/utils/graphql.d.ts +15 -0
  16. package/dist/cjs/utils/graphql.d.ts.map +1 -1
  17. package/dist/esm/core-sdk.d.ts.map +1 -1
  18. package/dist/esm/core-sdk.js.map +1 -1
  19. package/dist/esm/metadata/mixin.d.ts +7 -0
  20. package/dist/esm/metadata/mixin.d.ts.map +1 -1
  21. package/dist/esm/metadata/mixin.js +9 -1
  22. package/dist/esm/metadata/mixin.js.map +1 -1
  23. package/dist/esm/metadata/subgraph.d.ts +5 -1
  24. package/dist/esm/metadata/subgraph.d.ts.map +1 -1
  25. package/dist/esm/metadata/subgraph.js +68 -9
  26. package/dist/esm/metadata/subgraph.js.map +1 -1
  27. package/dist/esm/subgraph.d.ts +26358 -4612
  28. package/dist/esm/subgraph.d.ts.map +1 -1
  29. package/dist/esm/subgraph.js +340 -0
  30. package/dist/esm/subgraph.js.map +1 -1
  31. package/dist/esm/utils/graphql.d.ts +15 -0
  32. package/dist/esm/utils/graphql.d.ts.map +1 -1
  33. package/package.json +6 -4
  34. package/src/core-sdk.ts +4 -1
  35. package/src/metadata/bundle.graphql +128 -0
  36. package/src/metadata/mixin.ts +14 -1
  37. package/src/metadata/subgraph.ts +107 -10
  38. package/src/offers/queries.graphql +89 -0
  39. package/src/subgraph.ts +25604 -3318
@@ -0,0 +1,128 @@
1
+ query getBundleMetadataEntityByIdQuery(
2
+ $metadataId: ID!
3
+ $metadataSkip: Int
4
+ $metadataFirst: Int
5
+ $metadataOrderBy: BundleMetadataEntity_orderBy
6
+ $metadataOrderDirection: OrderDirection
7
+ $metadataFilter: BundleMetadataEntity_filter
8
+ ) {
9
+ bundleMetadataEntity(id: $metadataId) {
10
+ ...BundleMetadataEntityFields
11
+ }
12
+ }
13
+
14
+ query getBundleMetadataEntitiesQuery(
15
+ $metadataSkip: Int
16
+ $metadataFirst: Int
17
+ $metadataOrderBy: BundleMetadataEntity_orderBy
18
+ $metadataOrderDirection: OrderDirection
19
+ $metadataFilter: BundleMetadataEntity_filter
20
+ ) {
21
+ bundleMetadataEntities(
22
+ skip: $metadataSkip
23
+ first: $metadataFirst
24
+ orderBy: $metadataOrderBy
25
+ orderDirection: $metadataOrderDirection
26
+ where: $metadataFilter
27
+ ) {
28
+ ...BundleMetadataEntityFields
29
+ }
30
+ }
31
+
32
+ fragment BundleMetadataEntityFields on BundleMetadataEntity {
33
+ ...BaseBundleMetadataEntityFields
34
+ }
35
+
36
+ fragment BaseBundleMetadataEntityFields on BundleMetadataEntity {
37
+ id
38
+ name
39
+ bundleUuid
40
+ description
41
+ externalUrl
42
+ animationUrl
43
+ animationMetadata {
44
+ ...BaseAnimationMetadataFields
45
+ }
46
+ licenseUrl
47
+ condition
48
+ schemaUrl
49
+ type
50
+ image
51
+ attributes {
52
+ traitType
53
+ value
54
+ displayType
55
+ }
56
+ offer {
57
+ ...BaseOfferFields
58
+ exchanges {
59
+ ...BaseExchangeFields
60
+ }
61
+ }
62
+ seller {
63
+ ...BaseSellerFields
64
+ }
65
+ exchangeToken {
66
+ ...BaseExchangeTokenFields
67
+ }
68
+ createdAt
69
+ voided
70
+ validFromDate
71
+ validUntilDate
72
+ quantityAvailable
73
+ numberOfCommits
74
+ numberOfRedemptions
75
+ productV1Seller {
76
+ ...BaseProductV1SellerFields
77
+ }
78
+ productUuids
79
+ items {
80
+ id
81
+ schemaUrl
82
+ type
83
+ metadataUri
84
+ ... on ProductV1ItemMetadataEntity {
85
+ uuid
86
+ productUuid
87
+ productVersion
88
+ product {
89
+ ...BaseProductV1ProductFields
90
+ }
91
+ variations {
92
+ ...BaseProductV1VariationFields
93
+ }
94
+ exchangePolicy {
95
+ ...BaseProductV1ExchangePolicyFields
96
+ }
97
+ shipping {
98
+ ...BaseProductV1ShippingOptionFields
99
+ }
100
+ productOverrides {
101
+ ...BaseProductV1ProductOverridesFields
102
+ }
103
+ }
104
+ ... on NftItemMetadataEntity {
105
+ name
106
+ description
107
+ image
108
+ externalUrl
109
+ animationUrl
110
+ youtubeUrl
111
+ chainId
112
+ contract
113
+ tokenId
114
+ tokenIdRange {
115
+ min
116
+ max
117
+ }
118
+ transferMethod
119
+ transferDelay
120
+ quantity
121
+ attributes {
122
+ traitType
123
+ value
124
+ displayType
125
+ }
126
+ }
127
+ }
128
+ }
@@ -8,7 +8,8 @@ import {
8
8
  getProductWithVariants,
9
9
  getProductWithVariantsFromOfferId,
10
10
  getAllProductsWithVariants,
11
- getAllProductsWithNotVoidedVariants
11
+ getAllProductsWithNotVoidedVariants,
12
+ getBundleMetadataEntities
12
13
  } from "./subgraph";
13
14
 
14
15
  export class MetadataMixin extends BaseCoreSDK {
@@ -68,6 +69,17 @@ export class MetadataMixin extends BaseCoreSDK {
68
69
  return getProductV1MetadataEntities(this._subgraphUrl, queryVars);
69
70
  }
70
71
 
72
+ /**
73
+ * Returns `BUNDLE` type offer metadata entities from subgraph.
74
+ * @param queryVars - Optional query variables to skip, order or filter.
75
+ * @returns BundleMetadataEntities from subgraph.
76
+ */
77
+ public async getBundleMetadataEntities(
78
+ queryVars?: subgraph.GetBundleMetadataEntitiesQueryQueryVariables
79
+ ): Promise<subgraph.BundleMetadataEntityFieldsFragment[]> {
80
+ return getBundleMetadataEntities(this._subgraphUrl, queryVars);
81
+ }
82
+
71
83
  public async getProductV1Products(
72
84
  queryVars?: subgraph.GetProductV1ProductsQueryQueryVariables
73
85
  ): Promise<subgraph.BaseProductV1ProductFieldsFragment[]> {
@@ -79,6 +91,7 @@ export class MetadataMixin extends BaseCoreSDK {
79
91
  productUuid: string
80
92
  ): Promise<{
81
93
  product: subgraph.BaseProductV1ProductFieldsFragment;
94
+ bundles: subgraph.BundleMetadataEntityFieldsFragment[];
82
95
  variants: Array<{
83
96
  offer: subgraph.OfferFieldsFragment;
84
97
  variations: Array<subgraph.ProductV1Variation>;
@@ -18,8 +18,15 @@ import {
18
18
  GetProductV1ProductsWithVariantsQueryQueryVariables,
19
19
  BaseProductV1ProductWithNotVoidedVariantsFieldsFragment,
20
20
  BaseProductV1ProductWithVariantsFieldsFragment,
21
- GetAllProductsWithNotVoidedVariantsQueryQueryVariables
21
+ GetAllProductsWithNotVoidedVariantsQueryQueryVariables,
22
+ GetBundleMetadataEntityByIdQueryQueryVariables,
23
+ GetBundleMetadataEntitiesQueryQueryVariables,
24
+ BundleMetadataEntityFieldsFragment,
25
+ ItemMetadataType,
26
+ ProductV1ItemMetadataEntity
22
27
  } from "../subgraph";
28
+ import { productV1 } from "..";
29
+ import { productV1Item } from "@bosonprotocol/metadata";
23
30
 
24
31
  export type SingleBaseMetadataEntityQueryVariables = Omit<
25
32
  GetBaseMetadataEntityByIdQueryQueryVariables,
@@ -31,6 +38,11 @@ export type SingleProductV1MetadataEntityQueryVariables = Omit<
31
38
  "metadataId"
32
39
  >;
33
40
 
41
+ export type SingleBundleMetadataEntityQueryVariables = Omit<
42
+ GetBundleMetadataEntityByIdQueryQueryVariables,
43
+ "metadataId"
44
+ >;
45
+
34
46
  export async function getBaseMetadataEntityByOfferId(
35
47
  subgraphUrl: string,
36
48
  offerId: BigNumberish,
@@ -87,6 +99,34 @@ export async function getProductV1MetadataEntities(
87
99
  return productV1MetadataEntities;
88
100
  }
89
101
 
102
+ export async function getBundleMetadataEntityByOfferId(
103
+ subgraphUrl: string,
104
+ offerId: BigNumberish,
105
+ queryVars: SingleBundleMetadataEntityQueryVariables = {}
106
+ ): Promise<BundleMetadataEntityFieldsFragment> {
107
+ const subgraphSdk = getSubgraphSdk(subgraphUrl);
108
+ const { bundleMetadataEntity } =
109
+ await subgraphSdk.getBundleMetadataEntityByIdQuery({
110
+ metadataId: `${offerId}-metadata`,
111
+ ...queryVars
112
+ });
113
+
114
+ return bundleMetadataEntity;
115
+ }
116
+
117
+ export async function getBundleMetadataEntities(
118
+ subgraphUrl: string,
119
+ queryVars: GetBundleMetadataEntitiesQueryQueryVariables = {}
120
+ ): Promise<BundleMetadataEntityFieldsFragment[]> {
121
+ const subgraphSdk = getSubgraphSdk(subgraphUrl);
122
+ const { bundleMetadataEntities = [] } =
123
+ await subgraphSdk.getBundleMetadataEntitiesQuery({
124
+ ...queryVars
125
+ });
126
+
127
+ return bundleMetadataEntities;
128
+ }
129
+
90
130
  export async function getProductV1Brands(
91
131
  subgraphUrl: string,
92
132
  queryVars: GetProductV1BrandsQueryQueryVariables = {}
@@ -157,32 +197,89 @@ export async function getProductWithVariants(
157
197
  productUuid: string
158
198
  ): Promise<{
159
199
  product: BaseProductV1ProductFieldsFragment;
200
+ bundles: BundleMetadataEntityFieldsFragment[];
160
201
  variants: {
161
202
  offer: OfferFieldsFragment;
162
203
  variations: ProductV1Variation[];
163
204
  }[];
164
205
  } | null> {
165
206
  // Look for ProductV1MetadataEntities, filtered per productUuid
166
- const metadataEntities = await getProductV1MetadataEntities(subgraphUrl, {
207
+ const productV1MetadataEntities = await getProductV1MetadataEntities(
208
+ subgraphUrl,
209
+ {
210
+ metadataFilter: {
211
+ productUuid,
212
+ offer_: {
213
+ sellerId
214
+ }
215
+ }
216
+ }
217
+ );
218
+ // Look for BundleMetadataEntities, filtered per productUuid
219
+ const bundleMetadataEntities = await getBundleMetadataEntities(subgraphUrl, {
167
220
  metadataFilter: {
168
- productUuid,
221
+ productUuids_contains: [productUuid],
169
222
  offer_: {
170
223
  sellerId
171
224
  }
172
225
  }
173
226
  });
174
- if (metadataEntities.length === 0) {
227
+ if (productV1MetadataEntities.length + bundleMetadataEntities.length === 0) {
175
228
  return null;
176
229
  }
230
+ const itemsFromBundles = bundleMetadataEntities.reduce((prev, bundle) => {
231
+ const itemsFromBundle = getProductV1ItemFromBundle(bundle, productUuid);
232
+ return [...prev, ...itemsFromBundle];
233
+ }, [] as { productV1Item: ProductV1ItemMetadataEntity; offer: ProductV1MetadataEntityFieldsFragment["offer"] }[]);
234
+ const product = productV1MetadataEntities.length
235
+ ? productV1MetadataEntities[0].product
236
+ : itemsFromBundles[0]?.productV1Item.product;
237
+ const variants = productV1MetadataEntities.map((m) => {
238
+ return {
239
+ offer: m.offer,
240
+ variations: m.variations
241
+ };
242
+ });
243
+ const variantsFromBundleMap = itemsFromBundles.reduce((map, item) => {
244
+ if (!map.has(item.offer.id)) {
245
+ // ensure only add the same offer once
246
+ map.set(item.offer.id, {
247
+ offer: item.offer,
248
+ variations: item.productV1Item.variations
249
+ });
250
+ }
251
+ return map;
252
+ }, new Map());
253
+ variants.push(...Array.from(variantsFromBundleMap.values()));
177
254
  return {
178
- product: metadataEntities[0].product,
179
- variants: metadataEntities.map((m) => {
255
+ product, // return the product
256
+ bundles: bundleMetadataEntities, // return all bundles that contain this product
257
+ variants // return all variants for this product
258
+ };
259
+ }
260
+
261
+ /** returns the productV1ItemMetadataEntities in a bundle for a given productUuid */
262
+ // Note: it may returns several items, in case the BUNDLE contains different variants of
263
+ // the same product (or even the same variant several times),
264
+ function getProductV1ItemFromBundle(
265
+ bundle: BundleMetadataEntityFieldsFragment,
266
+ productUuid: string
267
+ ): {
268
+ productV1Item: ProductV1ItemMetadataEntity;
269
+ offer: ProductV1MetadataEntityFieldsFragment["offer"];
270
+ }[] {
271
+ return bundle.items
272
+ .filter(
273
+ (item): item is ProductV1ItemMetadataEntity =>
274
+ item.type === ItemMetadataType.ItemProductV1
275
+ )
276
+ .filter((item) => item.productUuid === productUuid)
277
+ .map((item) => {
180
278
  return {
181
- offer: m.offer,
182
- variations: m.variations
279
+ productV1Item: item,
280
+ offer: bundle.offer as ProductV1MetadataEntityFieldsFragment["offer"]
183
281
  };
184
- })
185
- };
282
+ });
186
283
  }
187
284
 
188
285
  export async function getProductWithVariantsFromOfferId(
@@ -84,6 +84,34 @@ query getOffersMediaQuery(
84
84
  }
85
85
  }
86
86
  }
87
+ ... on BundleMetadataEntity {
88
+ bundleUuid
89
+ productV1Seller {
90
+ images {
91
+ url
92
+ }
93
+ }
94
+ items {
95
+ ... on ProductV1ItemMetadataEntity {
96
+ productOverrides {
97
+ visuals_images {
98
+ url
99
+ }
100
+ visuals_videos {
101
+ url
102
+ }
103
+ }
104
+ product {
105
+ visuals_images {
106
+ url
107
+ }
108
+ visuals_videos {
109
+ url
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
87
115
  }
88
116
  }
89
117
  }
@@ -189,6 +217,67 @@ fragment BaseOfferFields on Offer {
189
217
  ...BaseProductV1ShippingOptionFields
190
218
  }
191
219
  }
220
+ ... on BundleMetadataEntity {
221
+ bundleUuid
222
+ attributes {
223
+ traitType
224
+ value
225
+ displayType
226
+ }
227
+ createdAt
228
+ voided
229
+ validFromDate
230
+ validUntilDate
231
+ quantityAvailable
232
+ productV1Seller {
233
+ ...BaseProductV1SellerFields
234
+ }
235
+ items {
236
+ type
237
+ metadataUri
238
+ ... on ProductV1ItemMetadataEntity {
239
+ uuid
240
+ product {
241
+ ...BaseProductV1ProductFields
242
+ }
243
+ variations {
244
+ ...BaseProductV1VariationFields
245
+ }
246
+ exchangePolicy {
247
+ ...BaseProductV1ExchangePolicyFields
248
+ }
249
+ shipping {
250
+ ...BaseProductV1ShippingOptionFields
251
+ }
252
+ productOverrides {
253
+ ...BaseProductV1ProductOverridesFields
254
+ }
255
+ }
256
+ ... on NftItemMetadataEntity {
257
+ name
258
+ description
259
+ image
260
+ externalUrl
261
+ animationUrl
262
+ youtubeUrl
263
+ chainId
264
+ contract
265
+ tokenId
266
+ tokenIdRange {
267
+ min
268
+ max
269
+ }
270
+ transferMethod
271
+ transferDelay
272
+ quantity
273
+ attributes {
274
+ traitType
275
+ value
276
+ displayType
277
+ }
278
+ }
279
+ }
280
+ }
192
281
  }
193
282
  range {
194
283
  ...BaseRangeFields