@propeller-commerce/propeller-v2-react-ui 0.9.0 → 0.10.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/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@ import { Services, ShopMode, UserMode, PriceComponentProps, StockComponentProps,
3
3
  export * from '@propeller-commerce/propeller-v2-core-ui';
4
4
  import * as React$1 from 'react';
5
5
  import React__default, { ReactNode, ComponentType } from 'react';
6
- import { GraphQLClient, Contact, Customer, Cart, CartMainItem, Product, Cluster, AddressType, Gender, YesNo, Address, TransformationsInput, MediaImageProductSearchInput, CartProcessResponse, Crossupsell, CartUpdateAddressInput, CartUpdateInput, CartAddressType, ClusterConfig, Company, CompanyVariables, PurchaseAuthorizationConfigCreateInput, PurchaseAuthorizationConfigUpdateInput, FavoriteList, DateSearchInput, DecimalSearchInput, OrderSortInput, OrderType, OrderSearchFields, Order, ProductTextFilterInput, AttributeFilter, ProductsResponse, Category, SparePart, ProductSortField, SortOrder, SparePartsResponse, SparePartsMachine, CrossupsellType, AttributeResult, RegisterContactInput as RegisterContactInput$1, PurchaseAuthorizationConfig, CartChildItemInput, CartAddress, WarehouseAddress, OrderAddress, CartBaseItem, CartCarrier, CartPaymethod, ClusterOption, ProductInventory, OrderItem, ProductPrice, Bundle, PaginatedMediaDocumentResponse, PaginatedMediaVideoResponse } from '@propeller-commerce/propeller-sdk-v2';
6
+ import { GraphQLClient, Contact, Customer, Cart, CartMainItem, Product, Cluster, AddressType, Gender, YesNo, Address, MagicTokenCreateInput, MagicToken, TransformationsInput, MediaImageProductSearchInput, CartProcessResponse, Crossupsell, CartUpdateAddressInput, CartUpdateInput, CartAddressType, ClusterConfig, Company, CompanyVariables, PurchaseAuthorizationConfigCreateInput, PurchaseAuthorizationConfigUpdateInput, FavoriteList, DateSearchInput, DecimalSearchInput, OrderSortInput, OrderType, OrderSearchFields, Order, ProductTextFilterInput, AttributeFilter, ProductsResponse, Category, SparePart, ProductSortField, SortOrder, SparePartsResponse, SparePartsMachine, CrossupsellType, AttributeResult, RegisterContactInput as RegisterContactInput$1, PurchaseAuthorizationConfig, CartChildItemInput, CartAddress, WarehouseAddress, OrderAddress, CartBaseItem, CartCarrier, CartPaymethod, ClusterOption, ProductInventory, OrderItem, ProductPrice, Bundle, PaginatedMediaDocumentResponse, PaginatedMediaVideoResponse } from '@propeller-commerce/propeller-sdk-v2';
7
7
 
8
8
  /**
9
9
  * Tier 1 — application-wide infrastructure. Bound by `<PropellerDepsProvider>`
@@ -499,6 +499,10 @@ interface UseAuthReturn {
499
499
  error: string | null;
500
500
  /** Authenticates by email/password; pass `onLoginSubmit` to fully override the SDK login. */
501
501
  login: (email: string, password: string, onLoginSubmit?: (email: string, password: string) => Promise<Contact | Customer>) => Promise<Result<AuthSuccess, string>>;
502
+ /** Passwordless login: exchanges a backend-issued magic token for a session (then loads the viewer). */
503
+ magicLogin: (token: string) => Promise<Result<AuthSuccess, string>>;
504
+ /** Issues a magic token for a contact/customer (authenticated); its `id` is embedded in a magic-login link. */
505
+ createMagicToken: (input: MagicTokenCreateInput) => Promise<Result<MagicToken, string>>;
502
506
  /** Registers a B2B contact (and optionally a company + addresses); `autoLogin` keeps the session. */
503
507
  registerContact: (input: RegisterContactInput, preferredLanguage?: string, autoLogin?: boolean) => Promise<Result<AuthSuccess, string>>;
504
508
  /** Registers a B2C customer (and optionally addresses); `autoLogin` keeps the session. */
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { Services, ShopMode, UserMode, PriceComponentProps, StockComponentProps,
3
3
  export * from '@propeller-commerce/propeller-v2-core-ui';
4
4
  import * as React$1 from 'react';
5
5
  import React__default, { ReactNode, ComponentType } from 'react';
6
- import { GraphQLClient, Contact, Customer, Cart, CartMainItem, Product, Cluster, AddressType, Gender, YesNo, Address, TransformationsInput, MediaImageProductSearchInput, CartProcessResponse, Crossupsell, CartUpdateAddressInput, CartUpdateInput, CartAddressType, ClusterConfig, Company, CompanyVariables, PurchaseAuthorizationConfigCreateInput, PurchaseAuthorizationConfigUpdateInput, FavoriteList, DateSearchInput, DecimalSearchInput, OrderSortInput, OrderType, OrderSearchFields, Order, ProductTextFilterInput, AttributeFilter, ProductsResponse, Category, SparePart, ProductSortField, SortOrder, SparePartsResponse, SparePartsMachine, CrossupsellType, AttributeResult, RegisterContactInput as RegisterContactInput$1, PurchaseAuthorizationConfig, CartChildItemInput, CartAddress, WarehouseAddress, OrderAddress, CartBaseItem, CartCarrier, CartPaymethod, ClusterOption, ProductInventory, OrderItem, ProductPrice, Bundle, PaginatedMediaDocumentResponse, PaginatedMediaVideoResponse } from '@propeller-commerce/propeller-sdk-v2';
6
+ import { GraphQLClient, Contact, Customer, Cart, CartMainItem, Product, Cluster, AddressType, Gender, YesNo, Address, MagicTokenCreateInput, MagicToken, TransformationsInput, MediaImageProductSearchInput, CartProcessResponse, Crossupsell, CartUpdateAddressInput, CartUpdateInput, CartAddressType, ClusterConfig, Company, CompanyVariables, PurchaseAuthorizationConfigCreateInput, PurchaseAuthorizationConfigUpdateInput, FavoriteList, DateSearchInput, DecimalSearchInput, OrderSortInput, OrderType, OrderSearchFields, Order, ProductTextFilterInput, AttributeFilter, ProductsResponse, Category, SparePart, ProductSortField, SortOrder, SparePartsResponse, SparePartsMachine, CrossupsellType, AttributeResult, RegisterContactInput as RegisterContactInput$1, PurchaseAuthorizationConfig, CartChildItemInput, CartAddress, WarehouseAddress, OrderAddress, CartBaseItem, CartCarrier, CartPaymethod, ClusterOption, ProductInventory, OrderItem, ProductPrice, Bundle, PaginatedMediaDocumentResponse, PaginatedMediaVideoResponse } from '@propeller-commerce/propeller-sdk-v2';
7
7
 
8
8
  /**
9
9
  * Tier 1 — application-wide infrastructure. Bound by `<PropellerDepsProvider>`
@@ -499,6 +499,10 @@ interface UseAuthReturn {
499
499
  error: string | null;
500
500
  /** Authenticates by email/password; pass `onLoginSubmit` to fully override the SDK login. */
501
501
  login: (email: string, password: string, onLoginSubmit?: (email: string, password: string) => Promise<Contact | Customer>) => Promise<Result<AuthSuccess, string>>;
502
+ /** Passwordless login: exchanges a backend-issued magic token for a session (then loads the viewer). */
503
+ magicLogin: (token: string) => Promise<Result<AuthSuccess, string>>;
504
+ /** Issues a magic token for a contact/customer (authenticated); its `id` is embedded in a magic-login link. */
505
+ createMagicToken: (input: MagicTokenCreateInput) => Promise<Result<MagicToken, string>>;
502
506
  /** Registers a B2B contact (and optionally a company + addresses); `autoLogin` keeps the session. */
503
507
  registerContact: (input: RegisterContactInput, preferredLanguage?: string, autoLogin?: boolean) => Promise<Result<AuthSuccess, string>>;
504
508
  /** Registers a B2C customer (and optionally addresses); `autoLogin` keeps the session. */
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ export * from '@propeller-commerce/propeller-v2-core-ui';
4
4
  import * as React6 from 'react';
5
5
  import { createContext, useState, useRef, useMemo, useCallback, useContext, useEffect } from 'react';
6
6
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
7
- import { ProductStatus, ProductSortField, SortOrder, PurchaseRole, CrossupsellType, CartStatus, CartAddressType, Gender, YesNo, AddressType, PaymentStatuses, OrderSearchFields, OrderItemClass, ProductSearchableField, machineService, AttributeType, OrderSortField, OrderType, OrderDiscountType, BundleCondition } from '@propeller-commerce/propeller-sdk-v2';
7
+ import { ProductStatus, ProductSortField, SortOrder, PurchaseRole, CrossupsellType, CartStatus, CartAddressType, Gender, YesNo, AddressType, MagicTokenService, PaymentStatuses, OrderSearchFields, OrderItemClass, ProductSearchableField, machineService, AttributeType, OrderSortField, OrderType, OrderDiscountType, BundleCondition } from '@propeller-commerce/propeller-sdk-v2';
8
8
  import { User } from 'lucide-react';
9
9
 
10
10
  // src/index.ts
@@ -287,6 +287,66 @@ function useAuth(options) {
287
287
  setLoading(false);
288
288
  }
289
289
  }, [graphqlClient, language, onAuthHeaderUpdate, configuration]);
290
+ const magicLogin = useCallback(async (token) => {
291
+ setLoading(true);
292
+ setError(null);
293
+ try {
294
+ const loginResult = await new MagicTokenService(graphqlClient).magicTokenLogin(token);
295
+ const session = loginResult?.session;
296
+ const accessToken = session?.accessToken;
297
+ const refreshToken = session?.refreshToken;
298
+ const expiresAt = session?.expirationTime;
299
+ if (accessToken) {
300
+ const cfg = graphqlClient.getConfig();
301
+ graphqlClient.updateConfig({
302
+ headers: { ...cfg.headers, Authorization: `Bearer ${accessToken}` }
303
+ });
304
+ onAuthHeaderUpdate?.(accessToken);
305
+ }
306
+ const userService = createServices(graphqlClient).user;
307
+ const viewerInput = {
308
+ ...configuration?.contactTrackAttributes?.length && {
309
+ contactAttributesInput: { attributeDescription: { names: configuration.contactTrackAttributes } }
310
+ },
311
+ ...configuration?.customerTrackAttributes?.length && {
312
+ customerAttributesInput: { attributeDescription: { names: configuration.customerTrackAttributes } }
313
+ },
314
+ ...configuration?.companyTrackAttributes?.length && {
315
+ companyAttributesInput: { attributeDescription: { names: configuration.companyTrackAttributes } }
316
+ },
317
+ // See isViewerSearchInput — an empty array `[]` is truthy but 400s the viewer.
318
+ ...isViewerSearchInput(configuration?.contactPAConfigInput) && {
319
+ contactPAConfigInput: configuration.contactPAConfigInput
320
+ },
321
+ ...isViewerSearchInput(configuration?.contactCompaniesSearchInput) && {
322
+ contactCompaniesSearchInput: configuration.contactCompaniesSearchInput
323
+ }
324
+ };
325
+ const viewer = await userService.getViewer(viewerInput);
326
+ const user = viewer;
327
+ return ok({ user, accessToken, refreshToken, expiresAt });
328
+ } catch (e) {
329
+ const msg = e instanceof Error ? e.message : "Magic-token login failed";
330
+ setError(msg);
331
+ return err(msg);
332
+ } finally {
333
+ setLoading(false);
334
+ }
335
+ }, [graphqlClient, onAuthHeaderUpdate, configuration]);
336
+ const createMagicToken = useCallback(async (input) => {
337
+ setLoading(true);
338
+ setError(null);
339
+ try {
340
+ const token = await new MagicTokenService(graphqlClient).createMagicToken(input);
341
+ return ok(token);
342
+ } catch (e) {
343
+ const msg = e instanceof Error ? e.message : "Failed to create magic token";
344
+ setError(msg);
345
+ return err(msg);
346
+ } finally {
347
+ setLoading(false);
348
+ }
349
+ }, [graphqlClient]);
290
350
  const registerContact = useCallback(async (input, preferredLanguage = language, autoLogin = true) => {
291
351
  setLoading(true);
292
352
  setError(null);
@@ -533,7 +593,7 @@ function useAuth(options) {
533
593
  setLoading(false);
534
594
  }
535
595
  }, [graphqlClient]);
536
- return { loading, error, login, registerContact, registerCustomer, forgotPassword };
596
+ return { loading, error, login, magicLogin, createMagicToken, registerContact, registerCustomer, forgotPassword };
537
597
  }
538
598
  async function initCart(config) {
539
599
  const {