brainerce 1.42.0 → 1.43.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 CHANGED
@@ -46,7 +46,7 @@ Every Brainerce storefront must include **all mandatory features** below. Featur
46
46
  | Forgot / reset password | `client.forgotPassword()`, `client.resetPassword()` | ✅ |
47
47
  | OAuth sign-in buttons + callback handler | `client.getAvailableOAuthProviders()` | ✅ |
48
48
  | Account area (profile + order history) | `client.getMyProfile()`, `client.getMyOrders()` | ✅ |
49
- | Loyalty & rewards (points balance + redeem) | `client.getLoyaltyStatus()`, `client.getAvailableRewards()`, `client.redeemLoyaltyReward(id)` | conditional |
49
+ | Loyalty & rewards (points balance + tiers + redeem) | `client.getLoyaltyStatus()`, `client.getAvailableRewards()`, `client.redeemLoyaltyReward(id)`, `client.reportSocialShare()` | conditional |
50
50
  | Global header: cart count + search autocomplete | `client.getCart()`, `client.getSearchSuggestions(query)` | ✅ |
51
51
  | Discount banners + product badges | `client.getDiscountBanners()`, `client.getProductDiscountBadge(productId)` | ✅ |
52
52
  | Product reviews on PDP + JSON-LD aggregateRating | `client.listProductReviews(id)`, `client.submitProductReview(id, …)` | ✅ |
@@ -2920,23 +2920,35 @@ customers check their points balance, enroll, and redeem rewards for one-time
2920
2920
  coupons that apply at checkout.
2921
2921
 
2922
2922
  ```typescript
2923
- // Current status — points balance + program display config.
2924
- // `program` is null if the store has no loyalty program.
2923
+ // Current status — points balance + program display config + tier progress.
2924
+ // `program`/`tier`/`nextTier` are null if the store has no loyalty program
2925
+ // (or no tiers configured / the customer hasn't reached one yet).
2925
2926
  const status = await client.getLoyaltyStatus();
2926
2927
  if (status.enrolled) {
2927
2928
  console.log(`${status.pointsBalance} ${status.program?.pointsName}`);
2929
+ if (status.nextTier) {
2930
+ console.log(`${status.pointsToNextTier} to reach ${status.nextTier.name}`);
2931
+ }
2928
2932
  }
2929
2933
 
2930
- // Enroll (idempotent) — only if the program is ACTIVE.
2934
+ // Enroll (idempotent) — only if the program is ACTIVE. May grant a one-time
2935
+ // "join the program" bonus if the store has one configured.
2931
2936
  await client.enrollInLoyalty();
2932
2937
 
2933
- // Rewards the customer can redeem, cheapest first.
2938
+ // Rewards the customer can redeem, cheapest first (already filtered to ones
2939
+ // their current tier qualifies for).
2934
2940
  const rewards = await client.getAvailableRewards();
2935
2941
 
2936
2942
  // Redeem → spends points, returns a one-time coupon code to apply to the cart.
2937
- const { couponCode, discountValue, pointsBalance } =
2943
+ // `discountType` tells you how to interpret `discountValue` (currency amount
2944
+ // for FIXED_DISCOUNT, 0-100 percent for PERCENT_DISCOUNT).
2945
+ const { couponCode, discountType, discountValue, pointsBalance } =
2938
2946
  await client.redeemLoyaltyReward(rewards[0].id);
2939
2947
  await client.applyCoupon(cartId, couponCode);
2948
+
2949
+ // Self-reported social share — grants the SOCIAL_SHARE bonus if configured
2950
+ // (once per customer).
2951
+ await client.reportSocialShare('instagram');
2940
2952
  ```
2941
2953
 
2942
2954
  #### Auth Response Type
package/dist/index.d.mts CHANGED
@@ -248,6 +248,21 @@ interface CustomerProfile {
248
248
  createdAt: string;
249
249
  updatedAt: string;
250
250
  }
251
+ /** The membership tier a customer currently holds, or is progressing toward. */
252
+ interface LoyaltyTierSummary {
253
+ id: string;
254
+ name: string;
255
+ /** Ordering; higher = better tier. */
256
+ level: number;
257
+ /** Points-earning multiplier this tier grants (e.g. 1.5 = 50% more points per order). */
258
+ pointsMultiplier: number;
259
+ }
260
+ /** The next tier up, including what it takes to qualify. */
261
+ interface LoyaltyNextTierSummary extends LoyaltyTierSummary {
262
+ qualificationType: 'SPEND' | 'POINTS';
263
+ /** Threshold in store currency (SPEND) or points (POINTS). */
264
+ qualificationThreshold: number;
265
+ }
251
266
  /** A store's loyalty program status for a logged-in customer. */
252
267
  interface LoyaltyStatus {
253
268
  /** Whether the customer has a membership in the program. */
@@ -264,21 +279,32 @@ interface LoyaltyStatus {
264
279
  currencyRatio: number;
265
280
  status: 'DRAFT' | 'ACTIVE' | 'PAUSED';
266
281
  } | null;
267
- }
268
- /** A reward a customer can redeem points for (fixed-amount discount coupon). */
282
+ /** The customer's current tier, or null if untiered / no tiers configured. */
283
+ tier: LoyaltyTierSummary | null;
284
+ /** The next tier up, or null if already at the top tier (or no tiers configured). */
285
+ nextTier: LoyaltyNextTierSummary | null;
286
+ /** 0..1 progress toward nextTier; 1 if no nextTier and a tier is held. */
287
+ progressToNextTier: number;
288
+ /** Remaining spend/points needed to reach nextTier, or null if there's no nextTier. */
289
+ pointsToNextTier: number | null;
290
+ }
291
+ /** A reward a customer can redeem points for. */
269
292
  interface LoyaltyReward {
270
293
  id: string;
271
294
  name: string;
272
295
  description: string | null;
273
296
  /** Points required to redeem this reward. */
274
297
  pointsCost: number;
275
- /** Fixed discount amount the minted coupon is worth, in store currency. */
298
+ /** FIXED_DISCOUNT: discountValue is a store-currency amount off. PERCENT_DISCOUNT: discountValue is a 0-100 percent off. */
299
+ type: 'FIXED_DISCOUNT' | 'PERCENT_DISCOUNT';
276
300
  discountValue: number;
277
301
  /** Minimum order amount for the coupon to apply, or null. */
278
302
  minOrderAmount: number | null;
279
303
  /** How many times a single customer may redeem this reward. */
280
304
  maxUsesPerUser: number;
281
305
  isActive: boolean;
306
+ /** Minimum tier level required to redeem this reward, or null for no restriction. */
307
+ minTierLevel: number | null;
282
308
  createdAt: string;
283
309
  updatedAt: string;
284
310
  }
@@ -286,7 +312,9 @@ interface LoyaltyReward {
286
312
  interface RedeemRewardResult {
287
313
  /** The minted one-time coupon code to apply at checkout. */
288
314
  couponCode: string;
289
- /** Fixed discount amount the coupon is worth. */
315
+ /** Matches the redeemed reward's `type` tells you how to interpret discountValue. */
316
+ discountType: 'FIXED_DISCOUNT' | 'PERCENT_DISCOUNT';
317
+ /** Currency amount (FIXED_DISCOUNT) or percent 0-100 (PERCENT_DISCOUNT) the coupon is worth. */
290
318
  discountValue: number;
291
319
  /** Points spent on this redemption. */
292
320
  pointsSpent: number;
@@ -8662,6 +8690,21 @@ declare class BrainerceClient {
8662
8690
  * ```
8663
8691
  */
8664
8692
  redeemLoyaltyReward(rewardId: string): Promise<RedeemRewardResult>;
8693
+ /**
8694
+ * Report a social share, granting the SOCIAL_SHARE earning-rule bonus if the
8695
+ * store has one configured (requires customerToken). Self-reported — no
8696
+ * share-tracking infra — and capped at once per customer per program. Only
8697
+ * available in storefront mode.
8698
+ *
8699
+ * @example
8700
+ * ```typescript
8701
+ * await client.reportSocialShare('instagram');
8702
+ * ```
8703
+ */
8704
+ reportSocialShare(platform?: string): Promise<{
8705
+ awarded: boolean;
8706
+ points: number;
8707
+ }>;
8665
8708
  /**
8666
8709
  * Get the current customer's orders (requires customerToken)
8667
8710
  * Works in vibe-coded and storefront modes
package/dist/index.d.ts CHANGED
@@ -248,6 +248,21 @@ interface CustomerProfile {
248
248
  createdAt: string;
249
249
  updatedAt: string;
250
250
  }
251
+ /** The membership tier a customer currently holds, or is progressing toward. */
252
+ interface LoyaltyTierSummary {
253
+ id: string;
254
+ name: string;
255
+ /** Ordering; higher = better tier. */
256
+ level: number;
257
+ /** Points-earning multiplier this tier grants (e.g. 1.5 = 50% more points per order). */
258
+ pointsMultiplier: number;
259
+ }
260
+ /** The next tier up, including what it takes to qualify. */
261
+ interface LoyaltyNextTierSummary extends LoyaltyTierSummary {
262
+ qualificationType: 'SPEND' | 'POINTS';
263
+ /** Threshold in store currency (SPEND) or points (POINTS). */
264
+ qualificationThreshold: number;
265
+ }
251
266
  /** A store's loyalty program status for a logged-in customer. */
252
267
  interface LoyaltyStatus {
253
268
  /** Whether the customer has a membership in the program. */
@@ -264,21 +279,32 @@ interface LoyaltyStatus {
264
279
  currencyRatio: number;
265
280
  status: 'DRAFT' | 'ACTIVE' | 'PAUSED';
266
281
  } | null;
267
- }
268
- /** A reward a customer can redeem points for (fixed-amount discount coupon). */
282
+ /** The customer's current tier, or null if untiered / no tiers configured. */
283
+ tier: LoyaltyTierSummary | null;
284
+ /** The next tier up, or null if already at the top tier (or no tiers configured). */
285
+ nextTier: LoyaltyNextTierSummary | null;
286
+ /** 0..1 progress toward nextTier; 1 if no nextTier and a tier is held. */
287
+ progressToNextTier: number;
288
+ /** Remaining spend/points needed to reach nextTier, or null if there's no nextTier. */
289
+ pointsToNextTier: number | null;
290
+ }
291
+ /** A reward a customer can redeem points for. */
269
292
  interface LoyaltyReward {
270
293
  id: string;
271
294
  name: string;
272
295
  description: string | null;
273
296
  /** Points required to redeem this reward. */
274
297
  pointsCost: number;
275
- /** Fixed discount amount the minted coupon is worth, in store currency. */
298
+ /** FIXED_DISCOUNT: discountValue is a store-currency amount off. PERCENT_DISCOUNT: discountValue is a 0-100 percent off. */
299
+ type: 'FIXED_DISCOUNT' | 'PERCENT_DISCOUNT';
276
300
  discountValue: number;
277
301
  /** Minimum order amount for the coupon to apply, or null. */
278
302
  minOrderAmount: number | null;
279
303
  /** How many times a single customer may redeem this reward. */
280
304
  maxUsesPerUser: number;
281
305
  isActive: boolean;
306
+ /** Minimum tier level required to redeem this reward, or null for no restriction. */
307
+ minTierLevel: number | null;
282
308
  createdAt: string;
283
309
  updatedAt: string;
284
310
  }
@@ -286,7 +312,9 @@ interface LoyaltyReward {
286
312
  interface RedeemRewardResult {
287
313
  /** The minted one-time coupon code to apply at checkout. */
288
314
  couponCode: string;
289
- /** Fixed discount amount the coupon is worth. */
315
+ /** Matches the redeemed reward's `type` tells you how to interpret discountValue. */
316
+ discountType: 'FIXED_DISCOUNT' | 'PERCENT_DISCOUNT';
317
+ /** Currency amount (FIXED_DISCOUNT) or percent 0-100 (PERCENT_DISCOUNT) the coupon is worth. */
290
318
  discountValue: number;
291
319
  /** Points spent on this redemption. */
292
320
  pointsSpent: number;
@@ -8662,6 +8690,21 @@ declare class BrainerceClient {
8662
8690
  * ```
8663
8691
  */
8664
8692
  redeemLoyaltyReward(rewardId: string): Promise<RedeemRewardResult>;
8693
+ /**
8694
+ * Report a social share, granting the SOCIAL_SHARE earning-rule bonus if the
8695
+ * store has one configured (requires customerToken). Self-reported — no
8696
+ * share-tracking infra — and capped at once per customer per program. Only
8697
+ * available in storefront mode.
8698
+ *
8699
+ * @example
8700
+ * ```typescript
8701
+ * await client.reportSocialShare('instagram');
8702
+ * ```
8703
+ */
8704
+ reportSocialShare(platform?: string): Promise<{
8705
+ awarded: boolean;
8706
+ points: number;
8707
+ }>;
8665
8708
  /**
8666
8709
  * Get the current customer's orders (requires customerToken)
8667
8710
  * Works in vibe-coded and storefront modes
package/dist/index.js CHANGED
@@ -6411,6 +6411,33 @@ var BrainerceClient = class {
6411
6411
  }
6412
6412
  throw new BrainerceError("redeemLoyaltyReward is only available in storefront mode", 400);
6413
6413
  }
6414
+ /**
6415
+ * Report a social share, granting the SOCIAL_SHARE earning-rule bonus if the
6416
+ * store has one configured (requires customerToken). Self-reported — no
6417
+ * share-tracking infra — and capped at once per customer per program. Only
6418
+ * available in storefront mode.
6419
+ *
6420
+ * @example
6421
+ * ```typescript
6422
+ * await client.reportSocialShare('instagram');
6423
+ * ```
6424
+ */
6425
+ async reportSocialShare(platform) {
6426
+ if (!this.customerToken && !this.proxyMode) {
6427
+ throw new BrainerceError(
6428
+ "Customer token required. Call setCustomerToken() after login.",
6429
+ 401
6430
+ );
6431
+ }
6432
+ if (this.storeId && !this.apiKey) {
6433
+ return this.storefrontRequest(
6434
+ "POST",
6435
+ "/loyalty/social-share",
6436
+ platform ? { platform } : {}
6437
+ );
6438
+ }
6439
+ throw new BrainerceError("reportSocialShare is only available in storefront mode", 400);
6440
+ }
6414
6441
  /**
6415
6442
  * Get the current customer's orders (requires customerToken)
6416
6443
  * Works in vibe-coded and storefront modes
package/dist/index.mjs CHANGED
@@ -6341,6 +6341,33 @@ var BrainerceClient = class {
6341
6341
  }
6342
6342
  throw new BrainerceError("redeemLoyaltyReward is only available in storefront mode", 400);
6343
6343
  }
6344
+ /**
6345
+ * Report a social share, granting the SOCIAL_SHARE earning-rule bonus if the
6346
+ * store has one configured (requires customerToken). Self-reported — no
6347
+ * share-tracking infra — and capped at once per customer per program. Only
6348
+ * available in storefront mode.
6349
+ *
6350
+ * @example
6351
+ * ```typescript
6352
+ * await client.reportSocialShare('instagram');
6353
+ * ```
6354
+ */
6355
+ async reportSocialShare(platform) {
6356
+ if (!this.customerToken && !this.proxyMode) {
6357
+ throw new BrainerceError(
6358
+ "Customer token required. Call setCustomerToken() after login.",
6359
+ 401
6360
+ );
6361
+ }
6362
+ if (this.storeId && !this.apiKey) {
6363
+ return this.storefrontRequest(
6364
+ "POST",
6365
+ "/loyalty/social-share",
6366
+ platform ? { platform } : {}
6367
+ );
6368
+ }
6369
+ throw new BrainerceError("reportSocialShare is only available in storefront mode", 400);
6370
+ }
6344
6371
  /**
6345
6372
  * Get the current customer's orders (requires customerToken)
6346
6373
  * Works in vibe-coded and storefront modes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brainerce",
3
- "version": "1.42.0",
3
+ "version": "1.43.0",
4
4
  "description": "Official SDK for building e-commerce storefronts with Brainerce Platform. Perfect for vibe-coded sites, AI-built stores (Cursor, Lovable, v0), and custom storefronts.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",