qarpeo 0.4.13 → 0.4.15
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 +197 -191
- package/dist/apps/cms.d.ts +1 -1
- package/dist/apps/comments.d.ts +1 -1
- package/dist/apps/payments.d.ts +1 -1
- package/dist/apps/store.d.ts +1 -1
- package/dist/chunks/{manifest.get.mjs → tools.mjs} +445 -430
- package/dist/cli/index.mjs +756 -746
- package/dist/core/aliases.d.ts +1 -1
- package/dist/core/context.d.ts +1 -1
- package/dist/core/d1-migrate.d.ts +1 -1
- package/dist/core/devtools.d.ts +1 -1
- package/dist/core/nitro.d.ts +1 -1
- package/dist/core/schema.d.ts +1 -1
- package/dist/core/server-utils.d.ts +1 -1
- package/dist/core/wrangler.d.ts +1 -1
- package/dist/fate/index.d.ts +8 -8
- package/dist/fate/index.mjs +3 -1
- package/dist/features/agents.d.ts +1 -1
- package/dist/features/auth.d.ts +1 -1
- package/dist/features/bots.d.ts +1 -1
- package/dist/features/console.d.ts +1 -1
- package/dist/features/fate.d.ts +1 -1
- package/dist/features/mail.d.ts +1 -1
- package/dist/features/mcp.d.ts +1 -1
- package/dist/features/multitenant.d.ts +1 -1
- package/dist/features/notifications.d.ts +1 -1
- package/dist/features/realtime.d.ts +1 -1
- package/dist/features/studio.d.ts +4 -0
- package/dist/module.d.ts +1 -1
- package/dist/module.mjs +5451 -5249
- package/dist/primitives/ai.d.ts +1 -1
- package/dist/primitives/analytics.d.ts +1 -1
- package/dist/primitives/blob.d.ts +1 -1
- package/dist/primitives/browser.d.ts +1 -1
- package/dist/primitives/cache.d.ts +1 -1
- package/dist/primitives/d1.d.ts +1 -1
- package/dist/primitives/do.d.ts +1 -1
- package/dist/primitives/email.d.ts +1 -1
- package/dist/primitives/hyperdrive.d.ts +1 -1
- package/dist/primitives/kv.d.ts +1 -1
- package/dist/primitives/queue.d.ts +1 -1
- package/dist/primitives/ratelimit.d.ts +1 -1
- package/dist/primitives/vectorize.d.ts +1 -1
- package/dist/primitives/workflows.d.ts +1 -1
- package/dist/runtime/ai.mjs +4 -1
- package/dist/runtime/app/components/CMSEditor.vue +439 -0
- package/dist/runtime/app/components/CMSEditorImageNode.vue +90 -0
- package/dist/runtime/app/components/CMSEditorLinkPopover.vue +120 -0
- package/dist/runtime/app/components/QDropZone.vue +327 -0
- package/dist/runtime/app/components/QImageCropper.vue +658 -0
- package/dist/runtime/app/components/QImageStudio.vue +300 -0
- package/dist/runtime/app/components/QImg.vue +7 -4
- package/dist/runtime/app/composables/analytics.d.ts +8 -8
- package/dist/runtime/app/composables/api-tokens.d.ts +5 -5
- package/dist/runtime/app/composables/auth.d.ts +23 -19
- package/dist/runtime/app/composables/chat.d.ts +7 -6
- package/dist/runtime/app/composables/cms-preview.d.ts +7 -8
- package/dist/runtime/app/composables/cms.d.ts +6 -6
- package/dist/runtime/app/composables/comments.d.ts +5 -5
- package/dist/runtime/app/composables/comments.mjs +7 -4
- package/dist/runtime/app/composables/console.d.ts +6 -14
- package/dist/runtime/app/composables/docs-version.d.ts +8 -8
- package/dist/runtime/app/composables/impersonation.d.ts +5 -5
- package/dist/runtime/app/composables/organization.d.ts +5 -5
- package/dist/runtime/app/composables/passkey.d.ts +5 -5
- package/dist/runtime/app/composables/passwordless.d.ts +5 -5
- package/dist/runtime/app/composables/payments.d.ts +5 -5
- package/dist/runtime/app/composables/rbac.d.ts +5 -5
- package/dist/runtime/app/composables/site.d.ts +2 -2
- package/dist/runtime/app/composables/sse.d.ts +20 -33
- package/dist/runtime/app/composables/sse.mjs +6 -3
- package/dist/runtime/app/composables/storage.d.ts +6 -8
- package/dist/runtime/app/composables/store.d.ts +52 -36
- package/dist/runtime/app/composables/store.mjs +70 -11
- package/dist/runtime/app/composables/studio.d.ts +59 -0
- package/dist/runtime/app/composables/studio.mjs +129 -0
- package/dist/runtime/app/composables/tenant.d.ts +7 -7
- package/dist/runtime/app/composables/turnstile.d.ts +5 -5
- package/dist/runtime/app/composables/two-factor.d.ts +5 -5
- package/dist/runtime/app/pages/devtools/notifications.vue +1 -6
- package/dist/runtime/app/plugins/pwa.mjs +1 -3
- package/dist/runtime/app/utils/cms-editor.d.ts +25 -0
- package/dist/runtime/app/utils/cms-editor.mjs +43 -0
- package/dist/runtime/auth.d.ts +9 -9
- package/dist/runtime/blob.d.ts +1 -3
- package/dist/runtime/blob.mjs +3 -1
- package/dist/runtime/cache.d.ts +8 -6
- package/dist/runtime/cache.mjs +8 -11
- package/dist/runtime/db.d.ts +4 -3
- package/dist/runtime/drizzle.d.ts +2 -1
- package/dist/runtime/drizzle.mjs +2 -2
- package/dist/runtime/queue.d.ts +1 -0
- package/dist/runtime/replica.d.ts +6 -10
- package/dist/runtime/replica.mjs +3 -1
- package/dist/runtime/schema-mysql.d.ts +16 -32
- package/dist/runtime/schema-pg.d.ts +15 -31
- package/dist/runtime/schema-shared.d.ts +20 -17
- package/dist/runtime/schema.d.ts +21 -33
- package/dist/runtime/server/durable-objects/agent.mjs +4 -1
- package/dist/runtime/server/durable-objects/room.d.ts +4 -6
- package/dist/runtime/server/durable-objects/room.mjs +18 -8
- package/dist/runtime/server/plugins/comments.d.ts +2 -3
- package/dist/runtime/server/plugins/email-inbound.d.ts +1 -3
- package/dist/runtime/server/plugins/store.d.ts +2 -3
- package/dist/runtime/server/routes/__qarpeo/cloud/agents/run.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.get.mjs +10 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.mjs +10 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.mjs +7 -1
- package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.mjs +5 -1
- package/dist/runtime/server/routes/__qarpeo/cloud/comments.get.d.ts +1 -3
- package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.mjs +15 -4
- package/dist/runtime/server/routes/__qarpeo/cloud/mail/unsuppress.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/cms.post.mjs +13 -4
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/products.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.d.ts +3 -3
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.mjs +22 -6
- package/dist/runtime/server/routes/__qarpeo/cloud/notifications/test.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/operations.get.d.ts +6 -5
- package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.d.ts +1 -3
- package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.mjs +14 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.d.ts +1 -3
- package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.mjs +7 -1
- package/dist/runtime/server/routes/__qarpeo/cloud/store/products.get.d.ts +1 -3
- package/dist/runtime/server/routes/__qarpeo/cloud/tasks/run.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.mjs +5 -1
- package/dist/runtime/server/routes/__qarpeo/cloud/users.get.d.ts +6 -5
- package/dist/runtime/server/routes/__qarpeo/cloud/users.get.mjs +1 -3
- package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +2 -2
- package/dist/runtime/server/routes/__qarpeo/manifest.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/og.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/rbac/me.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.mjs +5 -1
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.mjs +1 -5
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.mjs +5 -1
- package/dist/runtime/server/routes/__qarpeo/rbac/users.post.d.ts +2 -2
- package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +1 -6
- package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +1 -6
- package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +1 -6
- package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +5 -1
- package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +7 -1
- package/dist/runtime/server/routes/auth/magic-link/send.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/otp/send.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/search.get.mjs +2 -6
- package/dist/runtime/server/routes/comments/[id]/report.post.mjs +1 -4
- package/dist/runtime/server/routes/comments/[id].patch.mjs +1 -4
- package/dist/runtime/server/routes/comments/batch.post.mjs +1 -3
- package/dist/runtime/server/routes/comments/index.post.mjs +1 -5
- package/dist/runtime/server/routes/fate.mjs +1 -1
- package/dist/runtime/server/routes/mail/webhooks.post.mjs +1 -1
- package/dist/runtime/server/routes/sitemap.xml.get.mjs +2 -1
- package/dist/runtime/server/routes/storage/presigned-r2.post.d.ts +5 -6
- package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +1 -1
- package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +1 -1
- package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +1 -1
- package/dist/runtime/server/routes/store/currencies.get.mjs +1 -4
- package/dist/runtime/server/routes/store/orders/[id].get.mjs +1 -1
- package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +13 -4
- package/dist/runtime/server/routes/store/orders/index.get.mjs +1 -1
- package/dist/runtime/server/routes/store/products/index.get.mjs +2 -0
- package/dist/runtime/server/routes/store/tax/calculate.post.d.ts +2 -1
- package/dist/runtime/server/routes/store/tax/calculate.post.mjs +12 -3
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +4 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +4 -1
- package/dist/runtime/server/utils/ai.d.ts +38 -35
- package/dist/runtime/server/utils/ai.mjs +7 -11
- package/dist/runtime/server/utils/analytics-query.d.ts +4 -4
- package/dist/runtime/server/utils/auth.d.ts +25 -25
- package/dist/runtime/server/utils/auth.mjs +22 -8
- package/dist/runtime/server/utils/bots.d.ts +7 -7
- package/dist/runtime/server/utils/browser-utils.d.ts +26 -27
- package/dist/runtime/server/utils/cache.d.ts +20 -20
- package/dist/runtime/server/utils/cms/collections.mjs +1 -6
- package/dist/runtime/server/utils/cms/common.mjs +1 -0
- package/dist/runtime/server/utils/cms/markdown.d.ts +2 -2
- package/dist/runtime/server/utils/cms/markdown.mjs +5 -5
- package/dist/runtime/server/utils/cms/mutations.mjs +8 -23
- package/dist/runtime/server/utils/cms/navigation.mjs +4 -4
- package/dist/runtime/server/utils/cms/path.d.ts +1 -0
- package/dist/runtime/server/utils/cms/path.mjs +8 -2
- package/dist/runtime/server/utils/cms/references.mjs +1 -7
- package/dist/runtime/server/utils/cms/search.d.ts +2 -2
- package/dist/runtime/server/utils/cms/sync.mjs +4 -2
- package/dist/runtime/server/utils/cms/taxonomy.d.ts +2 -2
- package/dist/runtime/server/utils/cms.d.ts +1 -1
- package/dist/runtime/server/utils/cms.mjs +1 -5
- package/dist/runtime/server/utils/comments-filter.d.ts +9 -7
- package/dist/runtime/server/utils/comments.d.ts +68 -55
- package/dist/runtime/server/utils/comments.mjs +21 -9
- package/dist/runtime/server/utils/config.d.ts +2 -2
- package/dist/runtime/server/utils/console.d.ts +3 -5
- package/dist/runtime/server/utils/context.d.ts +10 -10
- package/dist/runtime/server/utils/crypto.d.ts +20 -20
- package/dist/runtime/server/utils/domains.mjs +3 -1
- package/dist/runtime/server/utils/drizzle.d.ts +24 -25
- package/dist/runtime/server/utils/drizzle.mjs +17 -17
- package/dist/runtime/server/utils/durable-object.d.ts +27 -25
- package/dist/runtime/server/utils/durable-object.mjs +3 -10
- package/dist/runtime/server/utils/email-inbound.d.ts +10 -10
- package/dist/runtime/server/utils/impersonation.d.ts +18 -18
- package/dist/runtime/server/utils/legacy-hash.d.ts +23 -27
- package/dist/runtime/server/utils/lock.d.ts +20 -23
- package/dist/runtime/server/utils/mail.d.ts +19 -19
- package/dist/runtime/server/utils/mail.mjs +4 -2
- package/dist/runtime/server/utils/mcp.d.ts +20 -20
- package/dist/runtime/server/utils/mcp.mjs +22 -38
- package/dist/runtime/server/utils/notifications.d.ts +49 -38
- package/dist/runtime/server/utils/oauth.d.ts +3 -9
- package/dist/runtime/server/utils/organization.d.ts +28 -28
- package/dist/runtime/server/utils/organization.mjs +15 -5
- package/dist/runtime/server/utils/passwordless.d.ts +24 -24
- package/dist/runtime/server/utils/payments/checkout.d.ts +12 -12
- package/dist/runtime/server/utils/payments/checkout.mjs +1 -3
- package/dist/runtime/server/utils/payments/common.d.ts +3 -3
- package/dist/runtime/server/utils/payments/paddle.d.ts +4 -1
- package/dist/runtime/server/utils/payments/polar.d.ts +4 -1
- package/dist/runtime/server/utils/payments/stripe.mjs +5 -7
- package/dist/runtime/server/utils/payments/subscriptions.d.ts +14 -14
- package/dist/runtime/server/utils/payments/subscriptions.mjs +2 -6
- package/dist/runtime/server/utils/payments/usage.mjs +1 -3
- package/dist/runtime/server/utils/payments/webhooks.mjs +2 -2
- package/dist/runtime/server/utils/queue.d.ts +54 -58
- package/dist/runtime/server/utils/queue.mjs +2 -6
- package/dist/runtime/server/utils/rag.d.ts +23 -23
- package/dist/runtime/server/utils/rag.mjs +10 -5
- package/dist/runtime/server/utils/ratelimit.d.ts +21 -18
- package/dist/runtime/server/utils/rbac.d.ts +13 -15
- package/dist/runtime/server/utils/rbac.mjs +44 -10
- package/dist/runtime/server/utils/realtime.d.ts +53 -52
- package/dist/runtime/server/utils/role-env.d.ts +5 -4
- package/dist/runtime/server/utils/scheduled-task.d.ts +14 -15
- package/dist/runtime/server/utils/session.d.ts +40 -40
- package/dist/runtime/server/utils/sse.d.ts +23 -33
- package/dist/runtime/server/utils/sse.mjs +5 -14
- package/dist/runtime/server/utils/sso.mjs +3 -1
- package/dist/runtime/server/utils/storage.d.ts +20 -22
- package/dist/runtime/server/utils/storage.mjs +2 -2
- package/dist/runtime/server/utils/store/cart.d.ts +5 -3
- package/dist/runtime/server/utils/store/cart.mjs +14 -10
- package/dist/runtime/server/utils/store/checkout.mjs +4 -1
- package/dist/runtime/server/utils/store/common.d.ts +1 -1
- package/dist/runtime/server/utils/store/common.mjs +36 -12
- package/dist/runtime/server/utils/store/inventory.mjs +3 -1
- package/dist/runtime/server/utils/store/orders.mjs +32 -24
- package/dist/runtime/server/utils/store/vendor.d.ts +11 -1
- package/dist/runtime/server/utils/store/vendor.mjs +47 -0
- package/dist/runtime/server/utils/store-localization.d.ts +9 -27
- package/dist/runtime/server/utils/store-localization.mjs +3 -3
- package/dist/runtime/server/utils/table-names.d.ts +15 -15
- package/dist/runtime/server/utils/table-names.mjs +1 -1
- package/dist/runtime/server/utils/tenant.d.ts +12 -12
- package/dist/runtime/server/utils/tenant.mjs +7 -4
- package/dist/runtime/server/utils/totp.d.ts +18 -18
- package/dist/runtime/server/utils/tracker.d.ts +5 -5
- package/dist/runtime/server/utils/turnstile.d.ts +9 -9
- package/dist/runtime/server/utils/urn.d.ts +5 -8
- package/dist/runtime/server/utils/workflows.d.ts +30 -31
- package/dist/runtime/server/utils/workflows.mjs +2 -4
- package/dist/runtime/server.d.ts +2 -2
- package/dist/runtime/service.d.ts +10 -10
- package/dist/runtime/test-utils.d.ts +10 -10
- package/dist/runtime/test-utils.mjs +9 -2
- package/dist/runtime/types/ai.d.ts +14 -14
- package/dist/runtime/types/d1.d.ts +6 -11
- package/dist/runtime/types/durable-object.d.ts +4 -8
- package/dist/runtime/types/email.d.ts +3 -9
- package/dist/runtime/types/index.d.ts +15 -21
- package/dist/runtime/types/r2.d.ts +5 -5
- package/dist/runtime/types/store.d.ts +7 -0
- package/dist/runtime/types/workflows.d.ts +5 -6
- package/dist/runtime/workflows.d.ts +1 -3
- package/dist/types/ai.d.ts +10 -17
- package/dist/types/auth.d.ts +5 -3
- package/dist/types/cache.d.ts +7 -7
- package/dist/types/cms.d.ts +30 -5
- package/dist/types/comments.d.ts +23 -21
- package/dist/types/console.d.ts +1 -3
- package/dist/types/db.d.ts +7 -7
- package/dist/types/index.d.ts +1 -0
- package/dist/types/options.d.ts +36 -24
- package/dist/types/site.d.ts +8 -2
- package/dist/types/storage.d.ts +2 -1
- package/dist/types/store-options.d.ts +31 -26
- package/dist/types/studio.d.ts +79 -0
- package/dist/utils/bots.d.ts +7 -3
- package/dist/utils/cms-table-names.d.ts +1 -1
- package/dist/utils/drizzle.d.ts +13 -14
- package/dist/utils/email-inbound.d.ts +4 -4
- package/dist/utils/features.d.ts +19 -5
- package/dist/utils/mcp.d.ts +1 -0
- package/dist/utils/migration-lock.d.ts +15 -29
- package/dist/utils/overridable-routes.d.ts +12 -0
- package/dist/utils/pkg.d.ts +6 -7
- package/dist/utils/schema-diff.d.ts +7 -11
- package/dist/utils/store-schema.d.ts +4 -6
- package/dist/utils/tools.d.ts +3 -3
- package/package.json +55 -5
|
@@ -6,14 +6,16 @@ export declare function getStoreCart(cartIdOrToken: string, event?: RequestEvent
|
|
|
6
6
|
* Resolves the active cart for the current request event and verifies ownership.
|
|
7
7
|
*
|
|
8
8
|
* Enforces ownership:
|
|
9
|
+
*
|
|
9
10
|
* 1. Resolves caller's token from:
|
|
11
|
+
*
|
|
10
12
|
* - `options.sessionToken` (if explicitly passed in body)
|
|
11
13
|
* - `x-cart-session` request header
|
|
12
14
|
* - `qarpeo_cart_session` cookie
|
|
13
15
|
* - Authenticated user ID via `getAuthContext(event)`
|
|
14
|
-
* 2. If caller already has an established cart or session, and an `explicitCartId`
|
|
15
|
-
*
|
|
16
|
-
*
|
|
16
|
+
* 2. If caller already has an established cart or session, and an `explicitCartId` is provided,
|
|
17
|
+
* verifies that `explicitCartId === cart.id` or that the cart belongs to the same authenticated
|
|
18
|
+
* user or session token.
|
|
17
19
|
* 3. Throws 403 Forbidden if a caller attempts to access, mutate, or checkout a foreign cart.
|
|
18
20
|
* 4. Persists the cookie on `event` so the browser maintains the verified session.
|
|
19
21
|
*/
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createError,
|
|
3
|
-
getCookie,
|
|
4
|
-
setCookie,
|
|
5
|
-
getRequestHeader
|
|
6
|
-
} from "nuxt/server";
|
|
1
|
+
import { createError, getCookie, setCookie, getRequestHeader } from "nuxt/server";
|
|
7
2
|
import { getAuthContext } from "../context.mjs";
|
|
8
3
|
import { nanoid } from "../crypto.mjs";
|
|
9
4
|
import { detectStoreCountry, calculateStoreTax } from "../store-localization.mjs";
|
|
@@ -41,9 +36,13 @@ export async function getOrCreateStoreCart(sessionToken, event) {
|
|
|
41
36
|
let cartRow = await db.prepare(`SELECT * FROM ${cart} WHERE session_token = ?`).bind(token).first();
|
|
42
37
|
if (!cartRow && userId) {
|
|
43
38
|
if (tenantId) {
|
|
44
|
-
cartRow = await db.prepare(
|
|
39
|
+
cartRow = await db.prepare(
|
|
40
|
+
`SELECT * FROM ${cart} WHERE user_id = ? AND tenant_id = ? AND expires_at > ? ORDER BY updated_at DESC LIMIT 1`
|
|
41
|
+
).bind(userId, tenantId, now).first();
|
|
45
42
|
} else {
|
|
46
|
-
cartRow = await db.prepare(
|
|
43
|
+
cartRow = await db.prepare(
|
|
44
|
+
`SELECT * FROM ${cart} WHERE user_id = ? AND tenant_id IS NULL AND expires_at > ? ORDER BY updated_at DESC LIMIT 1`
|
|
45
|
+
).bind(userId, now).first();
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
if (!cartRow) {
|
|
@@ -170,7 +169,10 @@ export async function addToStoreCart(cartId, item, event) {
|
|
|
170
169
|
}
|
|
171
170
|
const existing = await db.prepare(`SELECT * FROM ${cartItem} WHERE cart_id = ? AND variant_id = ?`).bind(cartId, item.variantId).first();
|
|
172
171
|
if (existing) {
|
|
173
|
-
const newQty = Math.min(
|
|
172
|
+
const newQty = Math.min(
|
|
173
|
+
999,
|
|
174
|
+
Math.max(1, Math.trunc(Number(existing.quantity) || 0) + safeQuantity)
|
|
175
|
+
);
|
|
174
176
|
await db.prepare(`UPDATE ${cartItem} SET quantity = ?, updated_at = ? WHERE id = ?`).bind(newQty, now, existing.id).run();
|
|
175
177
|
await db.prepare(`UPDATE ${cart} SET updated_at = ? WHERE id = ?`).bind(now, cartId).run();
|
|
176
178
|
const updated = await db.prepare(`SELECT * FROM ${cartItem} WHERE id = ?`).bind(existing.id).first();
|
|
@@ -318,7 +320,9 @@ export async function mergeGuestCartOnLogin(guestSessionToken, userId, event) {
|
|
|
318
320
|
if (!guestCart) {
|
|
319
321
|
return getOrCreateStoreCart(void 0, event);
|
|
320
322
|
}
|
|
321
|
-
const userCart = await db.prepare(
|
|
323
|
+
const userCart = await db.prepare(
|
|
324
|
+
`SELECT * FROM ${cart} WHERE user_id = ? AND expires_at > ? ORDER BY updated_at DESC LIMIT 1`
|
|
325
|
+
).bind(userId, now).first();
|
|
322
326
|
if (!userCart) {
|
|
323
327
|
await db.prepare(`UPDATE ${cart} SET user_id = ?, updated_at = ? WHERE id = ?`).bind(userId, now, guestCart.id).run();
|
|
324
328
|
return await getStoreCart(guestCart.id, event);
|
|
@@ -44,7 +44,10 @@ export async function createStoreCheckoutSession(cartId, opts = {}, event) {
|
|
|
44
44
|
order.items.forEach((item, index) => {
|
|
45
45
|
params.set(`line_items[${index}][price_data][currency]`, order.currency.toLowerCase());
|
|
46
46
|
params.set(`line_items[${index}][price_data][unit_amount]`, String(item.unitPrice));
|
|
47
|
-
params.set(
|
|
47
|
+
params.set(
|
|
48
|
+
`line_items[${index}][price_data][product_data][name]`,
|
|
49
|
+
item.title || "Store Item"
|
|
50
|
+
);
|
|
48
51
|
params.set(`line_items[${index}][quantity]`, String(item.quantity));
|
|
49
52
|
});
|
|
50
53
|
if (order.shippingTotal && order.shippingTotal > 0) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RequestEvent } from "nuxt/server";
|
|
2
|
-
import type { D1Database } from "../../../types/d1";
|
|
3
2
|
import type { StoreOptions } from "../../../../types";
|
|
3
|
+
import type { D1Database } from "../../../types/d1";
|
|
4
4
|
import type { StoreProduct, StoreProductVariant, StoreInventory, StoreCategory, StoreCart, StoreCartItem, StoreCustomerAddress, StoreOrder, StoreOrderItem, StoreDiscount } from "../../../types/store";
|
|
5
5
|
export declare function storeProductTbl(event?: RequestEvent): string;
|
|
6
6
|
export declare function storeVariantTbl(event?: RequestEvent): string;
|
|
@@ -280,7 +280,9 @@ export async function ensureStoreTables(event) {
|
|
|
280
280
|
`CREATE UNIQUE INDEX IF NOT EXISTS ${resolveIndexName(p, "unique_slug")} ON ${p}(COALESCE(tenant_id, ''), slug)`
|
|
281
281
|
),
|
|
282
282
|
db.prepare(`CREATE INDEX IF NOT EXISTS ${resolveIndexName(p, "status")} ON ${p}(status)`),
|
|
283
|
-
db.prepare(
|
|
283
|
+
db.prepare(
|
|
284
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(p, "category")} ON ${p}(category_id)`
|
|
285
|
+
),
|
|
284
286
|
db.prepare(`CREATE INDEX IF NOT EXISTS ${resolveIndexName(p, "tenant")} ON ${p}(tenant_id)`),
|
|
285
287
|
db.prepare(`CREATE INDEX IF NOT EXISTS ${resolveIndexName(p, "vendor")} ON ${p}(vendor_id)`),
|
|
286
288
|
// 2. Product Variants
|
|
@@ -297,7 +299,9 @@ export async function ensureStoreTables(event) {
|
|
|
297
299
|
created_at INTEGER NOT NULL,
|
|
298
300
|
updated_at INTEGER NOT NULL
|
|
299
301
|
)`),
|
|
300
|
-
db.prepare(
|
|
302
|
+
db.prepare(
|
|
303
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(v, "product")} ON ${v}(product_id)`
|
|
304
|
+
),
|
|
301
305
|
db.prepare(`CREATE INDEX IF NOT EXISTS ${resolveIndexName(v, "sku")} ON ${v}(sku)`),
|
|
302
306
|
// 3. Inventory
|
|
303
307
|
db.prepare(`CREATE TABLE IF NOT EXISTS ${inv} (
|
|
@@ -314,7 +318,9 @@ export async function ensureStoreTables(event) {
|
|
|
314
318
|
db.prepare(
|
|
315
319
|
`CREATE UNIQUE INDEX IF NOT EXISTS ${resolveIndexName(inv, "variant")} ON ${inv}(variant_id)`
|
|
316
320
|
),
|
|
317
|
-
db.prepare(
|
|
321
|
+
db.prepare(
|
|
322
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(inv, "product")} ON ${inv}(product_id)`
|
|
323
|
+
),
|
|
318
324
|
// 4. Categories
|
|
319
325
|
db.prepare(`CREATE TABLE IF NOT EXISTS ${c} (
|
|
320
326
|
id TEXT PRIMARY KEY,
|
|
@@ -350,8 +356,12 @@ export async function ensureStoreTables(event) {
|
|
|
350
356
|
db.prepare(
|
|
351
357
|
`CREATE UNIQUE INDEX IF NOT EXISTS ${resolveIndexName(cart, "session")} ON ${cart}(session_token)`
|
|
352
358
|
),
|
|
353
|
-
db.prepare(
|
|
354
|
-
|
|
359
|
+
db.prepare(
|
|
360
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(cart, "user")} ON ${cart}(user_id)`
|
|
361
|
+
),
|
|
362
|
+
db.prepare(
|
|
363
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(cart, "expires")} ON ${cart}(expires_at)`
|
|
364
|
+
),
|
|
355
365
|
// 6. Cart Items
|
|
356
366
|
db.prepare(`CREATE TABLE IF NOT EXISTS ${cartItem} (
|
|
357
367
|
id TEXT PRIMARY KEY,
|
|
@@ -363,7 +373,9 @@ export async function ensureStoreTables(event) {
|
|
|
363
373
|
created_at INTEGER NOT NULL,
|
|
364
374
|
updated_at INTEGER NOT NULL
|
|
365
375
|
)`),
|
|
366
|
-
db.prepare(
|
|
376
|
+
db.prepare(
|
|
377
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(cartItem, "cart")} ON ${cartItem}(cart_id)`
|
|
378
|
+
),
|
|
367
379
|
db.prepare(
|
|
368
380
|
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(cartItem, "variant")} ON ${cartItem}(variant_id)`
|
|
369
381
|
),
|
|
@@ -399,9 +411,13 @@ export async function ensureStoreTables(event) {
|
|
|
399
411
|
`CREATE UNIQUE INDEX IF NOT EXISTS ${resolveIndexName(ord, "unique_number")} ON ${ord}(COALESCE(tenant_id, ''), order_number)`
|
|
400
412
|
),
|
|
401
413
|
db.prepare(`CREATE INDEX IF NOT EXISTS ${resolveIndexName(ord, "user")} ON ${ord}(user_id)`),
|
|
402
|
-
db.prepare(
|
|
414
|
+
db.prepare(
|
|
415
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(ord, "email")} ON ${ord}(customer_email)`
|
|
416
|
+
),
|
|
403
417
|
db.prepare(`CREATE INDEX IF NOT EXISTS ${resolveIndexName(ord, "status")} ON ${ord}(status)`),
|
|
404
|
-
db.prepare(
|
|
418
|
+
db.prepare(
|
|
419
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(ord, "created")} ON ${ord}(created_at)`
|
|
420
|
+
),
|
|
405
421
|
// 8. Order Items
|
|
406
422
|
db.prepare(`CREATE TABLE IF NOT EXISTS ${ordItem} (
|
|
407
423
|
id TEXT PRIMARY KEY,
|
|
@@ -419,11 +435,15 @@ export async function ensureStoreTables(event) {
|
|
|
419
435
|
metadata_json TEXT NOT NULL DEFAULT '{}',
|
|
420
436
|
created_at INTEGER NOT NULL
|
|
421
437
|
)`),
|
|
422
|
-
db.prepare(
|
|
438
|
+
db.prepare(
|
|
439
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(ordItem, "order")} ON ${ordItem}(order_id)`
|
|
440
|
+
),
|
|
423
441
|
db.prepare(
|
|
424
442
|
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(ordItem, "variant")} ON ${ordItem}(variant_id)`
|
|
425
443
|
),
|
|
426
|
-
db.prepare(
|
|
444
|
+
db.prepare(
|
|
445
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(ordItem, "vendor")} ON ${ordItem}(vendor_id)`
|
|
446
|
+
),
|
|
427
447
|
// 9. Discounts
|
|
428
448
|
db.prepare(`CREATE TABLE IF NOT EXISTS ${disc} (
|
|
429
449
|
id TEXT PRIMARY KEY,
|
|
@@ -444,7 +464,9 @@ export async function ensureStoreTables(event) {
|
|
|
444
464
|
db.prepare(
|
|
445
465
|
`CREATE UNIQUE INDEX IF NOT EXISTS ${resolveIndexName(disc, "unique_code")} ON ${disc}(COALESCE(tenant_id, ''), code)`
|
|
446
466
|
),
|
|
447
|
-
db.prepare(
|
|
467
|
+
db.prepare(
|
|
468
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(disc, "active")} ON ${disc}(is_active)`
|
|
469
|
+
),
|
|
448
470
|
// 10. Customer Addresses
|
|
449
471
|
db.prepare(`CREATE TABLE IF NOT EXISTS ${addr} (
|
|
450
472
|
id TEXT PRIMARY KEY,
|
|
@@ -463,7 +485,9 @@ export async function ensureStoreTables(event) {
|
|
|
463
485
|
created_at INTEGER NOT NULL,
|
|
464
486
|
updated_at INTEGER NOT NULL
|
|
465
487
|
)`),
|
|
466
|
-
db.prepare(
|
|
488
|
+
db.prepare(
|
|
489
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(addr, "user")} ON ${addr}(user_id)`
|
|
490
|
+
),
|
|
467
491
|
db.prepare(`CREATE INDEX IF NOT EXISTS ${resolveIndexName(addr, "type")} ON ${addr}(type)`)
|
|
468
492
|
]).then(async () => {
|
|
469
493
|
await db.batch([
|
|
@@ -175,7 +175,9 @@ export async function releaseStoreOrderStock(orderId, event) {
|
|
|
175
175
|
const ordItem = storeOrderItemTbl(event);
|
|
176
176
|
const inv = storeInventoryTbl(event);
|
|
177
177
|
const now = Date.now();
|
|
178
|
-
const items = await db.prepare(
|
|
178
|
+
const items = await db.prepare(
|
|
179
|
+
`SELECT variant_id, quantity FROM ${ordItem} WHERE order_id = ? AND variant_id IS NOT NULL`
|
|
180
|
+
).bind(orderId).all();
|
|
179
181
|
const updates = (items.results ?? []).filter((item) => item.variant_id).map(
|
|
180
182
|
(item) => db.prepare(
|
|
181
183
|
`UPDATE ${inv}
|
|
@@ -2,7 +2,10 @@ import { createError } from "nuxt/server";
|
|
|
2
2
|
import { getAuthContext } from "../context.mjs";
|
|
3
3
|
import { nanoid, signHmacSha256 } from "../crypto.mjs";
|
|
4
4
|
import { getPaymentsConfig } from "../payments/index.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
registerPaymentWebhookListener
|
|
7
|
+
} from "../payments/common.mjs";
|
|
8
|
+
import { getStoreCart, clearStoreCart, calculateStoreCartTotals } from "./cart.mjs";
|
|
6
9
|
import {
|
|
7
10
|
getD1,
|
|
8
11
|
getStoreConfig,
|
|
@@ -16,7 +19,6 @@ import {
|
|
|
16
19
|
rowToOrder,
|
|
17
20
|
rowToAddress
|
|
18
21
|
} from "./common.mjs";
|
|
19
|
-
import { getStoreCart, clearStoreCart, calculateStoreCartTotals } from "./cart.mjs";
|
|
20
22
|
import { commitStoreStock, releaseStoreOrderStock, reserveStoreStock } from "./inventory.mjs";
|
|
21
23
|
function generateOrderNumber() {
|
|
22
24
|
const datePart = (/* @__PURE__ */ new Date()).toISOString().slice(2, 10).replace(/-/g, "");
|
|
@@ -530,24 +532,30 @@ export async function reconcileStoreOrderFromWebhook({
|
|
|
530
532
|
const orderId = obj.metadata.orderId;
|
|
531
533
|
if (orderId) {
|
|
532
534
|
const paymentIntentId = obj.payment_intent || obj.id;
|
|
533
|
-
await updateStoreOrderStatus(
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
).catch((err) => {
|
|
538
|
-
console.warn(
|
|
535
|
+
await updateStoreOrderStatus(orderId, "paid", {
|
|
536
|
+
paymentProvider: "stripe",
|
|
537
|
+
paymentIntentId,
|
|
538
|
+
event
|
|
539
|
+
}).catch((err) => {
|
|
540
|
+
console.warn(
|
|
541
|
+
"[qarpeo:store] Webhook failed to update order to paid:",
|
|
542
|
+
err?.message || err
|
|
543
|
+
);
|
|
539
544
|
});
|
|
540
545
|
}
|
|
541
546
|
}
|
|
542
547
|
} else if (type === "payment_intent.succeeded") {
|
|
543
548
|
const orderId = obj.metadata?.orderId;
|
|
544
549
|
if (orderId && (obj.metadata?.type === "store_order" || obj.metadata?.type === "store")) {
|
|
545
|
-
await updateStoreOrderStatus(
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
).catch((err) => {
|
|
550
|
-
console.warn(
|
|
550
|
+
await updateStoreOrderStatus(orderId, "paid", {
|
|
551
|
+
paymentProvider: "stripe",
|
|
552
|
+
paymentIntentId: obj.id,
|
|
553
|
+
event
|
|
554
|
+
}).catch((err) => {
|
|
555
|
+
console.warn(
|
|
556
|
+
"[qarpeo:store] payment_intent.succeeded failed to update order:",
|
|
557
|
+
err?.message || err
|
|
558
|
+
);
|
|
551
559
|
});
|
|
552
560
|
}
|
|
553
561
|
} else if (type === "payment_intent.payment_failed") {
|
|
@@ -567,22 +575,22 @@ export async function reconcileStoreOrderFromWebhook({
|
|
|
567
575
|
const customData = payload?.meta?.custom_data || {};
|
|
568
576
|
const orderId = customData.orderId || customData.order_id;
|
|
569
577
|
if (orderId && (customData.type === "store_order" || customData.type === "store")) {
|
|
570
|
-
await updateStoreOrderStatus(
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
).catch(() => {
|
|
578
|
+
await updateStoreOrderStatus(orderId, "paid", {
|
|
579
|
+
paymentProvider: "lemonsqueezy",
|
|
580
|
+
paymentIntentId: String(data?.id),
|
|
581
|
+
event
|
|
582
|
+
}).catch(() => {
|
|
575
583
|
});
|
|
576
584
|
}
|
|
577
585
|
} else if (provider === "polar" && (type === "order.created" || type === "payment.succeeded")) {
|
|
578
586
|
const meta = data?.metadata || {};
|
|
579
587
|
const orderId = meta.orderId || meta.order_id;
|
|
580
588
|
if (orderId && (meta.type === "store_order" || meta.type === "store")) {
|
|
581
|
-
await updateStoreOrderStatus(
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
).catch(() => {
|
|
589
|
+
await updateStoreOrderStatus(orderId, "paid", {
|
|
590
|
+
paymentProvider: "polar",
|
|
591
|
+
paymentIntentId: String(data?.id),
|
|
592
|
+
event
|
|
593
|
+
}).catch(() => {
|
|
586
594
|
});
|
|
587
595
|
}
|
|
588
596
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RequestEvent } from "nuxt/server";
|
|
2
|
-
import type { StoreProduct, StoreOrderItem, StoreQueryProductsOptions, StoreVendorMetrics } from "../../../types/store";
|
|
2
|
+
import type { StoreProduct, StoreOrderItem, StoreQueryProductsOptions, StoreVendorMetrics, StoreVendorSummary } from "../../../types/store";
|
|
3
3
|
export declare function isMultiVendorStore(event?: RequestEvent): boolean;
|
|
4
4
|
export declare function getStoreVendorMetrics(vendorId: string, opts?: {
|
|
5
5
|
tenantId?: string;
|
|
@@ -16,3 +16,13 @@ export declare function queryVendorOrderItems(vendorId: string, opts?: {
|
|
|
16
16
|
items: StoreOrderItem[];
|
|
17
17
|
total: number;
|
|
18
18
|
}>;
|
|
19
|
+
/** List active vendors aggregated from published products. */
|
|
20
|
+
export declare function queryStoreVendors(opts?: {
|
|
21
|
+
tenantId?: string;
|
|
22
|
+
limit?: number;
|
|
23
|
+
offset?: number;
|
|
24
|
+
}, event?: RequestEvent): Promise<StoreVendorSummary[]>;
|
|
25
|
+
/** Fetch a single vendor summary by vendor ID. Returns null if no active products exist. */
|
|
26
|
+
export declare function getStoreVendor(vendorId: string, opts?: {
|
|
27
|
+
tenantId?: string;
|
|
28
|
+
}, event?: RequestEvent): Promise<StoreVendorSummary | null>;
|
|
@@ -66,3 +66,50 @@ export async function queryVendorOrderItems(vendorId, opts = {}, event) {
|
|
|
66
66
|
).bind(...params, limit, offset).all();
|
|
67
67
|
return { items: (rows.results ?? []).map(rowToOrderItem), total };
|
|
68
68
|
}
|
|
69
|
+
export async function queryStoreVendors(opts = {}, event) {
|
|
70
|
+
const db = getD1(event);
|
|
71
|
+
const p = storeProductTbl(event);
|
|
72
|
+
const whereClauses = ["status = 'active'", "vendor_id IS NOT NULL"];
|
|
73
|
+
const params = [];
|
|
74
|
+
if (opts.tenantId !== void 0) {
|
|
75
|
+
whereClauses.push("tenant_id = ?");
|
|
76
|
+
params.push(opts.tenantId);
|
|
77
|
+
}
|
|
78
|
+
const limit = Math.min(opts.limit ?? 50, 100);
|
|
79
|
+
const offset = opts.offset ?? 0;
|
|
80
|
+
const result = await db.prepare(
|
|
81
|
+
`SELECT vendor_id as id, COUNT(*) as product_count
|
|
82
|
+
FROM ${p}
|
|
83
|
+
WHERE ${whereClauses.join(" AND ")}
|
|
84
|
+
GROUP BY vendor_id
|
|
85
|
+
ORDER BY product_count DESC
|
|
86
|
+
LIMIT ? OFFSET ?`
|
|
87
|
+
).bind(...params, limit, offset).all();
|
|
88
|
+
return (result.results ?? []).map((row) => ({
|
|
89
|
+
id: row.id,
|
|
90
|
+
name: row.id,
|
|
91
|
+
productCount: Number(row.product_count),
|
|
92
|
+
logoUrl: null,
|
|
93
|
+
description: null
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
export async function getStoreVendor(vendorId, opts = {}, event) {
|
|
97
|
+
const db = getD1(event);
|
|
98
|
+
const p = storeProductTbl(event);
|
|
99
|
+
const whereClauses = ["status = 'active'", "vendor_id = ?"];
|
|
100
|
+
const params = [vendorId];
|
|
101
|
+
if (opts.tenantId !== void 0) {
|
|
102
|
+
whereClauses.push("tenant_id = ?");
|
|
103
|
+
params.push(opts.tenantId);
|
|
104
|
+
}
|
|
105
|
+
const row = await db.prepare(`SELECT COUNT(*) as product_count FROM ${p} WHERE ${whereClauses.join(" AND ")}`).bind(...params).first();
|
|
106
|
+
const count = Number(row?.product_count ?? 0);
|
|
107
|
+
if (count === 0) return null;
|
|
108
|
+
return {
|
|
109
|
+
id: vendorId,
|
|
110
|
+
name: vendorId,
|
|
111
|
+
productCount: count,
|
|
112
|
+
logoUrl: null,
|
|
113
|
+
description: null
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -3,49 +3,31 @@ import type { StoreCurrency, StoreTaxCalculationInput, StoreTaxResult, StoreTaxO
|
|
|
3
3
|
export declare const DEFAULT_STORE_RATES: Record<string, number>;
|
|
4
4
|
export declare const SUPPORTED_STORE_CURRENCIES: Record<string, Omit<StoreCurrency, "rate">>;
|
|
5
5
|
export declare const COUNTRY_TO_CURRENCY_MAP: Record<string, string>;
|
|
6
|
-
/**
|
|
7
|
-
* Detects visitor ISO 3166-1 alpha-2 country code using Cloudflare headers.
|
|
8
|
-
*/
|
|
6
|
+
/** Detects visitor ISO 3166-1 alpha-2 country code using Cloudflare headers. */
|
|
9
7
|
export declare function detectStoreCountry(event?: RequestEvent): string;
|
|
10
|
-
/**
|
|
11
|
-
* Detects visitor preferred currency based on cookie or Cloudflare geo-location.
|
|
12
|
-
*/
|
|
8
|
+
/** Detects visitor preferred currency based on cookie or Cloudflare geo-location. */
|
|
13
9
|
export declare function detectStoreCurrency(event?: RequestEvent, options?: StoreLocalizationOptions): string;
|
|
14
|
-
/**
|
|
15
|
-
* Converts a price in cents from one currency to another using exchange rates.
|
|
16
|
-
*/
|
|
10
|
+
/** Converts a price in cents from one currency to another using exchange rates. */
|
|
17
11
|
export declare function convertStoreCurrency(amountInCents: number, fromCurrency: string, toCurrency: string, rates?: Record<string, number>, rounding?: "none" | "round" | "charm-99" | "charm-95"): number;
|
|
18
|
-
/**
|
|
19
|
-
* Formats a cent amount into a localized currency string.
|
|
20
|
-
*/
|
|
12
|
+
/** Formats a cent amount into a localized currency string. */
|
|
21
13
|
export declare function formatStorePrice(amountInCents: number, currency?: string, locale?: string): string;
|
|
22
|
-
/**
|
|
23
|
-
* Standard EU VAT Rates (as of 2026/2027 standard rules).
|
|
24
|
-
*/
|
|
14
|
+
/** Standard EU VAT Rates (as of 2026/2027 standard rules). */
|
|
25
15
|
export declare const EU_STANDARD_VAT_RATES: Record<string, {
|
|
26
16
|
rate: number;
|
|
27
17
|
name: string;
|
|
28
18
|
}>;
|
|
29
|
-
/**
|
|
30
|
-
* US State Sales Tax Default Base Rates.
|
|
31
|
-
*/
|
|
19
|
+
/** US State Sales Tax Default Base Rates. */
|
|
32
20
|
export declare const US_STATE_TAX_RATES: Record<string, number>;
|
|
33
|
-
/**
|
|
34
|
-
* Canadian Province Combined Sales Tax (GST/PST/HST).
|
|
35
|
-
*/
|
|
21
|
+
/** Canadian Province Combined Sales Tax (GST/PST/HST). */
|
|
36
22
|
export declare const CANADA_PROVINCE_TAX_RATES: Record<string, {
|
|
37
23
|
rate: number;
|
|
38
24
|
name: string;
|
|
39
25
|
}>;
|
|
40
|
-
/**
|
|
41
|
-
* Validates an EU VAT identification number format against official member state syntax rules.
|
|
42
|
-
*/
|
|
26
|
+
/** Validates an EU VAT identification number format against official member state syntax rules. */
|
|
43
27
|
export declare function validateEuVatNumber(vatNumber: string): {
|
|
44
28
|
valid: boolean;
|
|
45
29
|
countryCode?: string;
|
|
46
30
|
cleanNumber?: string;
|
|
47
31
|
};
|
|
48
|
-
/**
|
|
49
|
-
* Edge Tax Engine: Calculates exact tax, VAT, and B2B reverse charge exemptions.
|
|
50
|
-
*/
|
|
32
|
+
/** Edge Tax Engine: Calculates exact tax, VAT, and B2B reverse charge exemptions. */
|
|
51
33
|
export declare function calculateStoreTax(input: StoreTaxCalculationInput, options?: StoreTaxOptions): StoreTaxResult;
|
|
@@ -136,9 +136,9 @@ export function convertStoreCurrency(amountInCents, fromCurrency, toCurrency, ra
|
|
|
136
136
|
const toRate = rates[to] ?? DEFAULT_STORE_RATES[to] ?? 1;
|
|
137
137
|
const fromDecimals = SUPPORTED_STORE_CURRENCIES[from]?.decimals ?? 2;
|
|
138
138
|
const toDecimals = SUPPORTED_STORE_CURRENCIES[to]?.decimals ?? 2;
|
|
139
|
-
const baseUnits = amountInCents /
|
|
139
|
+
const baseUnits = amountInCents / 10 ** fromDecimals / fromRate;
|
|
140
140
|
const targetUnits = baseUnits * toRate;
|
|
141
|
-
let targetCents = Math.round(targetUnits *
|
|
141
|
+
let targetCents = Math.round(targetUnits * 10 ** toDecimals);
|
|
142
142
|
if (toDecimals === 2) {
|
|
143
143
|
if (rounding === "charm-99") {
|
|
144
144
|
const dollars = Math.floor(targetCents / 100);
|
|
@@ -153,7 +153,7 @@ export function convertStoreCurrency(amountInCents, fromCurrency, toCurrency, ra
|
|
|
153
153
|
export function formatStorePrice(amountInCents, currency = "USD", locale = "en-US") {
|
|
154
154
|
const curr = currency.toUpperCase();
|
|
155
155
|
const decimals = SUPPORTED_STORE_CURRENCIES[curr]?.decimals ?? 2;
|
|
156
|
-
const value = amountInCents /
|
|
156
|
+
const value = amountInCents / 10 ** decimals;
|
|
157
157
|
try {
|
|
158
158
|
return new Intl.NumberFormat(locale, {
|
|
159
159
|
style: "currency",
|
|
@@ -5,47 +5,47 @@ export interface TableResolveOptions {
|
|
|
5
5
|
tables?: Record<string, string | undefined>;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* Resolves the database table prefix.
|
|
9
|
-
*
|
|
8
|
+
* Resolves the database table prefix. Priority:
|
|
9
|
+
*
|
|
10
10
|
* 1. Explicit `explicitPrefix` argument (if provided as boolean or string)
|
|
11
11
|
* 2. `tablePrefix` or `prefix` from Qarpeo runtimeConfig (via `event` or global)
|
|
12
12
|
* 3. `process.env.QARPEO_TABLE_PREFIX`
|
|
13
13
|
*
|
|
14
14
|
* Rules:
|
|
15
|
+
*
|
|
15
16
|
* - `false`, `""`, or `undefined` -> `""` (no prefix, clean singular table name)
|
|
16
17
|
* - `true` -> `"qarpeo_"`
|
|
17
18
|
* - `"custom"` -> `"custom_"` (appends underscore if not present)
|
|
18
19
|
* - `"custom_"` -> `"custom_"`
|
|
19
20
|
*/
|
|
20
21
|
export declare function getTablePrefix(event?: RequestEvent, explicitPrefix?: boolean | string): string;
|
|
21
|
-
/**
|
|
22
|
-
* Returns configured granular table name overrides from runtime config or options.
|
|
23
|
-
*/
|
|
22
|
+
/** Returns configured granular table name overrides from runtime config or options. */
|
|
24
23
|
export declare function getTableOverrides(event?: RequestEvent): Record<string, string>;
|
|
25
24
|
/**
|
|
26
25
|
* Resolves a database table name given a base singular name and optional prefix/event/options.
|
|
27
26
|
*
|
|
28
27
|
* Resolution Order:
|
|
28
|
+
*
|
|
29
29
|
* 1. Granular table override (e.g. `tables.user` -> "profiles")
|
|
30
30
|
* 2. Prefix + baseName (e.g. `tablePrefix: "q_"` + "session" -> "q_session")
|
|
31
31
|
* 3. Clean singular baseName (default: "user", "comment", "customer")
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* resolveTableName("user") // "user"
|
|
36
|
+
* resolveTableName("user", "q_") // "q_user"
|
|
37
|
+
* resolveTableName("user", { tables: { user: "profiles" } }) // "profiles"
|
|
38
|
+
* resolveTableName("user", { tablePrefix: "q_", tables: { user: "profiles" } }) // "profiles"
|
|
39
|
+
* ```
|
|
40
40
|
*/
|
|
41
41
|
export declare function resolveTableName(baseName: string, prefixOrEventOrOptions?: boolean | string | RequestEvent | TableResolveOptions, event?: RequestEvent): string;
|
|
42
42
|
/**
|
|
43
43
|
* Resolves an index name given the resolved table name and index suffix.
|
|
44
44
|
*
|
|
45
45
|
* @example
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* resolveIndexName("comment", "target") // "idx_comment_target"
|
|
48
|
+
* resolveIndexName("qarpeo_comment", "target") // "idx_qarpeo_comment_target"
|
|
49
|
+
* ```
|
|
50
50
|
*/
|
|
51
51
|
export declare function resolveIndexName(tableName: string, suffix: string): string;
|
|
@@ -55,7 +55,7 @@ export function resolveTableName(baseName, prefixOrEventOrOptions, event) {
|
|
|
55
55
|
effectiveEvent = prefixOrEventOrOptions;
|
|
56
56
|
}
|
|
57
57
|
const runtimeOverrides = getTableOverrides(effectiveEvent);
|
|
58
|
-
const mergedTables = { ...runtimeOverrides, ...tablesMap
|
|
58
|
+
const mergedTables = { ...runtimeOverrides, ...tablesMap };
|
|
59
59
|
const camelKey = toCamelCase(baseName);
|
|
60
60
|
const override = mergedTables[baseName] || mergedTables[camelKey];
|
|
61
61
|
if (override) {
|
|
@@ -18,9 +18,9 @@ export declare function extractSubdomain(host: string, rootDomains: string[]): s
|
|
|
18
18
|
* Retrieve a tenant record by slug.
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* const tenant = await getTenantBySlug("acme", event)
|
|
23
|
+
* ```
|
|
24
24
|
*/
|
|
25
25
|
export declare function getTenantBySlug(slug: string, event?: RequestEvent): Promise<TenantRecord | null>;
|
|
26
26
|
/** Retrieve a tenant record by ID. */
|
|
@@ -40,9 +40,9 @@ export declare function listTenants(event?: RequestEvent): Promise<TenantRecord[
|
|
|
40
40
|
* 4. Direct database lookup (fallback)
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* const tenant = await resolveTenant(event)
|
|
45
|
+
* ```
|
|
46
46
|
*/
|
|
47
47
|
export declare function resolveTenant(event: RequestEvent): Promise<TenantRecord | null>;
|
|
48
48
|
/** Assign tenant to request context. */
|
|
@@ -52,17 +52,17 @@ export declare function setTenant(event: RequestEvent, tenant: TenantRecord): vo
|
|
|
52
52
|
* matched.
|
|
53
53
|
*
|
|
54
54
|
* @example
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* const tenant = getTenant(event)
|
|
57
|
+
* ```
|
|
58
58
|
*/
|
|
59
59
|
export declare function getTenant(event: RequestEvent): TenantRecord | null;
|
|
60
60
|
/**
|
|
61
61
|
* Retrieve the active tenant or throw a 404 HTTP error.
|
|
62
62
|
*
|
|
63
63
|
* @example
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* const tenant = useTenant(event)
|
|
66
|
+
* ```
|
|
67
67
|
*/
|
|
68
68
|
export declare function useTenant(event: RequestEvent): TenantRecord;
|
|
@@ -73,7 +73,9 @@ export async function getTenantBySlug(slug, event) {
|
|
|
73
73
|
const db = event?.context?.db;
|
|
74
74
|
if (db) {
|
|
75
75
|
await ensureTenantsTableMigrated(db, event);
|
|
76
|
-
const rows = await db.all(`SELECT * FROM ${tenantTbl(event)} WHERE slug = ? LIMIT 1`, [
|
|
76
|
+
const rows = await db.all(`SELECT * FROM ${tenantTbl(event)} WHERE slug = ? LIMIT 1`, [
|
|
77
|
+
cleanSlug
|
|
78
|
+
]);
|
|
77
79
|
if (rows?.[0]) {
|
|
78
80
|
const row = rows[0];
|
|
79
81
|
const rec = {
|
|
@@ -136,9 +138,10 @@ export async function getTenantByOrganization(orgId, event) {
|
|
|
136
138
|
const db = event?.context?.db;
|
|
137
139
|
if (db) {
|
|
138
140
|
await ensureTenantsTableMigrated(db, event);
|
|
139
|
-
const rows = await db.all(
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
const rows = await db.all(
|
|
142
|
+
`SELECT * FROM ${tenantTbl(event)} WHERE organization_id = ? LIMIT 1`,
|
|
143
|
+
[orgId]
|
|
144
|
+
);
|
|
142
145
|
if (rows?.[0]) {
|
|
143
146
|
const row = rows[0];
|
|
144
147
|
const rec = {
|