@tbox.cn/app-provider-mock 0.6.0 → 0.6.2

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.
@@ -232,11 +232,15 @@ declare const mockMallInfoFactory: ServiceAdapterFactory;
232
232
  * - body `{userId?}`:缺省 = 调用方 token 身份(统一登录改造 T11 收口——固定 demo-user
233
233
  * 缺省退役,IDOR 写任意用户面收窄为「已鉴权调用方声明 demo 主体」;gate 页经 query
234
234
  * 透传 H5 身份,curl 可定向翻指定访客造会员态调试)。
235
- * - 幂等(Set.add / 余额保守写);NODE_ENV=production → 503(provider-mock 不进生产装配,双保险)。
235
+ * - 幂等(Set.add / 余额保守写);NODE_ENV 不设防(2026-09-21 裁决:mock 装配即演示开关——
236
+ * mock 档 prod 演示部署为合法场景,登录换码链在 prod 已放行,enroll/logout 不再单独设防)。
236
237
  * - 经全局 /api 鉴权(AUTH_MODE 缺省 required)——调用方须携登录令牌;
237
238
  * 匿名写显式拒绝(不随 AUTH_MODE 放宽)。
238
239
  * - doctor naked-write-route:/demo 前缀在白名单内(webhook/upload/demo/run)。
239
240
  *
241
+ * ⚠️ 同构副本:provider-mocktest/src/server/mock-enroll-route.ts——双包 twins,
242
+ * 任何改动须同步(仅路由命名空间与 SDK import 允许差异)。
243
+ *
240
244
  * 决策逻辑抽纯函数 resolveMockEnroll(单测直达,路由层只做 HTTP 形状映射)。
241
245
  */
242
246
 
@@ -347,7 +347,7 @@ var MockPromotionServiceImpl = class {
347
347
  offerType: "COUPON",
348
348
  title: CFG3.couponTitle,
349
349
  subtitle: "\u5168\u573A\u901A\u7528\uFF08mock \u6F14\u793A\uFF09",
350
- imageUrl: "https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*LHeBTp64HUYAAAAARLAAAAgAegitAQ/fmt.webp",
350
+ imageUrl: "https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*UiQ2S7W7eaUAAAAARAAAAAgAegitAQ/fmt.webp",
351
351
  tags: ["\u901A\u7528"],
352
352
  validity: { start: ts, end: inDays(CFG3.couponValidityDays) },
353
353
  facets: [{ kind: "COUPON", discountType: "AMOUNT", value: CFG3.couponValueCents, thresholdCents: CFG3.couponThresholdCents }],
@@ -382,7 +382,7 @@ var MockPromotionServiceImpl = class {
382
382
  activityRef: "demo:activity:3001",
383
383
  title: CFG3.activityTitle,
384
384
  subtitle: "mock \u6F14\u793A\u6D3B\u52A8",
385
- coverUrl: "https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*DIRTQ6CBBC0AAAAAgEAAAAgAegitAQ/fmt.webp",
385
+ coverUrl: "https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*yXl6Ta2WcjIAAAAARyAAAAgAegitAQ/fmt.webp",
386
386
  registrationRequired: false,
387
387
  offerRefs: ["demo:coupon:1001"]
388
388
  }
@@ -645,9 +645,6 @@ var mockMallInfoFactory = (input) => {
645
645
  import { Router } from "express";
646
646
  import { getRequestContext } from "@tbox.cn/app-agent-sdk-server";
647
647
  function resolveMockEnroll(input) {
648
- if ((input.nodeEnv ?? process.env.NODE_ENV) === "production") {
649
- return { status: 503, body: { error: "mock-only" } };
650
- }
651
648
  if (!input.identity || input.identity.source === "anonymous") {
652
649
  return { status: 401, body: { error: "unauthorized" } };
653
650
  }
@@ -657,9 +654,6 @@ function resolveMockEnroll(input) {
657
654
  return { status: 200, body: { state: "active", memberRef: `demo:member:${userId}` } };
658
655
  }
659
656
  function resolveMockLogout(input) {
660
- if ((input.nodeEnv ?? process.env.NODE_ENV) === "production") {
661
- return { status: 503, body: { error: "mock-only" } };
662
- }
663
657
  if (!input.identity || input.identity.source === "anonymous") {
664
658
  return { status: 401, body: { error: "unauthorized" } };
665
659
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-provider-mock",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "type": "module",
5
5
  "description": "商圈 Mock Provider 包(极简零配置):17 槽 local 供给开箱即用——免传输/凭据/实例配置/集成配置;config 消费与配置验证面见 @tbox.cn/app-provider-mocktest。",
6
6
  "exports": {
@@ -5,11 +5,15 @@
5
5
  * - body `{userId?}`:缺省 = 调用方 token 身份(统一登录改造 T11 收口——固定 demo-user
6
6
  * 缺省退役,IDOR 写任意用户面收窄为「已鉴权调用方声明 demo 主体」;gate 页经 query
7
7
  * 透传 H5 身份,curl 可定向翻指定访客造会员态调试)。
8
- * - 幂等(Set.add / 余额保守写);NODE_ENV=production → 503(provider-mock 不进生产装配,双保险)。
8
+ * - 幂等(Set.add / 余额保守写);NODE_ENV 不设防(2026-09-21 裁决:mock 装配即演示开关——
9
+ * mock 档 prod 演示部署为合法场景,登录换码链在 prod 已放行,enroll/logout 不再单独设防)。
9
10
  * - 经全局 /api 鉴权(AUTH_MODE 缺省 required)——调用方须携登录令牌;
10
11
  * 匿名写显式拒绝(不随 AUTH_MODE 放宽)。
11
12
  * - doctor naked-write-route:/demo 前缀在白名单内(webhook/upload/demo/run)。
12
13
  *
14
+ * ⚠️ 同构副本:provider-mocktest/src/server/mock-enroll-route.ts——双包 twins,
15
+ * 任何改动须同步(仅路由命名空间与 SDK import 允许差异)。
16
+ *
13
17
  * 决策逻辑抽纯函数 resolveMockEnroll(单测直达,路由层只做 HTTP 形状映射)。
14
18
  */
15
19
  import { Router } from 'express';
@@ -19,18 +23,13 @@ import { enrollMockMember, logoutMockMember } from './member';
19
23
 
20
24
  export type MockEnrollOutcome =
21
25
  | { status: 200; body: { state: 'active'; memberRef: string } }
22
- | { status: 401; body: { error: string } }
23
- | { status: 503; body: { error: string } };
26
+ | { status: 401; body: { error: string } };
24
27
 
25
- /** 纯决策:production 拒 503 → 匿名/无身份拒 401 → 翻状态返 200(幂等;主体缺省 = 调用方) */
28
+ /** 纯决策(零环境读取——NODE_ENV 不设防,见头注):匿名/无身份拒 401 → 翻状态返 200(幂等;主体缺省 = 调用方) */
26
29
  export function resolveMockEnroll(input: {
27
30
  body?: unknown;
28
31
  identity?: { source: string; userId?: string } | null;
29
- nodeEnv?: string;
30
32
  }): MockEnrollOutcome {
31
- if ((input.nodeEnv ?? process.env.NODE_ENV) === 'production') {
32
- return { status: 503, body: { error: 'mock-only' } };
33
- }
34
33
  if (!input.identity || input.identity.source === 'anonymous') {
35
34
  return { status: 401, body: { error: 'unauthorized' } };
36
35
  }
@@ -44,18 +43,13 @@ export function resolveMockEnroll(input: {
44
43
 
45
44
  export type MockLogoutOutcome =
46
45
  | { status: 200; body: { state: 'logged_out' } }
47
- | { status: 401; body: { error: string } }
48
- | { status: 503; body: { error: string } };
46
+ | { status: 401; body: { error: string } };
49
47
 
50
- /** 纯决策:production 拒 503 → 匿名/无身份拒 401 → 翻登出态返 200(与 enroll 同形;主体缺省 = 调用方) */
48
+ /** 纯决策(与 enroll 同形同律):匿名/无身份拒 401 → 翻登出态返 200(主体缺省 = 调用方) */
51
49
  export function resolveMockLogout(input: {
52
50
  body?: unknown;
53
51
  identity?: { source: string; userId?: string } | null;
54
- nodeEnv?: string;
55
52
  }): MockLogoutOutcome {
56
- if ((input.nodeEnv ?? process.env.NODE_ENV) === 'production') {
57
- return { status: 503, body: { error: 'mock-only' } };
58
- }
59
53
  if (!input.identity || input.identity.source === 'anonymous') {
60
54
  return { status: 401, body: { error: 'unauthorized' } };
61
55
  }
@@ -56,7 +56,7 @@ export class MockPromotionServiceImpl implements MockPromotionService {
56
56
  offerType: 'COUPON',
57
57
  title: CFG.couponTitle,
58
58
  subtitle: '全场通用(mock 演示)',
59
- imageUrl: 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*LHeBTp64HUYAAAAARLAAAAgAegitAQ/fmt.webp',
59
+ imageUrl: 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*UiQ2S7W7eaUAAAAARAAAAAgAegitAQ/fmt.webp',
60
60
  tags: ['通用'],
61
61
  validity: { start: ts, end: inDays(CFG.couponValidityDays) },
62
62
  facets: [{ kind: 'COUPON', discountType: 'AMOUNT', value: CFG.couponValueCents, thresholdCents: CFG.couponThresholdCents }],
@@ -91,7 +91,7 @@ export class MockPromotionServiceImpl implements MockPromotionService {
91
91
  activityRef: 'demo:activity:3001',
92
92
  title: CFG.activityTitle,
93
93
  subtitle: 'mock 演示活动',
94
- coverUrl: 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*DIRTQ6CBBC0AAAAAgEAAAAgAegitAQ/fmt.webp',
94
+ coverUrl: 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*yXl6Ta2WcjIAAAAARyAAAAgAegitAQ/fmt.webp',
95
95
  registrationRequired: false,
96
96
  offerRefs: ['demo:coupon:1001'],
97
97
  },
@@ -122,7 +122,7 @@ describe('provider-mock:mock 实现 Port 面与厂商中立', () => {
122
122
  expect(page.items).toEqual(expect.arrayContaining([
123
123
  expect.objectContaining({
124
124
  title: '满 100 减 20 元券',
125
- imageUrl: 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*LHeBTp64HUYAAAAARLAAAAgAegitAQ/fmt.webp',
125
+ imageUrl: 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*UiQ2S7W7eaUAAAAARAAAAAgAegitAQ/fmt.webp',
126
126
  }),
127
127
  expect.objectContaining({
128
128
  title: '餐饮双人套餐 5 折',
@@ -132,9 +132,9 @@ describe('provider-mock:mock 实现 Port 面与厂商中立', () => {
132
132
  const detail = await promotion.getOfferDetail(promoCtx, { offerRef: 'demo:coupon:1001' });
133
133
  expect(detail?.title).toContain('满 100 减 20');
134
134
  const activities = await promotion.listActivities();
135
- expect(activities.items[0]?.coverUrl).toBe('https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*DIRTQ6CBBC0AAAAAgEAAAAgAegitAQ/fmt.webp');
135
+ expect(activities.items[0]?.coverUrl).toBe('https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*yXl6Ta2WcjIAAAAARyAAAAgAegitAQ/fmt.webp');
136
136
  const activityDetail = await promotion.getActivityDetail(promoCtx, 'demo:activity:3001');
137
- expect(activityDetail?.coverUrl).toBe('https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*DIRTQ6CBBC0AAAAAgEAAAAgAegitAQ/fmt.webp');
137
+ expect(activityDetail?.coverUrl).toBe('https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*yXl6Ta2WcjIAAAAARyAAAAgAegitAQ/fmt.webp');
138
138
  const op = await promotion.acquire(promoCtx, { offerRef: 'demo:coupon:1001', externalMemberRef: 'demo:member:u1', idempotencyKey: 'k1' });
139
139
  expect(op.status).toBe('SUCCEEDED');
140
140
  });
@@ -348,10 +348,8 @@ describe('provider-mock:mock 入会落地路由(resolveMockEnroll 纯决策
348
348
  expect(isMockMemberEnrolled('demo-user')).toBe(false);
349
349
  });
350
350
 
351
- it('NODE_ENV=production → 503(mock 不进生产装配,双保险)', () => {
352
- expect(resolveMockEnroll({ body: {}, identity: { source: 'local' }, nodeEnv: 'production' }).status).toBe(503);
353
- expect(isMockMemberEnrolled('demo-user')).toBe(false);
354
- });
351
+ // NODE_ENV 不设防(2026-09-21 裁决:mock 装配即演示开关——prod 演示部署 enroll 同链放行)。
352
+ // 纯函数零环境读取,生产可用性由「无分支」构造性成立,上列 200/401 用例即生产行为全谱。
355
353
  });
356
354
 
357
355
  describe('provider-mock:登出态(logout 路由 + 换码降级 GUEST 形态 + getAccount 感知)', () => {
@@ -367,11 +365,10 @@ describe('provider-mock:登出态(logout 路由 + 换码降级 GUEST 形态
367
365
  expect(isMockMemberLoggedOut('guest_a1')).toBe(false);
368
366
  });
369
367
 
370
- it('resolveMockLogout:匿名/无身份 → 401;production → 503(与 enroll 同形)', () => {
368
+ it('resolveMockLogout:匿名/无身份 → 401(与 enroll 同形同律)', () => {
371
369
  __resetMockMemberState();
372
370
  expect(resolveMockLogout({ body: {}, identity: null }).status).toBe(401);
373
371
  expect(resolveMockLogout({ body: {}, identity: { source: 'anonymous' } }).status).toBe(401);
374
- expect(resolveMockLogout({ body: {}, identity: { source: 'local' }, nodeEnv: 'production' }).status).toBe(503);
375
372
  expect(isMockMemberLoggedOut('demo-user')).toBe(false);
376
373
  });
377
374