@daffodil/driver 0.89.0 → 0.90.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.
@@ -1,11 +1,11 @@
1
1
  import * as i1 from 'apollo-angular';
2
2
  import { gql, provideNamedApollo } from 'apollo-angular';
3
3
  import * as i0 from '@angular/core';
4
- import { Injectable, inject } from '@angular/core';
5
- import { InMemoryCache } from '@apollo/client/cache';
6
- import { from } from '@apollo/client/core';
4
+ import { Injectable, inject, InjectionToken } from '@angular/core';
5
+ import { InMemoryCache, from } from '@apollo/client/core';
7
6
  import { setContext } from '@apollo/client/link/context';
8
7
  import { onError } from '@apollo/client/link/error';
8
+ import { HttpHeaders } from '@angular/common/http';
9
9
  import { HttpLink } from 'apollo-angular/http';
10
10
 
11
11
  /** The set of valid sort keys for the Article query. */
@@ -2313,12 +2313,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.1", ngImpor
2313
2313
  * @returns An ApolloLink instance that sets authentication headers.
2314
2314
  */
2315
2315
  function createAuthLink(accessToken) {
2316
- return setContext(() => ({
2317
- headers: {
2318
- 'Content-Type': 'application/json',
2319
- 'X-Shopify-Storefront-Access-Token': accessToken,
2320
- },
2321
- }));
2316
+ return setContext(() => {
2317
+ if (typeof accessToken === 'function') {
2318
+ return {
2319
+ headers: {
2320
+ 'X-Shopify-Storefront-Access-Token': accessToken(),
2321
+ },
2322
+ };
2323
+ }
2324
+ return {
2325
+ headers: {
2326
+ 'X-Shopify-Storefront-Access-Token': accessToken,
2327
+ },
2328
+ };
2329
+ });
2322
2330
  }
2323
2331
 
2324
2332
  /**
@@ -2347,7 +2355,16 @@ function createErrorLink() {
2347
2355
  */
2348
2356
  function createHttpLink(url) {
2349
2357
  const httpLink = inject(HttpLink);
2350
- return httpLink.create({ uri: url });
2358
+ if (typeof url === 'function') {
2359
+ return httpLink.create({
2360
+ uri: () => `${url()}/api/2025-01/graphql.json`,
2361
+ headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
2362
+ });
2363
+ }
2364
+ return httpLink.create({
2365
+ uri: `${url}/api/2025-01/graphql.json`,
2366
+ headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
2367
+ });
2351
2368
  }
2352
2369
 
2353
2370
  /**
@@ -2359,24 +2376,38 @@ const APOLLO_CLIENT_NAME = 'shopify';
2359
2376
  /**
2360
2377
  * Provides an Apollo client configuration for Shopify's Storefront API.
2361
2378
  *
2362
- * @deprecated, prefer using provideShopifyDriver Deprecated in version 0.89.0. Will be removed in version 0.92.0.
2363
- *
2364
2379
  * @param domain - The Shopify store domain (e.g. "https://daffodil-demo-alpha.myshopify.com")
2365
2380
  * @param accessToken - The Shopify Storefront API access token.
2366
2381
  * @returns An Apollo client provider configured with a Shopify store domain and Storefront API access token.
2367
2382
  */
2368
- function provideShopifyApolloDriver(domain, accessToken) {
2369
- const shopifyStorefrontAPIEndpoint = `${domain}/api/2025-01/graphql.json`;
2370
- return provideNamedApollo(() => ({
2383
+ const provideShopifyDriver = (config) => provideNamedApollo(() => {
2384
+ const resolvedConfig = config instanceof InjectionToken ? inject(config) : config;
2385
+ return {
2371
2386
  [APOLLO_CLIENT_NAME]: {
2372
2387
  link: from([
2373
2388
  createErrorLink(),
2374
- createAuthLink(accessToken),
2375
- createHttpLink(shopifyStorefrontAPIEndpoint),
2389
+ createAuthLink(resolvedConfig.accessToken),
2390
+ createHttpLink(resolvedConfig.domain),
2376
2391
  ]),
2377
2392
  cache: new InMemoryCache(),
2378
2393
  },
2379
- }));
2394
+ };
2395
+ });
2396
+
2397
+ /**
2398
+ * Provides an Apollo client configuration for Shopify's Storefront API.
2399
+ *
2400
+ * @deprecated, prefer using provideShopifyDriver Deprecated in version 0.89.0. Will be removed in version 0.92.0.
2401
+ *
2402
+ * @param domain - The Shopify store domain (e.g. "https://daffodil-demo-alpha.myshopify.com")
2403
+ * @param accessToken - The Shopify Storefront API access token.
2404
+ * @returns An Apollo client provider configured with a Shopify store domain and Storefront API access token.
2405
+ */
2406
+ function provideShopifyApolloDriver(domain, accessToken) {
2407
+ return provideShopifyDriver({
2408
+ domain,
2409
+ accessToken,
2410
+ });
2380
2411
  }
2381
2412
 
2382
2413
  /**
@@ -2421,17 +2452,32 @@ const shopifyUrlTransformer = (url) => {
2421
2452
  };
2422
2453
 
2423
2454
  /**
2424
- * Provides an Apollo client configuration for Shopify's Storefront API.
2455
+ * Generates a route path based on the Shopify resource type and handle.
2425
2456
  *
2426
- * @param domain - The Shopify store domain (e.g. "https://daffodil-demo-alpha.myshopify.com")
2427
- * @param accessToken - The Shopify Storefront API access token.
2428
- * @returns An Apollo client provider configured with a Shopify store domain and Storefront API access token.
2457
+ * @param type The Shopify resource type (COLLECTION, PRODUCT, PAGE, etc.)
2458
+ * @param handle The resource handle/slug
2459
+ * @returns The formatted route path
2460
+ * @throws Error if type is empty
2429
2461
  */
2430
- const provideShopifyDriver = (domain, accessToken) => provideShopifyApolloDriver(domain, accessToken);
2462
+ const getShopifyRoutePath = (type, handle) => {
2463
+ if (!type) {
2464
+ throw new Error('Type cannot be empty');
2465
+ }
2466
+ switch (type) {
2467
+ case MenuItemType.Collection:
2468
+ return `/collections/${handle}`;
2469
+ case MenuItemType.Product:
2470
+ return `/products/${handle}`;
2471
+ case MenuItemType.Page:
2472
+ return `/pages/${handle}`;
2473
+ default:
2474
+ return `/${type.toLowerCase()}s/${handle}`;
2475
+ }
2476
+ };
2431
2477
 
2432
2478
  /**
2433
2479
  * Generated bundle index. Do not edit.
2434
2480
  */
2435
2481
 
2436
- export { APOLLO_CLIENT_NAME, ArticleSortKeys, BlogSortKeys, CardBrand, CartCardSource, CartDeliveryGroupType, CartErrorCode, CheckoutErrorCode, CollectionSortKeys, CompletionErrorCode, CountryCode, CropRegion, CurrencyCode, CustomerErrorCode, DeliveryAddressValidationStrategy, DeliveryMethodType, DigitalWallet, DiscountApplicationAllocationMethod, DiscountApplicationTargetSelection, DiscountApplicationTargetType, FilterPresentation, FilterType, ImageContentType, LanguageCode, LocationSortKeys, MediaContentType, MediaHost, MediaPresentationFormat, MenuItemType, MetafieldDeleteErrorCode, MetafieldsSetUserErrorCode, OrderCancelReason, OrderFinancialStatus, OrderFulfillmentStatus, OrderSortKeys, PageSortKeys, PaymentTokenType, PredictiveSearchLimitScope, PredictiveSearchType, PreferenceDeliveryMethodType, ProductCollectionSortKeys, ProductImageSortKeys, ProductMediaSortKeys, ProductRecommendationIntent, ProductSortKeys, ProductVariantSortKeys, SearchPrefixQueryType, SearchSortKeys, SearchType, SearchUnavailableProductsType, SearchableField, SellingPlanCheckoutChargeType, ShopifyGetAProductDocument, ShopifyGetAProductGQL, ShopifyGetAllProductsDocument, ShopifyGetAllProductsGQL, ShopifyGetProductByUrlDocument, ShopifyGetProductByUrlGQL, SubmissionErrorCode, TransactionKind, TransactionStatus, UnitPriceMeasurementMeasuredType, UnitPriceMeasurementMeasuredUnit, UnitSystem, WeightUnit, provideShopifyApolloDriver, provideShopifyDriver, shopifyHandleTransformer, shopifyIdTransformer, shopifyUrlTransformer };
2482
+ export { APOLLO_CLIENT_NAME, ArticleSortKeys, BlogSortKeys, CardBrand, CartCardSource, CartDeliveryGroupType, CartErrorCode, CheckoutErrorCode, CollectionSortKeys, CompletionErrorCode, CountryCode, CropRegion, CurrencyCode, CustomerErrorCode, DeliveryAddressValidationStrategy, DeliveryMethodType, DigitalWallet, DiscountApplicationAllocationMethod, DiscountApplicationTargetSelection, DiscountApplicationTargetType, FilterPresentation, FilterType, ImageContentType, LanguageCode, LocationSortKeys, MediaContentType, MediaHost, MediaPresentationFormat, MenuItemType, MetafieldDeleteErrorCode, MetafieldsSetUserErrorCode, OrderCancelReason, OrderFinancialStatus, OrderFulfillmentStatus, OrderSortKeys, PageSortKeys, PaymentTokenType, PredictiveSearchLimitScope, PredictiveSearchType, PreferenceDeliveryMethodType, ProductCollectionSortKeys, ProductImageSortKeys, ProductMediaSortKeys, ProductRecommendationIntent, ProductSortKeys, ProductVariantSortKeys, SearchPrefixQueryType, SearchSortKeys, SearchType, SearchUnavailableProductsType, SearchableField, SellingPlanCheckoutChargeType, ShopifyGetAProductDocument, ShopifyGetAProductGQL, ShopifyGetAllProductsDocument, ShopifyGetAllProductsGQL, ShopifyGetProductByUrlDocument, ShopifyGetProductByUrlGQL, SubmissionErrorCode, TransactionKind, TransactionStatus, UnitPriceMeasurementMeasuredType, UnitPriceMeasurementMeasuredUnit, UnitSystem, WeightUnit, getShopifyRoutePath, provideShopifyApolloDriver, provideShopifyDriver, shopifyHandleTransformer, shopifyIdTransformer, shopifyUrlTransformer };
2437
2483
  //# sourceMappingURL=daffodil-driver-shopify.mjs.map