@porulle/plugin-loyalty 0.11.0 → 0.13.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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAM,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAG3D,YAAY,EAAE,oBAAoB,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,wBAAgB,aAAa,CAAC,WAAW,GAAE,oBAAyB,0CAsCnE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAM,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAG3D,YAAY,EAAE,oBAAoB,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,wBAAgB,aAAa,CAAC,WAAW,GAAE,oBAAyB,0CAsCnE"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineCommercePlugin, resolveOrgId } from "@porulle/core";
1
+ import { defineCommercePlugin, resolveOrgIdForCommerce } from "@porulle/core";
2
2
  import { loyaltyPoints, loyaltyTransactions, loyaltyRedemptionOffers } from "./schema.js";
3
3
  import { LoyaltyService } from "./services/loyalty-service.js";
4
4
  import { buildLoyaltyRoutes } from "./routes/loyalty.js";
@@ -22,7 +22,7 @@ export function loyaltyPlugin(userOptions = {}) {
22
22
  const rawDb = context.services.database?.db;
23
23
  if (!rawDb)
24
24
  return;
25
- const orgId = resolveOrgId(context.actor);
25
+ const orgId = resolveOrgIdForCommerce(context.actor, context.commerceConfig);
26
26
  const pointsEarned = Math.floor((result.grandTotal / 100) * options.pointsPerDollar);
27
27
  if (pointsEarned <= 0)
28
28
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@porulle/plugin-loyalty",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -19,14 +19,14 @@
19
19
  "dependencies": {
20
20
  "@hono/zod-openapi": "^1.2.2",
21
21
  "hono": "^4.12.5",
22
- "@porulle/core": "0.11.0"
22
+ "@porulle/core": "0.13.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^24.5.2",
26
26
  "typescript": "5.9.2",
27
27
  "vitest": "^3.2.4",
28
- "@porulle/eslint-config": "0.1.0",
29
- "@porulle/typescript-config": "0.1.0"
28
+ "@porulle/typescript-config": "0.1.0",
29
+ "@porulle/eslint-config": "0.1.0"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { defineCommercePlugin, resolveOrgId } from "@porulle/core";
1
+ import { defineCommercePlugin, resolveOrgIdForCommerce } from "@porulle/core";
2
+ import type { CommerceConfig } from "@porulle/core";
2
3
  import { eq, and, sql } from "@porulle/core/drizzle";
3
4
  import { loyaltyPoints, loyaltyTransactions, loyaltyRedemptionOffers } from "./schema.js";
4
5
  import { LoyaltyService } from "./services/loyalty-service.js";
@@ -24,13 +25,13 @@ export function loyaltyPlugin(userOptions: LoyaltyPluginOptions = {}) {
24
25
  async handler(args: unknown) {
25
26
  const { result, context } = args as {
26
27
  result: { id: string; customerId?: string; grandTotal: number };
27
- context: { actor?: { organizationId?: string | null } | null; logger: { info(msg: string, data?: unknown): void }; services: { database?: { db: unknown } } };
28
+ context: { actor?: { organizationId?: string | null } | null; commerceConfig?: CommerceConfig | null; logger: { info(msg: string, data?: unknown): void }; services: { database?: { db: unknown } } };
28
29
  };
29
30
  if (!result.customerId) return;
30
31
  const rawDb = context.services.database?.db;
31
32
  if (!rawDb) return;
32
33
 
33
- const orgId = resolveOrgId(context.actor);
34
+ const orgId = resolveOrgIdForCommerce(context.actor, context.commerceConfig);
34
35
  const pointsEarned = Math.floor((result.grandTotal / 100) * options.pointsPerDollar);
35
36
  if (pointsEarned <= 0) return;
36
37