@prenta/plugin-commerce 0.2.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/CHANGELOG.md +262 -0
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/__tests__/checkout.test.d.ts +2 -0
- package/dist/__tests__/checkout.test.d.ts.map +1 -0
- package/dist/__tests__/checkout.test.js +83 -0
- package/dist/__tests__/checkout.test.js.map +1 -0
- package/dist/__tests__/client.test.d.ts +2 -0
- package/dist/__tests__/client.test.d.ts.map +1 -0
- package/dist/__tests__/client.test.js +74 -0
- package/dist/__tests__/client.test.js.map +1 -0
- package/dist/__tests__/customer.test.d.ts +2 -0
- package/dist/__tests__/customer.test.d.ts.map +1 -0
- package/dist/__tests__/customer.test.js +21 -0
- package/dist/__tests__/customer.test.js.map +1 -0
- package/dist/__tests__/hooks.test.d.ts +2 -0
- package/dist/__tests__/hooks.test.d.ts.map +1 -0
- package/dist/__tests__/hooks.test.js +119 -0
- package/dist/__tests__/hooks.test.js.map +1 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.d.ts.map +1 -0
- package/dist/__tests__/index.test.js +37 -0
- package/dist/__tests__/index.test.js.map +1 -0
- package/dist/__tests__/products.test.d.ts +2 -0
- package/dist/__tests__/products.test.d.ts.map +1 -0
- package/dist/__tests__/products.test.js +39 -0
- package/dist/__tests__/products.test.js.map +1 -0
- package/dist/__tests__/webhooks.test.d.ts +2 -0
- package/dist/__tests__/webhooks.test.d.ts.map +1 -0
- package/dist/__tests__/webhooks.test.js +71 -0
- package/dist/__tests__/webhooks.test.js.map +1 -0
- package/dist/admin/CommerceDashboard.d.ts +35 -0
- package/dist/admin/CommerceDashboard.d.ts.map +1 -0
- package/dist/admin/CommerceDashboard.js +36 -0
- package/dist/admin/CommerceDashboard.js.map +1 -0
- package/dist/admin/DiscountManager.d.ts +24 -0
- package/dist/admin/DiscountManager.d.ts.map +1 -0
- package/dist/admin/DiscountManager.js +77 -0
- package/dist/admin/DiscountManager.js.map +1 -0
- package/dist/admin/OrderDetail.d.ts +62 -0
- package/dist/admin/OrderDetail.d.ts.map +1 -0
- package/dist/admin/OrderDetail.js +62 -0
- package/dist/admin/OrderDetail.js.map +1 -0
- package/dist/admin/OrderList.d.ts +29 -0
- package/dist/admin/OrderList.d.ts.map +1 -0
- package/dist/admin/OrderList.js +30 -0
- package/dist/admin/OrderList.js.map +1 -0
- package/dist/admin/ProductEdit.d.ts +43 -0
- package/dist/admin/ProductEdit.d.ts.map +1 -0
- package/dist/admin/ProductEdit.js +68 -0
- package/dist/admin/ProductEdit.js.map +1 -0
- package/dist/admin/ProductList.d.ts +21 -0
- package/dist/admin/ProductList.d.ts.map +1 -0
- package/dist/admin/ProductList.js +39 -0
- package/dist/admin/ProductList.js.map +1 -0
- package/dist/client.d.ts +107 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +71 -0
- package/dist/client.js.map +1 -0
- package/dist/collections.d.ts +4 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +335 -0
- package/dist/collections.js.map +1 -0
- package/dist/fields.d.ts +4 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +3 -0
- package/dist/fields.js.map +1 -0
- package/dist/hooks.d.ts +3 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +33 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/stripe/checkout.d.ts +39 -0
- package/dist/stripe/checkout.d.ts.map +1 -0
- package/dist/stripe/checkout.js +60 -0
- package/dist/stripe/checkout.js.map +1 -0
- package/dist/stripe/customer.d.ts +11 -0
- package/dist/stripe/customer.d.ts.map +1 -0
- package/dist/stripe/customer.js +22 -0
- package/dist/stripe/customer.js.map +1 -0
- package/dist/stripe/products.d.ts +25 -0
- package/dist/stripe/products.d.ts.map +1 -0
- package/dist/stripe/products.js +29 -0
- package/dist/stripe/products.js.map +1 -0
- package/dist/stripe/webhooks.d.ts +28 -0
- package/dist/stripe/webhooks.d.ts.map +1 -0
- package/dist/stripe/webhooks.js +103 -0
- package/dist/stripe/webhooks.js.map +1 -0
- package/package.json +43 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# @actuate-media/plugin-commerce
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5eea995: Product rename: ActuateCMS is now **Prenta**. Every package moves from the
|
|
8
|
+
`@actuate-media/*` scope to `@prenta/*` with simplified names (`@prenta/core`,
|
|
9
|
+
`@prenta/admin`, `create-prenta`), and version numbers continue from where the
|
|
10
|
+
old scope left off.
|
|
11
|
+
|
|
12
|
+
This is a clean break — no backwards-compat aliases:
|
|
13
|
+
- **npm packages**: `@actuate-media/cms-core` → `@prenta/core`,
|
|
14
|
+
`@actuate-media/cms-admin` → `@prenta/admin`, all other packages keep their
|
|
15
|
+
suffix under `@prenta/*`. `create-actuate-cms` → `create-prenta`
|
|
16
|
+
(`npm create prenta`), `create-actuate-astro` → `create-prenta-astro`.
|
|
17
|
+
CLI bins: `actuate`/`actuate-cms` → `prenta`/`prenta-cms`; `actuate-mcp` →
|
|
18
|
+
`prenta-mcp`.
|
|
19
|
+
- **Database**: migration `0012_rename_to_prenta` renames all 36 `actuate_*`
|
|
20
|
+
tables to `prenta_*` in place (plus prefixed constraints, indexes, and
|
|
21
|
+
sequences). Run `prisma migrate deploy` when upgrading.
|
|
22
|
+
- **Runtime identifiers**: `getActuateConfig` → `getPrentaConfig`,
|
|
23
|
+
`handleActuateAPI` → `handlePrentaAPI`, `ActuateClient` → `PrentaClient`,
|
|
24
|
+
`ActuateDB` → `PrentaDB`, config file `actuate.config.ts` →
|
|
25
|
+
`prenta.config.ts`, CSS scopes `.actuate-admin`/`.actuate-canvas` →
|
|
26
|
+
`.prenta-admin`/`.prenta-canvas`, preview protocol `actuate-preview:*` →
|
|
27
|
+
`prenta-preview:*`, webhook headers `X-Actuate-*` → `X-Prenta-*`, session
|
|
28
|
+
cookie `actuate_session` → `prenta_session`, env vars `ACTUATE_*` →
|
|
29
|
+
`PRENTA_*`, purge route `/api/actuate/purge` → `/api/prenta/purge`.
|
|
30
|
+
- **Sessions and webhooks**: all sessions reset on upgrade (cookie + JWT issuer
|
|
31
|
+
changed); webhook consumers must re-verify signatures against the new
|
|
32
|
+
`X-Prenta-*` headers.
|
|
33
|
+
|
|
34
|
+
The old `@actuate-media/*` packages are deprecated on npm and will receive no
|
|
35
|
+
further releases.
|
|
36
|
+
|
|
37
|
+
## 0.1.3
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- daf91b4: Fix `syncProduct` letting caller metadata overwrite the authoritative `actuateProductId`.
|
|
42
|
+
|
|
43
|
+
The Stripe product metadata was built with `actuateProductId` assigned _before_
|
|
44
|
+
the `...product.metadata` spread, so a caller-supplied `metadata.actuateProductId`
|
|
45
|
+
won on key collision and silently corrupted the Actuate→Stripe foreign key. The
|
|
46
|
+
spread now comes first and the authoritative key is assigned last.
|
|
47
|
+
|
|
48
|
+
## 0.1.2
|
|
49
|
+
|
|
50
|
+
### Patch Changes
|
|
51
|
+
|
|
52
|
+
- e25cd48: Standardize React peer ranges to `^18.0.0 || ^19.0.0`.
|
|
53
|
+
|
|
54
|
+
Plugin React peer ranges were inconsistent: `plugin-ai`, `plugin-commerce`, and
|
|
55
|
+
`plugin-seo` pinned `react: ^19.2.0` (excluding React 18, which `cms-core`
|
|
56
|
+
supports via `react >=18.0.0`), while the others used `^18.0.0 || ^19.2.0`
|
|
57
|
+
(excluding React 19.0/19.1). Either produced an `ERESOLVE` install failure for
|
|
58
|
+
consumers on the excluded versions. All bundled plugins now declare `react`
|
|
59
|
+
(and `react-dom` where already peered) as `^18.0.0 || ^19.0.0`.
|
|
60
|
+
|
|
61
|
+
## 0.1.1
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- cd8a061: Remove dead sidebar nav from bundled plugins and guard the whole class.
|
|
66
|
+
|
|
67
|
+
`plugin-ai`, `plugin-commerce`, and `plugin-blocks` each advertised
|
|
68
|
+
`adminNavItems` paths (`/ai/*`, `/commerce/*`, `/blocks`) that the admin router
|
|
69
|
+
has no view for — plugins cannot register views, and these plugins register no
|
|
70
|
+
collection backing those paths — so every one of those sidebar links landed on
|
|
71
|
+
the 404 page. The commerce items were also duplicates of the working collection
|
|
72
|
+
nav (its collections already appear under the "Commerce" group at their real
|
|
73
|
+
`/<slug>` routes).
|
|
74
|
+
- Dropped the dead `adminNavItems` from all three plugins. Commerce collections
|
|
75
|
+
remain reachable at `/products`, `/orders`, `/discounts`, …; plugin-ai and
|
|
76
|
+
plugin-blocks are backend/page-builder plugins with no standalone admin route.
|
|
77
|
+
- Added `cms-admin`'s `router/admin-routes` resolver (`adminPathResolves`) plus
|
|
78
|
+
a table-driven test asserting **every** bundled plugin's nav paths resolve to a
|
|
79
|
+
real view, and a drift test that keeps the known-route list in sync with
|
|
80
|
+
`AdminRoot`. This is the systemic guard for a bug class that has now shipped in
|
|
81
|
+
published packages three times.
|
|
82
|
+
|
|
83
|
+
## 0.1.0
|
|
84
|
+
|
|
85
|
+
### Minor Changes
|
|
86
|
+
|
|
87
|
+
- d278add: Verify Stripe webhook signatures and lock in the checkout money-mapping.
|
|
88
|
+
|
|
89
|
+
The webhook handler previously "verified" a payload by only checking that the
|
|
90
|
+
signature and secret strings were non-empty before parsing it — so a forged POST
|
|
91
|
+
with any non-empty `Stripe-Signature` would be processed as a real event (a fake
|
|
92
|
+
`payment_intent.succeeded` is a direct fraud risk). `handleStripeWebhook` now
|
|
93
|
+
performs real HMAC-SHA256 verification via a new exported `verifyStripeSignature`
|
|
94
|
+
(a dependency-free equivalent of `stripe.webhooks.constructEvent`: signed-payload
|
|
95
|
+
HMAC, constant-time compare, multi-`v1` key rotation, and timestamp replay
|
|
96
|
+
tolerance).
|
|
97
|
+
|
|
98
|
+
The money-critical checkout mapping (dollar→integer-cents rounding for line items
|
|
99
|
+
and shipping, discounts, metadata) is extracted into a pure, exported
|
|
100
|
+
`buildCheckoutSessionParams` so it is unit-tested independently of the
|
|
101
|
+
(still-stubbed) Stripe API call. Adds 15 behavioral tests covering signature
|
|
102
|
+
accept/reject/replay/rotation, event routing, and cents/shipping/discount mapping.
|
|
103
|
+
|
|
104
|
+
## 0.0.14
|
|
105
|
+
|
|
106
|
+
### Patch Changes
|
|
107
|
+
|
|
108
|
+
- c231dd0: Add `definePlugin` and migrate all 10 plugins onto the canonical `PluginDefinition` contract.
|
|
109
|
+
|
|
110
|
+
cms-core already exported `PluginDefinition`, but every plugin hand-rolled a
|
|
111
|
+
local `ActuatePlugin` interface — a lossy subset that dropped `version`/`init`
|
|
112
|
+
and, in blocks/email/ai, widened hook payloads to `unknown[]`/`event: string`.
|
|
113
|
+
That's copy-paste drift with no shared source of truth.
|
|
114
|
+
|
|
115
|
+
`cms-core` now exports `definePlugin(plugin: PluginDefinition)` (an identity
|
|
116
|
+
helper like `defineConfig`), and each plugin imports the canonical type instead
|
|
117
|
+
of its own: the local `ActuatePlugin` interfaces are deleted, factory return
|
|
118
|
+
types are `PluginDefinition`, and the widened `hooks.ts` types are retyped as
|
|
119
|
+
`PluginHook[]`. Type-only change — no runtime behavior, plugin `name`, or config
|
|
120
|
+
options changed. Net −69 lines.
|
|
121
|
+
|
|
122
|
+
- 325694f: Import `definePlugin` from the lightweight `@actuate-media/cms-core/config`
|
|
123
|
+
entry instead of the barrel.
|
|
124
|
+
|
|
125
|
+
The plugin-definition migration imported the `definePlugin` **value** from
|
|
126
|
+
`@actuate-media/cms-core`, which pulls the entire cms-core barrel (graphql,
|
|
127
|
+
sharp, sentry, codegen) into every plugin's runtime — bundle bloat for
|
|
128
|
+
consumers and, under parallel test load, a timeout. The `/config` subpath exists
|
|
129
|
+
precisely to avoid the barrel. Types stay as erased `import type`, so nothing
|
|
130
|
+
heavy is loaded. No API or behavior change.
|
|
131
|
+
|
|
132
|
+
## 0.0.13
|
|
133
|
+
|
|
134
|
+
### Patch Changes
|
|
135
|
+
|
|
136
|
+
- 041a228: Add the MIT `license` field to every published package (previously missing) and correct `repository.url` to `github.com/actuate-media/actuatecms` (13 packages carried the wrong org).
|
|
137
|
+
- de419f2: Give plugin hooks a frozen, typed event contract. cms-core now exports
|
|
138
|
+
`PluginHook`, `PluginHookEvent`, and `PluginHookPayload` (document + upload
|
|
139
|
+
variants) as the single source of truth, and dispatches a complete, consistent
|
|
140
|
+
set of events: `afterCreate` / `afterUpdate` / `afterDelete` — each also in a
|
|
141
|
+
collection-namespaced form (`afterUpdate:navigations`, `afterCreate:orders`) —
|
|
142
|
+
plus `afterUpload` (fired post-upload from the media route). Every handler now
|
|
143
|
+
receives one typed payload; document field values live on `payload.data`.
|
|
144
|
+
|
|
145
|
+
Previously core fired only bare `afterCreate`/`afterUpdate` with the raw row, so
|
|
146
|
+
several shipped plugins' hooks were dead: `plugin-media`'s `afterUpload` never
|
|
147
|
+
fired, `plugin-navigation` read fields that didn't exist, and the namespaced
|
|
148
|
+
events `plugin-forms`/`plugin-commerce` declared were never dispatched. Each
|
|
149
|
+
plugin has been aligned to the shared type and dispatched events (and
|
|
150
|
+
`plugin-redirects`' request-time `onRedirectMatch` hook — which the lifecycle
|
|
151
|
+
bus never dispatched — was removed). Undispatched event names are now a
|
|
152
|
+
compile-time error.
|
|
153
|
+
|
|
154
|
+
## 0.0.12
|
|
155
|
+
|
|
156
|
+
### Patch Changes
|
|
157
|
+
|
|
158
|
+
- 854152d: Developer experience improvements from external-consumer feedback:
|
|
159
|
+
- Every published package now ships its `CHANGELOG.md` in the npm tarball, and packages that were missing a `README.md` (cli, cms-admin, cms-core, import, platform-vercel, all plugins, sections-react) now have one — so release notes and usage docs are visible on npmjs.com and in `node_modules`.
|
|
160
|
+
- New client-safe form validation entry point: `@actuate-media/cms-core/forms/client` exports `validateFormFieldClient()`, `validateFormValuesClient()`, visibility/conditional helpers, and the exact `FORM_EMAIL_RE` / `FORM_PHONE_RE` regexes the server enforces — zero Node dependencies, so public-site forms can mirror server rules without reimplementing them. The server validator now imports the same primitives, so client and server can never drift.
|
|
161
|
+
|
|
162
|
+
## 0.0.11
|
|
163
|
+
|
|
164
|
+
### Patch Changes
|
|
165
|
+
|
|
166
|
+
- b5de8dd: Fix ESM module resolution and dependency duplication issues reported during consumer integration.
|
|
167
|
+
- Add "default" export condition to all platform and plugin packages so they resolve correctly from require() contexts (fixes ERR_PACKAGE_PATH_NOT_EXPORTED in next.config.ts and serverless functions).
|
|
168
|
+
- Move @actuate-media/cms-core from direct dependencies to peerDependencies across all packages to prevent duplicate installations when consumer version ranges don't exactly match the pinned version.
|
|
169
|
+
- Add "prepack" lifecycle script to create-actuate-cms to guarantee dist/ is built before npm publishes the package (fixes empty dist/ in v0.4.0).
|
|
170
|
+
|
|
171
|
+
## 0.0.10
|
|
172
|
+
|
|
173
|
+
### Patch Changes
|
|
174
|
+
|
|
175
|
+
- Updated dependencies [54c7a3b]
|
|
176
|
+
- @actuate-media/cms-core@0.6.0
|
|
177
|
+
|
|
178
|
+
## 0.0.9
|
|
179
|
+
|
|
180
|
+
### Patch Changes
|
|
181
|
+
|
|
182
|
+
- Updated dependencies [c08cf8b]
|
|
183
|
+
- Updated dependencies [80aa939]
|
|
184
|
+
- @actuate-media/cms-core@0.5.0
|
|
185
|
+
|
|
186
|
+
## 0.0.8
|
|
187
|
+
|
|
188
|
+
### Patch Changes
|
|
189
|
+
|
|
190
|
+
- Updated dependencies [f2cf7d7]
|
|
191
|
+
- @actuate-media/cms-core@0.4.0
|
|
192
|
+
|
|
193
|
+
## 0.0.7
|
|
194
|
+
|
|
195
|
+
### Patch Changes
|
|
196
|
+
|
|
197
|
+
- Updated dependencies [0621037]
|
|
198
|
+
- @actuate-media/cms-core@0.3.1
|
|
199
|
+
|
|
200
|
+
## 0.0.6
|
|
201
|
+
|
|
202
|
+
### Patch Changes
|
|
203
|
+
|
|
204
|
+
- Updated dependencies [4e3a5eb]
|
|
205
|
+
- @actuate-media/cms-core@0.3.0
|
|
206
|
+
|
|
207
|
+
## 0.0.5
|
|
208
|
+
|
|
209
|
+
### Patch Changes
|
|
210
|
+
|
|
211
|
+
- Updated dependencies
|
|
212
|
+
- @actuate-media/cms-core@0.2.3
|
|
213
|
+
|
|
214
|
+
## 0.0.4
|
|
215
|
+
|
|
216
|
+
### Patch Changes
|
|
217
|
+
|
|
218
|
+
- Updated dependencies
|
|
219
|
+
- @actuate-media/cms-core@0.2.2
|
|
220
|
+
|
|
221
|
+
## 0.0.3
|
|
222
|
+
|
|
223
|
+
### Patch Changes
|
|
224
|
+
|
|
225
|
+
- Updated dependencies
|
|
226
|
+
- @actuate-media/cms-core@0.2.1
|
|
227
|
+
|
|
228
|
+
## 0.0.2
|
|
229
|
+
|
|
230
|
+
### Patch Changes
|
|
231
|
+
|
|
232
|
+
- 3fd38a2: Fix all 13 integration issues discovered during MaidPro.co deployment
|
|
233
|
+
|
|
234
|
+
**cms-core:**
|
|
235
|
+
- Add .js extensions to all ESM relative imports (58 files)
|
|
236
|
+
- Replace workspace:\* with versioned deps in all packages
|
|
237
|
+
- Add sideEffects:false for proper tree-shaking
|
|
238
|
+
- Subpath exports (/config, /api, /middleware, /next) avoid barrel side effects
|
|
239
|
+
- Stats/search routes use safeCount/safeFindMany for missing Prisma models
|
|
240
|
+
- Ship prisma/cms-schema.prisma with all required CMS models
|
|
241
|
+
- Accept both CMS_SECRET and CMS_SESSION_SECRET with clear error messages
|
|
242
|
+
- Fix hardcoded /admin paths in OAuth flow (now uses getAdminPath())
|
|
243
|
+
- Loosen withActuateCMS and createCMSMiddleware parameter types
|
|
244
|
+
- Auto-inject transpilePackages and serverExternalPackages in withActuateCMS
|
|
245
|
+
- Unify PluginDefinition with ActuatePlugin interface
|
|
246
|
+
|
|
247
|
+
**cms-admin:**
|
|
248
|
+
- Scope all 40+ CSS theme variables to .actuate-admin instead of :root
|
|
249
|
+
- ThemeProvider applies dark class to .actuate-admin, not document.documentElement
|
|
250
|
+
- Scaffold uses (admin)/(site) route groups for full CSS/script isolation
|
|
251
|
+
- Sidebar branding supports custom logo via config.admin.branding
|
|
252
|
+
|
|
253
|
+
**platform-vercel:**
|
|
254
|
+
- Email adapter accepts both `from` and `defaultFrom`
|
|
255
|
+
|
|
256
|
+
**All plugin/platform packages:**
|
|
257
|
+
- Fix ESM .js extensions in compiled output
|
|
258
|
+
- Replace workspace:\* with ^0.1.0 for publishable deps
|
|
259
|
+
|
|
260
|
+
- Updated dependencies [682dac7]
|
|
261
|
+
- Updated dependencies [3fd38a2]
|
|
262
|
+
- @actuate-media/cms-core@0.2.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Actuate Media
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @prenta/plugin-commerce
|
|
2
|
+
|
|
3
|
+
Commerce collections for [Prenta CMS](https://github.com/actuate-media/prenta)
|
|
4
|
+
— products, categories, and pricing fields.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm install @prenta/plugin-commerce
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { commercePlugin } from '@prenta/plugin-commerce'
|
|
14
|
+
|
|
15
|
+
export default defineConfig({
|
|
16
|
+
plugins: [commercePlugin()],
|
|
17
|
+
// ...
|
|
18
|
+
})
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Release notes
|
|
22
|
+
|
|
23
|
+
See [CHANGELOG.md](./CHANGELOG.md) (shipped with the package) or the
|
|
24
|
+
[GitHub releases](https://github.com/actuate-media/prenta/releases).
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/checkout.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { buildCheckoutSessionParams, createCheckoutSession } from '../stripe/checkout.js';
|
|
3
|
+
const base = { successUrl: '/success', cancelUrl: '/cancel' };
|
|
4
|
+
const lineItem = (over = {}) => ({
|
|
5
|
+
productId: 'p1',
|
|
6
|
+
name: 'Widget',
|
|
7
|
+
quantity: 1,
|
|
8
|
+
unitPrice: 5,
|
|
9
|
+
...over,
|
|
10
|
+
});
|
|
11
|
+
describe('buildCheckoutSessionParams', () => {
|
|
12
|
+
it('converts dollar unit prices to integer cents (float-safe)', () => {
|
|
13
|
+
const params = buildCheckoutSessionParams({
|
|
14
|
+
...base,
|
|
15
|
+
lineItems: [lineItem({ unitPrice: 19.99, quantity: 2 })],
|
|
16
|
+
});
|
|
17
|
+
const li = params.line_items[0];
|
|
18
|
+
expect(li.price_data.unit_amount).toBe(1999); // 19.99*100 = 1998.999… → round
|
|
19
|
+
expect(li.quantity).toBe(2);
|
|
20
|
+
expect(params.mode).toBe('payment');
|
|
21
|
+
expect(params.success_url).toBe('/success');
|
|
22
|
+
});
|
|
23
|
+
it('rounds a value that floats below the integer (10.1 → 1010c)', () => {
|
|
24
|
+
const params = buildCheckoutSessionParams({
|
|
25
|
+
...base,
|
|
26
|
+
lineItems: [lineItem({ unitPrice: 10.1 })],
|
|
27
|
+
});
|
|
28
|
+
expect(params.line_items[0].price_data.unit_amount).toBe(1010);
|
|
29
|
+
});
|
|
30
|
+
it('includes variant metadata + image only when present', () => {
|
|
31
|
+
const withVariant = buildCheckoutSessionParams({
|
|
32
|
+
...base,
|
|
33
|
+
lineItems: [lineItem({ variantId: 'v1', image: 'https://img/x.png' })],
|
|
34
|
+
});
|
|
35
|
+
const pd = withVariant.line_items[0].price_data.product_data;
|
|
36
|
+
expect(pd.metadata).toEqual({ productId: 'p1', variantId: 'v1' });
|
|
37
|
+
expect(pd.images).toEqual(['https://img/x.png']);
|
|
38
|
+
const bare = buildCheckoutSessionParams({ ...base, lineItems: [lineItem()] });
|
|
39
|
+
const pd2 = bare.line_items[0].price_data.product_data;
|
|
40
|
+
expect(pd2.metadata).toEqual({ productId: 'p1' });
|
|
41
|
+
expect(pd2.images).toEqual([]);
|
|
42
|
+
});
|
|
43
|
+
it('maps shipping options to fixed_amount cents', () => {
|
|
44
|
+
const params = buildCheckoutSessionParams({
|
|
45
|
+
...base,
|
|
46
|
+
lineItems: [lineItem()],
|
|
47
|
+
shippingOptions: [{ id: 's1', label: 'Express', amount: 12.5 }],
|
|
48
|
+
});
|
|
49
|
+
const so = params.shipping_options[0];
|
|
50
|
+
expect(so.shipping_rate_data.fixed_amount).toEqual({ amount: 1250, currency: 'usd' });
|
|
51
|
+
expect(so.shipping_rate_data.display_name).toBe('Express');
|
|
52
|
+
});
|
|
53
|
+
it('adds discounts + customer_email only when provided', () => {
|
|
54
|
+
const full = buildCheckoutSessionParams({
|
|
55
|
+
...base,
|
|
56
|
+
lineItems: [lineItem()],
|
|
57
|
+
discountCode: 'SAVE10',
|
|
58
|
+
customerEmail: 'a@b.com',
|
|
59
|
+
});
|
|
60
|
+
expect(full.discounts).toEqual([{ coupon: 'SAVE10' }]);
|
|
61
|
+
expect(full.customer_email).toBe('a@b.com');
|
|
62
|
+
const bare = buildCheckoutSessionParams({ ...base, lineItems: [lineItem()] });
|
|
63
|
+
expect(bare.discounts).toBeUndefined();
|
|
64
|
+
expect(bare.customer_email).toBeUndefined();
|
|
65
|
+
expect(bare.shipping_options).toBeUndefined();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('createCheckoutSession (stub wrapper)', () => {
|
|
69
|
+
afterEach(() => {
|
|
70
|
+
vi.useRealTimers();
|
|
71
|
+
});
|
|
72
|
+
it('returns a stub session that expires ~30 minutes from now', async () => {
|
|
73
|
+
vi.useFakeTimers();
|
|
74
|
+
vi.setSystemTime(new Date('2026-07-09T00:00:00.000Z'));
|
|
75
|
+
const session = await createCheckoutSession({ ...base, lineItems: [lineItem()] });
|
|
76
|
+
const diff = session.expiresAt.getTime() - Date.now();
|
|
77
|
+
expect(diff).toBeGreaterThanOrEqual(29 * 60 * 1000);
|
|
78
|
+
expect(diff).toBeLessThanOrEqual(30 * 60 * 1000);
|
|
79
|
+
expect(session.id).toMatch(/^cs_stub_/);
|
|
80
|
+
expect(session.url).toMatch(/^https:\/\/checkout\.stripe\.com\/pay\/cs_stub_/);
|
|
81
|
+
});
|
|
82
|
+
});
|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3,"file":"client.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/client.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
+
import { createCommerceClient } from '../client.js';
|
|
3
|
+
const originalFetch = globalThis.fetch;
|
|
4
|
+
/** Replaces the global fetch with a spy that resolves a controllable Response-like object. */
|
|
5
|
+
function stubFetch(overrides = {}) {
|
|
6
|
+
const fn = vi.fn(async (_input, _init) => ({
|
|
7
|
+
ok: true,
|
|
8
|
+
status: 200,
|
|
9
|
+
statusText: 'OK',
|
|
10
|
+
json: async () => ({}),
|
|
11
|
+
...overrides,
|
|
12
|
+
}));
|
|
13
|
+
globalThis.fetch = fn;
|
|
14
|
+
return fn;
|
|
15
|
+
}
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
globalThis.fetch = originalFetch;
|
|
18
|
+
vi.restoreAllMocks();
|
|
19
|
+
});
|
|
20
|
+
describe('createCommerceClient request/URL construction', () => {
|
|
21
|
+
it('normalizes a trailing slash and drops undefined query params (URL-encoded)', async () => {
|
|
22
|
+
const fetchMock = stubFetch({ json: async () => ({ data: [], total: 0 }) });
|
|
23
|
+
await createCommerceClient('http://x/').products.find({
|
|
24
|
+
status: 'active',
|
|
25
|
+
minPrice: undefined,
|
|
26
|
+
search: 'a b',
|
|
27
|
+
});
|
|
28
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
29
|
+
// No double slash after 'http://x', minPrice dropped, space encoded to %20.
|
|
30
|
+
expect(fetchMock.mock.calls[0][0]).toBe('http://x/api/commerce/products?status=active&search=a%20b');
|
|
31
|
+
});
|
|
32
|
+
it('emits no query string when there are no filters', async () => {
|
|
33
|
+
const fetchMock = stubFetch({ json: async () => ({ data: [], total: 0 }) });
|
|
34
|
+
await createCommerceClient('http://x/').products.find();
|
|
35
|
+
expect(fetchMock.mock.calls[0][0]).toBe('http://x/api/commerce/products');
|
|
36
|
+
});
|
|
37
|
+
it('URL-encodes a path segment containing a slash (sessionId)', async () => {
|
|
38
|
+
const fetchMock = stubFetch();
|
|
39
|
+
await createCommerceClient('http://x').cart.get('sess/1');
|
|
40
|
+
expect(fetchMock.mock.calls[0][0]).toBe('http://x/api/commerce/cart/sess%2F1');
|
|
41
|
+
});
|
|
42
|
+
it('POSTs addItem with the correct method and JSON body', async () => {
|
|
43
|
+
const fetchMock = stubFetch();
|
|
44
|
+
await createCommerceClient('http://x').cart.addItem('s', 'p', 2, 'v');
|
|
45
|
+
const [url, init] = fetchMock.mock.calls[0];
|
|
46
|
+
expect(url).toBe('http://x/api/commerce/cart/s/items');
|
|
47
|
+
expect(init.method).toBe('POST');
|
|
48
|
+
expect(JSON.parse(init.body)).toEqual({
|
|
49
|
+
productId: 'p',
|
|
50
|
+
quantity: 2,
|
|
51
|
+
variantId: 'v',
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
it('POSTs checkout with sessionId spread alongside the options', async () => {
|
|
55
|
+
const fetchMock = stubFetch();
|
|
56
|
+
await createCommerceClient('http://x').checkout.create('s', {
|
|
57
|
+
email: 'a@b.com',
|
|
58
|
+
shippingAddress: { line1: '1 St' },
|
|
59
|
+
});
|
|
60
|
+
const [url, init] = fetchMock.mock.calls[0];
|
|
61
|
+
expect(url).toBe('http://x/api/commerce/checkout');
|
|
62
|
+
expect(init.method).toBe('POST');
|
|
63
|
+
expect(JSON.parse(init.body)).toEqual({
|
|
64
|
+
sessionId: 's',
|
|
65
|
+
email: 'a@b.com',
|
|
66
|
+
shippingAddress: { line1: '1 St' },
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
it('throws "Commerce API error: <status> <statusText>" on a non-ok response', async () => {
|
|
70
|
+
stubFetch({ ok: false, status: 404, statusText: 'Not Found' });
|
|
71
|
+
await expect(createCommerceClient('http://x').orders.findById('o1')).rejects.toThrow(/Commerce API error: 404 Not Found/);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
//# s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AAC,CAAC,CAAA;IAEF,EAAE,CAAC,yEAAyE,EAAE,KAAK,IAAI,EAAE;QACvF,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAA;QAC9D,MAAM,MAAM,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAClF,mCAAmC,CACpC,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/customer.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { getOrCreateCustomer, syncCustomer } from '../stripe/customer.js';
|
|
3
|
+
describe('getOrCreateCustomer', () => {
|
|
4
|
+
it('passes the email through and starts with empty metadata', async () => {
|
|
5
|
+
const customer = await getOrCreateCustomer('a@b.com');
|
|
6
|
+
expect(customer.email).toBe('a@b.com');
|
|
7
|
+
expect(customer.metadata).toEqual({});
|
|
8
|
+
expect(customer.id).toMatch(/^cus_stub_/);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
describe('syncCustomer', () => {
|
|
12
|
+
it('injects prentaUserId while preserving the resolved customer email and metadata', async () => {
|
|
13
|
+
const customer = await syncCustomer('user_7', 'a@b.com');
|
|
14
|
+
// Delegates to getOrCreateCustomer (email passthrough, cus_stub_ id) and then
|
|
15
|
+
// spreads its metadata ({}), adding only prentaUserId — nothing dropped/added.
|
|
16
|
+
expect(customer.email).toBe('a@b.com');
|
|
17
|
+
expect(customer.metadata).toEqual({ prentaUserId: 'user_7' });
|
|
18
|
+
expect(customer.id).toMatch(/^cus_stub_/);
|
|
19
|
+
});
|
|
20
|
+
});
|
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