@open-mercato/checkout 0.10.1-develop.7954.1.48da4a7d13 → 0.10.1-develop.7972.1.03f813eaaf

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.
@@ -10,31 +10,37 @@ function stableUuidFromString(input) {
10
10
  const hex = Buffer.from(bytes).toString("hex");
11
11
  return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
12
12
  }
13
+ async function ensureTransactionExpirySchedule(ctx) {
14
+ const cradle = ctx.container;
15
+ if (typeof cradle.hasRegistration !== "function" || !cradle.hasRegistration("schedulerService")) return;
16
+ const schedulerService = ctx.container.resolve("schedulerService");
17
+ await schedulerService.register({
18
+ id: stableUuidFromString(`checkout:transaction-expiry:${ctx.tenantId}:${ctx.organizationId}`),
19
+ name: "Checkout transaction expiry",
20
+ description: "Marks stale checkout transactions as expired and runs usage limit updates.",
21
+ scopeType: "organization",
22
+ organizationId: ctx.organizationId,
23
+ tenantId: ctx.tenantId,
24
+ scheduleType: "interval",
25
+ scheduleValue: "10m",
26
+ timezone: "UTC",
27
+ targetType: "queue",
28
+ targetQueue: CHECKOUT_EXPIRY_QUEUE,
29
+ sourceType: "module",
30
+ sourceModule: "checkout",
31
+ isEnabled: true
32
+ });
33
+ }
13
34
  const setup = {
14
35
  async seedDefaults(ctx) {
15
36
  await ensureCheckoutFieldsetsAndDefinitions(ctx.em, {
16
37
  tenantId: ctx.tenantId,
17
38
  organizationId: ctx.organizationId
18
39
  });
19
- const cradle = ctx.container;
20
- if (typeof cradle.hasRegistration !== "function" || !cradle.hasRegistration("schedulerService")) return;
21
- const schedulerService = ctx.container.resolve("schedulerService");
22
- await schedulerService.register({
23
- id: stableUuidFromString(`checkout:transaction-expiry:${ctx.tenantId}:${ctx.organizationId}`),
24
- name: "Checkout transaction expiry",
25
- description: "Marks stale checkout transactions as expired and runs usage limit updates.",
26
- scopeType: "organization",
27
- organizationId: ctx.organizationId,
28
- tenantId: ctx.tenantId,
29
- scheduleType: "interval",
30
- scheduleValue: "10m",
31
- timezone: "UTC",
32
- targetType: "queue",
33
- targetQueue: CHECKOUT_EXPIRY_QUEUE,
34
- sourceType: "module",
35
- sourceModule: "checkout",
36
- isEnabled: true
37
- });
40
+ await ensureTransactionExpirySchedule(ctx);
41
+ },
42
+ async onOrganizationCreated(ctx) {
43
+ await ensureTransactionExpirySchedule(ctx);
38
44
  },
39
45
  defaultRoleFeatures: {
40
46
  superadmin: ["checkout.*"],
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/modules/checkout/setup.ts"],
4
- "sourcesContent": ["import type { ModuleSetupConfig } from '@open-mercato/shared/modules/setup'\nimport { createHash } from 'node:crypto'\nimport { ensureCheckoutFieldsetsAndDefinitions } from './seed/customFields'\nimport { seedCheckoutExamples } from './seed/examples'\nimport { CHECKOUT_EXPIRY_QUEUE } from './workers/transaction-expiry.worker'\nexport { DEFAULT_CHECKOUT_CUSTOMER_FIELDS } from './lib/defaults'\n\nfunction stableUuidFromString(input: string): string {\n const bytes = createHash('sha256').update(input).digest().subarray(0, 16)\n bytes[6] = (bytes[6] & 0x0f) | 0x50\n bytes[8] = (bytes[8] & 0x3f) | 0x80\n const hex = Buffer.from(bytes).toString('hex')\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`\n}\n\ntype SchedulerServiceLike = {\n register: (registration: {\n id: string\n name: string\n description?: string\n scopeType: 'organization'\n organizationId: string\n tenantId: string\n scheduleType: 'cron' | 'interval'\n scheduleValue: string\n timezone?: string\n targetType: 'queue'\n targetQueue: string\n targetPayload?: Record<string, unknown>\n sourceType: 'module'\n sourceModule: string\n isEnabled?: boolean\n }) => Promise<void>\n}\n\nexport const setup: ModuleSetupConfig = {\n async seedDefaults(ctx) {\n await ensureCheckoutFieldsetsAndDefinitions(ctx.em, {\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n })\n\n const cradle = ctx.container as { hasRegistration?: (name: string) => boolean }\n if (typeof cradle.hasRegistration !== 'function' || !cradle.hasRegistration('schedulerService')) return\n\n const schedulerService = ctx.container.resolve('schedulerService') as SchedulerServiceLike\n await schedulerService.register({\n id: stableUuidFromString(`checkout:transaction-expiry:${ctx.tenantId}:${ctx.organizationId}`),\n name: 'Checkout transaction expiry',\n description: 'Marks stale checkout transactions as expired and runs usage limit updates.',\n scopeType: 'organization',\n organizationId: ctx.organizationId,\n tenantId: ctx.tenantId,\n scheduleType: 'interval',\n scheduleValue: '10m',\n timezone: 'UTC',\n targetType: 'queue',\n targetQueue: CHECKOUT_EXPIRY_QUEUE,\n sourceType: 'module',\n sourceModule: 'checkout',\n isEnabled: true,\n })\n },\n\n defaultRoleFeatures: {\n superadmin: ['checkout.*'],\n admin: ['checkout.view', 'checkout.create', 'checkout.edit', 'checkout.delete', 'checkout.viewPii', 'checkout.export'],\n employee: ['checkout.view'],\n },\n\n async seedExamples(ctx) {\n await seedCheckoutExamples(ctx)\n },\n}\n\nexport default setup\n"],
5
- "mappings": "AACA,SAAS,kBAAkB;AAC3B,SAAS,6CAA6C;AACtD,SAAS,4BAA4B;AACrC,SAAS,6BAA6B;AACtC,SAAS,wCAAwC;AAEjD,SAAS,qBAAqB,OAAuB;AACnD,QAAM,QAAQ,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,GAAG,EAAE;AACxE,QAAM,CAAC,IAAK,MAAM,CAAC,IAAI,KAAQ;AAC/B,QAAM,CAAC,IAAK,MAAM,CAAC,IAAI,KAAQ;AAC/B,QAAM,MAAM,OAAO,KAAK,KAAK,EAAE,SAAS,KAAK;AAC7C,SAAO,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC;AAC9G;AAsBO,MAAM,QAA2B;AAAA,EACtC,MAAM,aAAa,KAAK;AACtB,UAAM,sCAAsC,IAAI,IAAI;AAAA,MAClD,UAAU,IAAI;AAAA,MACd,gBAAgB,IAAI;AAAA,IACtB,CAAC;AAED,UAAM,SAAS,IAAI;AACnB,QAAI,OAAO,OAAO,oBAAoB,cAAc,CAAC,OAAO,gBAAgB,kBAAkB,EAAG;AAEjG,UAAM,mBAAmB,IAAI,UAAU,QAAQ,kBAAkB;AACjE,UAAM,iBAAiB,SAAS;AAAA,MAC9B,IAAI,qBAAqB,+BAA+B,IAAI,QAAQ,IAAI,IAAI,cAAc,EAAE;AAAA,MAC5F,MAAM;AAAA,MACN,aAAa;AAAA,MACb,WAAW;AAAA,MACX,gBAAgB,IAAI;AAAA,MACpB,UAAU,IAAI;AAAA,MACd,cAAc;AAAA,MACd,eAAe;AAAA,MACf,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,aAAa;AAAA,MACb,YAAY;AAAA,MACZ,cAAc;AAAA,MACd,WAAW;AAAA,IACb,CAAC;AAAA,EACH;AAAA,EAEA,qBAAqB;AAAA,IACnB,YAAY,CAAC,YAAY;AAAA,IACzB,OAAO,CAAC,iBAAiB,mBAAmB,iBAAiB,mBAAmB,oBAAoB,iBAAiB;AAAA,IACrH,UAAU,CAAC,eAAe;AAAA,EAC5B;AAAA,EAEA,MAAM,aAAa,KAAK;AACtB,UAAM,qBAAqB,GAAG;AAAA,EAChC;AACF;AAEA,IAAO,gBAAQ;",
4
+ "sourcesContent": ["import type { ModuleSetupConfig } from '@open-mercato/shared/modules/setup'\nimport { createHash } from 'node:crypto'\nimport { ensureCheckoutFieldsetsAndDefinitions } from './seed/customFields'\nimport { seedCheckoutExamples } from './seed/examples'\nimport { CHECKOUT_EXPIRY_QUEUE } from './workers/transaction-expiry.worker'\nexport { DEFAULT_CHECKOUT_CUSTOMER_FIELDS } from './lib/defaults'\n\nfunction stableUuidFromString(input: string): string {\n const bytes = createHash('sha256').update(input).digest().subarray(0, 16)\n bytes[6] = (bytes[6] & 0x0f) | 0x50\n bytes[8] = (bytes[8] & 0x3f) | 0x80\n const hex = Buffer.from(bytes).toString('hex')\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`\n}\n\ntype SchedulerServiceLike = {\n register: (registration: {\n id: string\n name: string\n description?: string\n scopeType: 'organization'\n organizationId: string\n tenantId: string\n scheduleType: 'cron' | 'interval'\n scheduleValue: string\n timezone?: string\n targetType: 'queue'\n targetQueue: string\n targetPayload?: Record<string, unknown>\n sourceType: 'module'\n sourceModule: string\n isEnabled?: boolean\n }) => Promise<void>\n}\n\nasync function ensureTransactionExpirySchedule(ctx: {\n container: import('awilix').AwilixContainer\n tenantId: string\n organizationId: string\n}): Promise<void> {\n const cradle = ctx.container as { hasRegistration?: (name: string) => boolean }\n if (typeof cradle.hasRegistration !== 'function' || !cradle.hasRegistration('schedulerService')) return\n\n const schedulerService = ctx.container.resolve('schedulerService') as SchedulerServiceLike\n await schedulerService.register({\n id: stableUuidFromString(`checkout:transaction-expiry:${ctx.tenantId}:${ctx.organizationId}`),\n name: 'Checkout transaction expiry',\n description: 'Marks stale checkout transactions as expired and runs usage limit updates.',\n scopeType: 'organization',\n organizationId: ctx.organizationId,\n tenantId: ctx.tenantId,\n scheduleType: 'interval',\n scheduleValue: '10m',\n timezone: 'UTC',\n targetType: 'queue',\n targetQueue: CHECKOUT_EXPIRY_QUEUE,\n sourceType: 'module',\n sourceModule: 'checkout',\n isEnabled: true,\n })\n}\n\nexport const setup: ModuleSetupConfig = {\n async seedDefaults(ctx) {\n await ensureCheckoutFieldsetsAndDefinitions(ctx.em, {\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n })\n\n await ensureTransactionExpirySchedule(ctx)\n },\n\n async onOrganizationCreated(ctx) {\n await ensureTransactionExpirySchedule(ctx)\n },\n\n defaultRoleFeatures: {\n superadmin: ['checkout.*'],\n admin: ['checkout.view', 'checkout.create', 'checkout.edit', 'checkout.delete', 'checkout.viewPii', 'checkout.export'],\n employee: ['checkout.view'],\n },\n\n async seedExamples(ctx) {\n await seedCheckoutExamples(ctx)\n },\n}\n\nexport default setup\n"],
5
+ "mappings": "AACA,SAAS,kBAAkB;AAC3B,SAAS,6CAA6C;AACtD,SAAS,4BAA4B;AACrC,SAAS,6BAA6B;AACtC,SAAS,wCAAwC;AAEjD,SAAS,qBAAqB,OAAuB;AACnD,QAAM,QAAQ,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,GAAG,EAAE;AACxE,QAAM,CAAC,IAAK,MAAM,CAAC,IAAI,KAAQ;AAC/B,QAAM,CAAC,IAAK,MAAM,CAAC,IAAI,KAAQ;AAC/B,QAAM,MAAM,OAAO,KAAK,KAAK,EAAE,SAAS,KAAK;AAC7C,SAAO,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC;AAC9G;AAsBA,eAAe,gCAAgC,KAI7B;AAChB,QAAM,SAAS,IAAI;AACnB,MAAI,OAAO,OAAO,oBAAoB,cAAc,CAAC,OAAO,gBAAgB,kBAAkB,EAAG;AAEjG,QAAM,mBAAmB,IAAI,UAAU,QAAQ,kBAAkB;AACjE,QAAM,iBAAiB,SAAS;AAAA,IAC9B,IAAI,qBAAqB,+BAA+B,IAAI,QAAQ,IAAI,IAAI,cAAc,EAAE;AAAA,IAC5F,MAAM;AAAA,IACN,aAAa;AAAA,IACb,WAAW;AAAA,IACX,gBAAgB,IAAI;AAAA,IACpB,UAAU,IAAI;AAAA,IACd,cAAc;AAAA,IACd,eAAe;AAAA,IACf,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,aAAa;AAAA,IACb,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,WAAW;AAAA,EACb,CAAC;AACH;AAEO,MAAM,QAA2B;AAAA,EACtC,MAAM,aAAa,KAAK;AACtB,UAAM,sCAAsC,IAAI,IAAI;AAAA,MAClD,UAAU,IAAI;AAAA,MACd,gBAAgB,IAAI;AAAA,IACtB,CAAC;AAED,UAAM,gCAAgC,GAAG;AAAA,EAC3C;AAAA,EAEA,MAAM,sBAAsB,KAAK;AAC/B,UAAM,gCAAgC,GAAG;AAAA,EAC3C;AAAA,EAEA,qBAAqB;AAAA,IACnB,YAAY,CAAC,YAAY;AAAA,IACzB,OAAO,CAAC,iBAAiB,mBAAmB,iBAAiB,mBAAmB,oBAAoB,iBAAiB;AAAA,IACrH,UAAU,CAAC,eAAe;AAAA,EAC5B;AAAA,EAEA,MAAM,aAAa,KAAK;AACtB,UAAM,qBAAqB,GAAG;AAAA,EAChC;AACF;AAEA,IAAO,gBAAQ;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/checkout",
3
- "version": "0.10.1-develop.7954.1.48da4a7d13",
3
+ "version": "0.10.1-develop.7972.1.03f813eaaf",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -62,18 +62,18 @@
62
62
  }
63
63
  },
64
64
  "dependencies": {
65
- "@open-mercato/core": "0.10.1-develop.7954.1.48da4a7d13",
66
- "@open-mercato/ui": "0.10.1-develop.7954.1.48da4a7d13",
65
+ "@open-mercato/core": "0.10.1-develop.7972.1.03f813eaaf",
66
+ "@open-mercato/ui": "0.10.1-develop.7972.1.03f813eaaf",
67
67
  "bcryptjs": "^3.0.3"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "@mikro-orm/postgresql": "^7.0.14",
71
- "@open-mercato/shared": "0.10.1-develop.7954.1.48da4a7d13",
71
+ "@open-mercato/shared": "0.10.1-develop.7972.1.03f813eaaf",
72
72
  "react": "^19.0.0",
73
73
  "react-dom": "^19.0.0"
74
74
  },
75
75
  "devDependencies": {
76
- "@open-mercato/shared": "0.10.1-develop.7954.1.48da4a7d13",
76
+ "@open-mercato/shared": "0.10.1-develop.7972.1.03f813eaaf",
77
77
  "@types/jest": "^30.0.0",
78
78
  "@types/react": "^19.2.18",
79
79
  "@types/react-dom": "^19.2.5",
@@ -48,6 +48,12 @@ async function seedDefaults(context: InitSetupContext): Promise<void> {
48
48
  await setup.seedDefaults(context)
49
49
  }
50
50
 
51
+ async function onOrganizationCreated(context: InitSetupContext): Promise<void> {
52
+ const { setup } = await import('../setup')
53
+ if (!setup.onOrganizationCreated) throw new Error('[internal] Checkout onOrganizationCreated hook is missing')
54
+ await setup.onOrganizationCreated(context)
55
+ }
56
+
51
57
  describe('checkout setup schedules', () => {
52
58
  it('registers one organization-scoped transaction-expiry schedule', async () => {
53
59
  const { context, register } = createSetupContext({})
@@ -62,6 +68,16 @@ describe('checkout setup schedules', () => {
62
68
  }))
63
69
  })
64
70
 
71
+ it('registers the schedule for a later organization without replaying tenant defaults', async () => {
72
+ const { context, register } = createSetupContext({ organizationId: 'organization-2' })
73
+ ensureCheckoutFieldsetsAndDefinitions.mockClear()
74
+
75
+ await onOrganizationCreated(context)
76
+
77
+ expect(register).toHaveBeenCalledWith(expect.objectContaining({ organizationId: 'organization-2' }))
78
+ expect(ensureCheckoutFieldsetsAndDefinitions).not.toHaveBeenCalled()
79
+ })
80
+
65
81
  it('uses stable IDs that remain distinct across organizations in one tenant', async () => {
66
82
  const first = createSetupContext({ organizationId: 'organization-1' })
67
83
  const second = createSetupContext({ organizationId: 'organization-2' })
@@ -33,6 +33,33 @@ type SchedulerServiceLike = {
33
33
  }) => Promise<void>
34
34
  }
35
35
 
36
+ async function ensureTransactionExpirySchedule(ctx: {
37
+ container: import('awilix').AwilixContainer
38
+ tenantId: string
39
+ organizationId: string
40
+ }): Promise<void> {
41
+ const cradle = ctx.container as { hasRegistration?: (name: string) => boolean }
42
+ if (typeof cradle.hasRegistration !== 'function' || !cradle.hasRegistration('schedulerService')) return
43
+
44
+ const schedulerService = ctx.container.resolve('schedulerService') as SchedulerServiceLike
45
+ await schedulerService.register({
46
+ id: stableUuidFromString(`checkout:transaction-expiry:${ctx.tenantId}:${ctx.organizationId}`),
47
+ name: 'Checkout transaction expiry',
48
+ description: 'Marks stale checkout transactions as expired and runs usage limit updates.',
49
+ scopeType: 'organization',
50
+ organizationId: ctx.organizationId,
51
+ tenantId: ctx.tenantId,
52
+ scheduleType: 'interval',
53
+ scheduleValue: '10m',
54
+ timezone: 'UTC',
55
+ targetType: 'queue',
56
+ targetQueue: CHECKOUT_EXPIRY_QUEUE,
57
+ sourceType: 'module',
58
+ sourceModule: 'checkout',
59
+ isEnabled: true,
60
+ })
61
+ }
62
+
36
63
  export const setup: ModuleSetupConfig = {
37
64
  async seedDefaults(ctx) {
38
65
  await ensureCheckoutFieldsetsAndDefinitions(ctx.em, {
@@ -40,26 +67,11 @@ export const setup: ModuleSetupConfig = {
40
67
  organizationId: ctx.organizationId,
41
68
  })
42
69
 
43
- const cradle = ctx.container as { hasRegistration?: (name: string) => boolean }
44
- if (typeof cradle.hasRegistration !== 'function' || !cradle.hasRegistration('schedulerService')) return
70
+ await ensureTransactionExpirySchedule(ctx)
71
+ },
45
72
 
46
- const schedulerService = ctx.container.resolve('schedulerService') as SchedulerServiceLike
47
- await schedulerService.register({
48
- id: stableUuidFromString(`checkout:transaction-expiry:${ctx.tenantId}:${ctx.organizationId}`),
49
- name: 'Checkout transaction expiry',
50
- description: 'Marks stale checkout transactions as expired and runs usage limit updates.',
51
- scopeType: 'organization',
52
- organizationId: ctx.organizationId,
53
- tenantId: ctx.tenantId,
54
- scheduleType: 'interval',
55
- scheduleValue: '10m',
56
- timezone: 'UTC',
57
- targetType: 'queue',
58
- targetQueue: CHECKOUT_EXPIRY_QUEUE,
59
- sourceType: 'module',
60
- sourceModule: 'checkout',
61
- isEnabled: true,
62
- })
73
+ async onOrganizationCreated(ctx) {
74
+ await ensureTransactionExpirySchedule(ctx)
63
75
  },
64
76
 
65
77
  defaultRoleFeatures: {