@jarwizz/create-jarshop 0.1.9 → 0.3.1
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 +15 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/generator.d.ts +11 -1
- package/dist/generator.js +45 -11
- package/dist/generator.js.map +1 -1
- package/dist/presets.d.ts +26 -0
- package/dist/presets.js +94 -0
- package/dist/presets.js.map +1 -0
- package/dist/template/CONTEXT.md +4 -2
- package/dist/template/README.md +255 -3
- package/dist/template/env.example.template +19 -0
- package/dist/template/gitignore.template +1 -0
- package/dist/template/jarshop.config.ts +31 -0
- package/dist/template/package.json +4 -0
- package/dist/template/pnpm-lock.yaml +3284 -1815
- package/dist/template/pnpm-workspace.yaml +6 -1
- package/dist/template/src/client/features.ts +41 -0
- package/dist/template/src/client/invoicing.ts +29 -0
- package/dist/template/src/dev-storefront-environment.test.ts +45 -0
- package/dist/template/src/dev-storefront-environment.ts +32 -0
- package/dist/template/src/dev-storefront.ts +3 -12
- package/dist/template/src/environment.d.ts +8 -0
- package/dist/template/src/invoice-email-recover.ts +59 -0
- package/dist/template/src/jarshop-config-loader.ts +118 -0
- package/dist/template/src/jarshop-config.test.ts +335 -0
- package/dist/template/src/jarshop-config.ts +439 -0
- package/dist/template/src/jarshop-features.test.ts +222 -0
- package/dist/template/src/jarshop-features.ts +112 -0
- package/dist/template/src/operation-codes.ts +34 -0
- package/dist/template/src/packeta-config.test.ts +95 -0
- package/dist/template/src/packeta-countries.test.ts +161 -0
- package/dist/template/src/packeta-countries.ts +120 -0
- package/dist/template/src/packeta-validation.test.ts +35 -0
- package/dist/template/src/packeta-validation.ts +52 -0
- package/dist/template/src/payment-return-url.test.ts +57 -0
- package/dist/template/src/payment-return-url.ts +34 -0
- package/dist/template/src/plugins/jarshop-checkout/confirmation-view.test.ts +79 -0
- package/dist/template/src/plugins/jarshop-checkout/confirmation.ts +51 -0
- package/dist/template/src/plugins/jarshop-checkout/dashboard/index.tsx +1 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-delivery.plugin.ts +79 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email-events.ts +35 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email-lifecycle.ts +235 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email-worker.test.ts +426 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email.test.ts +107 -0
- package/dist/template/src/plugins/jarshop-checkout/jarshop-checkout.plugin.ts +161 -57
- package/dist/template/src/plugins/jarshop-checkout/market-channels.test.ts +58 -0
- package/dist/template/src/plugins/jarshop-checkout/market-channels.ts +87 -0
- package/dist/template/src/plugins/jarshop-checkout/operation-code-check.ts +36 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-configuration.entity.ts +1 -1
- package/dist/template/src/plugins/jarshop-checkout/order-email-configuration.ts +1 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-delivery-core.ts +94 -1
- package/dist/template/src/plugins/jarshop-checkout/order-email-delivery.entity.ts +1 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-outbox.ts +83 -1
- package/dist/template/src/plugins/jarshop-checkout/order-email-worker.ts +136 -1
- package/dist/template/src/plugins/jarshop-checkout/shipping-tax.test.ts +109 -0
- package/dist/template/src/plugins/jarshop-checkout/shipping.test.ts +156 -0
- package/dist/template/src/plugins/jarshop-checkout/shipping.ts +75 -11
- package/dist/template/src/seed.ts +427 -184
- package/dist/template/src/vendure-config.ts +258 -113
- package/dist/template/storefront/README.md +7 -0
- package/dist/template/storefront/app/[locale]/[slug]/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/login/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/page.tsx +10 -4
- package/dist/template/storefront/app/[locale]/account/password-reset/callback/route.ts +4 -2
- package/dist/template/storefront/app/[locale]/account/password-reset/complete/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/password-reset/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/register/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/verify/complete/route.ts +4 -2
- package/dist/template/storefront/app/[locale]/account/verify/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/cart/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/checkout/actions.ts +43 -0
- package/dist/template/storefront/app/[locale]/checkout/checkout-form.tsx +188 -36
- package/dist/template/storefront/app/[locale]/checkout/confirmation/route.ts +2 -2
- package/dist/template/storefront/app/[locale]/checkout/packeta-chooser.tsx +96 -0
- package/dist/template/storefront/app/[locale]/checkout/page.tsx +60 -2
- package/dist/template/storefront/app/[locale]/checkout/payment-return/actions.ts +55 -0
- package/dist/template/storefront/app/[locale]/checkout/payment-return/page.tsx +32 -0
- package/dist/template/storefront/app/[locale]/checkout/payment-return/payment-return.tsx +84 -0
- package/dist/template/storefront/app/[locale]/checkout/success/page.tsx +32 -2
- package/dist/template/storefront/app/[locale]/layout.tsx +3 -2
- package/dist/template/storefront/app/[locale]/page.tsx +3 -2
- package/dist/template/storefront/app/globals.css +16 -0
- package/dist/template/storefront/app/layout.tsx +6 -2
- package/dist/template/storefront/lib/cart.ts +2 -4
- package/dist/template/storefront/lib/checkout-contract.test.ts +18 -1
- package/dist/template/storefront/lib/checkout-contract.ts +8 -0
- package/dist/template/storefront/lib/checkout-countries.test.ts +61 -0
- package/dist/template/storefront/lib/checkout-countries.ts +67 -0
- package/dist/template/storefront/lib/checkout.ts +22 -11
- package/dist/template/storefront/lib/commerce.ts +262 -2
- package/dist/template/storefront/lib/confirmation.test.ts +116 -0
- package/dist/template/storefront/lib/confirmation.ts +13 -7
- package/dist/template/storefront/lib/i18n.test.ts +32 -12
- package/dist/template/storefront/lib/i18n.ts +29 -8
- package/dist/template/storefront/lib/market-config.ts +40 -0
- package/dist/template/storefront/lib/market-routing.test.ts +107 -0
- package/dist/template/storefront/lib/market-routing.ts +57 -0
- package/dist/template/storefront/lib/market.ts +51 -0
- package/dist/template/storefront/lib/packeta-selection.test.ts +141 -0
- package/dist/template/storefront/lib/packeta-selection.ts +98 -0
- package/dist/template/storefront/lib/payment-return-actions.test.ts +61 -0
- package/dist/template/storefront/lib/payment-return-page.test.ts +30 -0
- package/dist/template/storefront/lib/payment-return-polling.test.ts +37 -0
- package/dist/template/storefront/lib/payment-return-polling.ts +58 -0
- package/dist/template/storefront/messages/en.json +13 -1
- package/dist/template/storefront/messages/sk.json +13 -1
- package/dist/template/storefront/package.json +2 -1
- package/dist/template/storefront/proxy.ts +35 -0
- package/dist/template/turbo.json +5 -1
- package/dist/template-manifest.json +1 -1
- package/dist/template.js +1 -0
- package/dist/template.js.map +1 -1
- package/package.json +1 -1
|
@@ -8,8 +8,11 @@ packages:
|
|
|
8
8
|
overrides:
|
|
9
9
|
eslint-import-resolver-typescript: 3.8.7
|
|
10
10
|
|
|
11
|
+
# JarShop publishes its own @jarwizz packages from CI with OIDC; the release-age
|
|
12
|
+
# delay protects against third-party takeovers, not against our own releases,
|
|
13
|
+
# so the Starter consumes a freshly published platform release immediately.
|
|
11
14
|
minimumReleaseAgeExclude:
|
|
12
|
-
- "@jarwizz
|
|
15
|
+
- "@jarwizz/*"
|
|
13
16
|
|
|
14
17
|
allowBuilds:
|
|
15
18
|
bcrypt: true
|
|
@@ -20,6 +23,7 @@ allowBuilds:
|
|
|
20
23
|
ssh2: false
|
|
21
24
|
"@apollo/protobufjs": false
|
|
22
25
|
msw: false
|
|
26
|
+
"puppeteer@23.1.0": false
|
|
23
27
|
strictDepBuilds: true
|
|
24
28
|
dangerouslyAllowAllBuilds: false
|
|
25
29
|
verifyDepsBeforeRun: warn
|
|
@@ -31,6 +35,7 @@ trustPolicy: no-downgrade
|
|
|
31
35
|
trustPolicyExclude:
|
|
32
36
|
- semver@6.3.1
|
|
33
37
|
- chokidar@4.0.3
|
|
38
|
+
- encodeurl@2.0.2
|
|
34
39
|
trustLockfile: false
|
|
35
40
|
blockExoticSubdeps: true
|
|
36
41
|
patchedDependencies:
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { defaultShippingEligibilityChecker } from "@vendure/core";
|
|
2
|
+
import { createTariffShippingCalculator } from "@jarwizz/feature-adapter-kit/server";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
jarShopCodPaymentHandler,
|
|
6
|
+
referenceRedirectPaymentHandler,
|
|
7
|
+
type JarShopFeatures,
|
|
8
|
+
} from "../jarshop-features.js";
|
|
9
|
+
import { invoicingConfig } from "./invoicing.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Client-owned feature composition. Upgrades never change anything under
|
|
13
|
+
* `src/client/`; platform-managed `src/vendure-config.ts` only reads this file.
|
|
14
|
+
*
|
|
15
|
+
* - `paymentMethodHandlers`: every payment handler the shop offers. Add a
|
|
16
|
+
* provider Feature's handler here, or remove one you do not use.
|
|
17
|
+
* - `shippingEligibilityCheckers` / `shippingCalculators`: the shipping
|
|
18
|
+
* operations Shipping Methods may use. The demo pickup and courier methods
|
|
19
|
+
* use the tariff calculator, which taxes shipping by the order's tax zone
|
|
20
|
+
* (one TaxRate per market zone and tax category) instead of one fixed rate.
|
|
21
|
+
* - `packeta`: Packeta pickup points; `JARSHOP_PACKETA_ENABLED=0` still
|
|
22
|
+
* switches it off for one environment.
|
|
23
|
+
* - `invoicing`: built-in Slovak invoicing from `./invoicing.ts`, or `false`
|
|
24
|
+
* for a shop that issues invoices elsewhere.
|
|
25
|
+
* - `plugins` / `migrations`: any other Vendure plugin, for example a published
|
|
26
|
+
* Feature Package or your own plugin under `src/client/`, and its migrations.
|
|
27
|
+
*/
|
|
28
|
+
const features = {
|
|
29
|
+
paymentMethodHandlers: [
|
|
30
|
+
jarShopCodPaymentHandler,
|
|
31
|
+
referenceRedirectPaymentHandler,
|
|
32
|
+
],
|
|
33
|
+
shippingEligibilityCheckers: [defaultShippingEligibilityChecker],
|
|
34
|
+
shippingCalculators: [createTariffShippingCalculator()],
|
|
35
|
+
packeta: true,
|
|
36
|
+
invoicing: invoicingConfig,
|
|
37
|
+
plugins: [],
|
|
38
|
+
migrations: [],
|
|
39
|
+
} satisfies JarShopFeatures;
|
|
40
|
+
|
|
41
|
+
export default features;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { SellerProfile } from "@jarwizz/jarshop-invoicing";
|
|
3
|
+
import { configureSlovakInvoicing } from "@jarwizz/jarshop-invoicing/server";
|
|
4
|
+
|
|
5
|
+
// Client-owned, reviewed invoicing configuration used by ./features.ts.
|
|
6
|
+
// Replace this synthetic profile and Last Issued Number before issuing any
|
|
7
|
+
// real invoices. Never reset a live series.
|
|
8
|
+
export const invoiceSeller: SellerProfile = {
|
|
9
|
+
name: "JarShop ukážkový obchod",
|
|
10
|
+
street: "Testovacia 1",
|
|
11
|
+
city: "Žilina",
|
|
12
|
+
postalCode: "010 01",
|
|
13
|
+
ico: "00000000",
|
|
14
|
+
dic: "0000000000",
|
|
15
|
+
vatStatus: "non-payer",
|
|
16
|
+
iban: "TEST-IBAN",
|
|
17
|
+
registerEntry: "Ukážkový register — nie je skutočný predajca",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const invoicingConfig = configureSlovakInvoicing({
|
|
21
|
+
seller: invoiceSeller,
|
|
22
|
+
lastIssuedNumber: 20260000,
|
|
23
|
+
vendureHost: process.env.JARSHOP_VENDURE_HOST ?? "http://localhost:3000",
|
|
24
|
+
localStorageDirectory:
|
|
25
|
+
process.env.JARSHOP_INVOICE_DIRECTORY ??
|
|
26
|
+
path.join(__dirname, "../../static/invoices"),
|
|
27
|
+
chromeExecutablePath:
|
|
28
|
+
process.env.PUPPETEER_EXECUTABLE_PATH ?? "/usr/bin/chromium",
|
|
29
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { storefrontChildEnvironment } from "./dev-storefront-environment.js";
|
|
4
|
+
|
|
5
|
+
describe("the local storefront process environment", () => {
|
|
6
|
+
it("forwards only runtime plumbing and explicit server-side storefront values", () => {
|
|
7
|
+
const child = storefrontChildEnvironment({
|
|
8
|
+
APP_ENV: "dev",
|
|
9
|
+
COOKIE_SECRET: "do-not-forward",
|
|
10
|
+
DB_PASSWORD: "do-not-forward",
|
|
11
|
+
PACKETA_API_KEY: "do-not-forward",
|
|
12
|
+
JARSHOP_PACKETA_ENABLED: "0",
|
|
13
|
+
JARSHOP_FAKE_PACKETA_VALIDATION: "1",
|
|
14
|
+
PATH: "/usr/bin",
|
|
15
|
+
HOME: "/tmp/home",
|
|
16
|
+
CI: "1",
|
|
17
|
+
JARSHOP_COMMERCE_ENDPOINT: "http://localhost:3000/shop-api",
|
|
18
|
+
JARSHOP_ACCOUNT_RATE_LIMIT_URL: "redis://localhost:6380",
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(child).toMatchObject({
|
|
22
|
+
PATH: "/usr/bin",
|
|
23
|
+
HOME: "/tmp/home",
|
|
24
|
+
CI: "1",
|
|
25
|
+
JARSHOP_COMMERCE_ENDPOINT: "http://localhost:3000/shop-api",
|
|
26
|
+
JARSHOP_ACCOUNT_RATE_LIMIT_URL: "redis://localhost:6380",
|
|
27
|
+
});
|
|
28
|
+
expect(child).not.toHaveProperty("APP_ENV");
|
|
29
|
+
expect(child).not.toHaveProperty("COOKIE_SECRET");
|
|
30
|
+
expect(child).not.toHaveProperty("DB_PASSWORD");
|
|
31
|
+
expect(child).not.toHaveProperty("PACKETA_API_KEY");
|
|
32
|
+
expect(child).not.toHaveProperty("JARSHOP_PACKETA_ENABLED");
|
|
33
|
+
expect(child).not.toHaveProperty("JARSHOP_FAKE_PACKETA_VALIDATION");
|
|
34
|
+
expect(child).not.toHaveProperty("JARSHOP_DEV_MARKET");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("forwards the development market only when one is chosen", () => {
|
|
38
|
+
expect(
|
|
39
|
+
storefrontChildEnvironment({ JARSHOP_DEV_MARKET: "cz" }),
|
|
40
|
+
).toMatchObject({ JARSHOP_DEV_MARKET: "cz" });
|
|
41
|
+
expect(
|
|
42
|
+
storefrontChildEnvironment({ JARSHOP_DEV_MARKET: "" }),
|
|
43
|
+
).not.toHaveProperty("JARSHOP_DEV_MARKET");
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const runtimeKeys = [
|
|
2
|
+
"CI",
|
|
3
|
+
"FORCE_COLOR",
|
|
4
|
+
"HOME",
|
|
5
|
+
"NO_COLOR",
|
|
6
|
+
"PATH",
|
|
7
|
+
"SHELL",
|
|
8
|
+
"TERM",
|
|
9
|
+
"TMPDIR",
|
|
10
|
+
] as const;
|
|
11
|
+
|
|
12
|
+
export function storefrontChildEnvironment(
|
|
13
|
+
environment: NodeJS.ProcessEnv,
|
|
14
|
+
): NodeJS.ProcessEnv {
|
|
15
|
+
const runtime = Object.fromEntries(
|
|
16
|
+
runtimeKeys.flatMap((key) =>
|
|
17
|
+
environment[key] === undefined ? [] : [[key, environment[key]]],
|
|
18
|
+
),
|
|
19
|
+
);
|
|
20
|
+
return {
|
|
21
|
+
...runtime,
|
|
22
|
+
JARSHOP_COMMERCE_ENDPOINT:
|
|
23
|
+
environment.JARSHOP_COMMERCE_ENDPOINT ??
|
|
24
|
+
`http://localhost:${environment.PORT ?? "3000"}/shop-api`,
|
|
25
|
+
JARSHOP_ACCOUNT_RATE_LIMIT_URL:
|
|
26
|
+
environment.JARSHOP_ACCOUNT_RATE_LIMIT_URL ?? "redis://localhost:6380",
|
|
27
|
+
NEXT_TELEMETRY_DISABLED: environment.NEXT_TELEMETRY_DISABLED ?? "1",
|
|
28
|
+
...(environment.JARSHOP_DEV_MARKET
|
|
29
|
+
? { JARSHOP_DEV_MARKET: environment.JARSHOP_DEV_MARKET }
|
|
30
|
+
: {}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -2,8 +2,9 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import dotenv from "dotenv";
|
|
4
4
|
|
|
5
|
+
import { storefrontChildEnvironment } from "./dev-storefront-environment.js";
|
|
6
|
+
|
|
5
7
|
const root = resolve(__dirname, "..");
|
|
6
|
-
const inheritedEnvironment = { ...process.env };
|
|
7
8
|
|
|
8
9
|
function parsePort(value: string): number {
|
|
9
10
|
const port = Number(value);
|
|
@@ -20,9 +21,6 @@ async function main(): Promise<void> {
|
|
|
20
21
|
const storefrontPort = parsePort(
|
|
21
22
|
process.env.JARSHOP_STOREFRONT_PORT ?? "3001",
|
|
22
23
|
);
|
|
23
|
-
const commerceEndpoint =
|
|
24
|
-
process.env.JARSHOP_COMMERCE_ENDPOINT ??
|
|
25
|
-
`http://localhost:${process.env.PORT ?? "3000"}/shop-api`;
|
|
26
24
|
const child = spawn(
|
|
27
25
|
"pnpm",
|
|
28
26
|
["--dir", "storefront", "dev", "--port", String(storefrontPort)],
|
|
@@ -33,14 +31,7 @@ async function main(): Promise<void> {
|
|
|
33
31
|
// Server, worker and database credentials therefore stay inside their
|
|
34
32
|
// own process; the local storefront receives only the commerce endpoint
|
|
35
33
|
// and its server-only local Valkey URL.
|
|
36
|
-
env:
|
|
37
|
-
...inheritedEnvironment,
|
|
38
|
-
JARSHOP_COMMERCE_ENDPOINT: commerceEndpoint,
|
|
39
|
-
JARSHOP_ACCOUNT_RATE_LIMIT_URL:
|
|
40
|
-
process.env.JARSHOP_ACCOUNT_RATE_LIMIT_URL ??
|
|
41
|
-
"redis://localhost:6380",
|
|
42
|
-
NEXT_TELEMETRY_DISABLED: process.env.NEXT_TELEMETRY_DISABLED ?? "1",
|
|
43
|
-
},
|
|
34
|
+
env: storefrontChildEnvironment(process.env),
|
|
44
35
|
},
|
|
45
36
|
);
|
|
46
37
|
await new Promise<void>((resolvePromise, reject) => {
|
|
@@ -7,6 +7,10 @@ declare global {
|
|
|
7
7
|
PORT?: string;
|
|
8
8
|
JARSHOP_STOREFRONT_PORT?: string;
|
|
9
9
|
JARSHOP_COMMERCE_ENDPOINT?: string;
|
|
10
|
+
PACKETA_API_KEY?: string;
|
|
11
|
+
JARSHOP_PACKETA_ENABLED?: string;
|
|
12
|
+
JARSHOP_PACKETA_ZBOX_ENABLED?: string;
|
|
13
|
+
JARSHOP_FAKE_PACKETA_VALIDATION?: string;
|
|
10
14
|
COOKIE_SECRET?: string;
|
|
11
15
|
SUPERADMIN_USERNAME?: string;
|
|
12
16
|
SUPERADMIN_PASSWORD?: string;
|
|
@@ -20,6 +24,10 @@ declare global {
|
|
|
20
24
|
JARSHOP_EMAIL_TRANSPORT?: string;
|
|
21
25
|
JARSHOP_EMAIL_FILE_TRANSPORT_PATH?: string;
|
|
22
26
|
JARSHOP_STOREFRONT_URL?: string;
|
|
27
|
+
JARSHOP_DEV_MARKET?: string;
|
|
28
|
+
JARSHOP_MARKET_CHANNEL_CHECK?: string;
|
|
29
|
+
NEXT_PUBLIC_JARSHOP_PAYMENT_RETURN_POLL_INTERVAL_MS?: string;
|
|
30
|
+
NEXT_PUBLIC_JARSHOP_PAYMENT_RETURN_POLL_WINDOW_MS?: string;
|
|
23
31
|
}
|
|
24
32
|
}
|
|
25
33
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import {
|
|
3
|
+
bootstrapWorker,
|
|
4
|
+
Injector,
|
|
5
|
+
RequestContextService,
|
|
6
|
+
} from "@vendure/core";
|
|
7
|
+
import { ModuleRef } from "@nestjs/core";
|
|
8
|
+
import { getJarShopInvoiceDeliveryEvents } from "@jarwizz/jarshop-invoicing/server";
|
|
9
|
+
import { config } from "./vendure-config.js";
|
|
10
|
+
import { JarShopInvoiceEmailOutbox } from "./plugins/jarshop-checkout/invoice-email-lifecycle.js";
|
|
11
|
+
import { JarShopInvoiceDeliveryPlugin } from "./plugins/jarshop-checkout/invoice-delivery.plugin.js";
|
|
12
|
+
|
|
13
|
+
/** Invoicing is switched off in src/client/features.ts. */
|
|
14
|
+
class InvoicingDisabledError extends Error {}
|
|
15
|
+
|
|
16
|
+
async function main() {
|
|
17
|
+
const [channelToken, orderId, ...extra] = process.argv.slice(2);
|
|
18
|
+
if (
|
|
19
|
+
!channelToken ||
|
|
20
|
+
!orderId ||
|
|
21
|
+
!/^[1-9]\d*$/.test(orderId) ||
|
|
22
|
+
extra.length
|
|
23
|
+
) {
|
|
24
|
+
throw new Error("Usage: invoice-email-recover.ts CHANNEL_TOKEN ORDER_ID");
|
|
25
|
+
}
|
|
26
|
+
if (!config.plugins?.includes(JarShopInvoiceDeliveryPlugin)) {
|
|
27
|
+
throw new InvoicingDisabledError();
|
|
28
|
+
}
|
|
29
|
+
const worker = await bootstrapWorker(config);
|
|
30
|
+
try {
|
|
31
|
+
const ctx = await worker.app
|
|
32
|
+
.get(RequestContextService)
|
|
33
|
+
.create({ apiType: "admin", channelOrToken: channelToken });
|
|
34
|
+
if (ctx.channel.token !== channelToken) throw new Error("Unknown Channel");
|
|
35
|
+
const events = await getJarShopInvoiceDeliveryEvents(
|
|
36
|
+
ctx,
|
|
37
|
+
new Injector(worker.app.get(ModuleRef)),
|
|
38
|
+
orderId,
|
|
39
|
+
);
|
|
40
|
+
const outbox = worker.app.get(JarShopInvoiceEmailOutbox);
|
|
41
|
+
for (const event of events) {
|
|
42
|
+
await outbox.recover(event);
|
|
43
|
+
}
|
|
44
|
+
console.log(
|
|
45
|
+
"Invoice delivery recovery complete; existing sent deliveries were preserved.",
|
|
46
|
+
);
|
|
47
|
+
} finally {
|
|
48
|
+
await worker.app.close();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
main().catch((error: unknown) => {
|
|
53
|
+
console.error(
|
|
54
|
+
error instanceof InvoicingDisabledError
|
|
55
|
+
? "INVOICING_DISABLED"
|
|
56
|
+
: "INVOICE_EMAIL_RECOVERY_FAILED",
|
|
57
|
+
);
|
|
58
|
+
process.exitCode = 1;
|
|
59
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
defaultMarket,
|
|
7
|
+
marketForChannelToken,
|
|
8
|
+
parseJarShopConfig,
|
|
9
|
+
resolveMarketLanguage,
|
|
10
|
+
type JarShopConfig,
|
|
11
|
+
type JarShopMarket,
|
|
12
|
+
} from "./jarshop-config.js";
|
|
13
|
+
|
|
14
|
+
export const jarShopConfigFileName = "jarshop.config.ts";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Finds the client-owned configuration by walking up from the running module.
|
|
18
|
+
* The same lookup works from `src` under tsx, from the compiled `dist`, and
|
|
19
|
+
* from the copy the Dashboard build compiles inside `node_modules`. The working
|
|
20
|
+
* directory is only a last resort.
|
|
21
|
+
*/
|
|
22
|
+
export function locateJarShopConfig(
|
|
23
|
+
startDirectory: string = __dirname,
|
|
24
|
+
): string {
|
|
25
|
+
let directory = path.resolve(startDirectory);
|
|
26
|
+
for (;;) {
|
|
27
|
+
const candidate = path.join(directory, jarShopConfigFileName);
|
|
28
|
+
if (existsSync(candidate)) return candidate;
|
|
29
|
+
const parent = path.dirname(directory);
|
|
30
|
+
if (parent === directory) break;
|
|
31
|
+
directory = parent;
|
|
32
|
+
}
|
|
33
|
+
const fromWorkingDirectory = path.resolve(jarShopConfigFileName);
|
|
34
|
+
if (existsSync(fromWorkingDirectory)) return fromWorkingDirectory;
|
|
35
|
+
throw new Error(
|
|
36
|
+
`${jarShopConfigFileName} was not found above ${startDirectory} or in ${process.cwd()}. ` +
|
|
37
|
+
`Every JarShop project declares its markets in this client-owned file at the project root; ` +
|
|
38
|
+
`deploy it next to package.json and dist/, not under node_modules. A project generated before ` +
|
|
39
|
+
`markets existed must create it first: see "Markets" in the project README for the sk-standard example.`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Loads and validates `jarshop.config.ts`. The file stays TypeScript source:
|
|
45
|
+
* it is kept out of the server compilation so the build output layout does not
|
|
46
|
+
* change, and Node 24 strips its erasable types when it is required here.
|
|
47
|
+
*/
|
|
48
|
+
export function readJarShopConfig(file: string): JarShopConfig {
|
|
49
|
+
const loaded = createRequire(file)(file) as { default?: unknown };
|
|
50
|
+
return parseJarShopConfig(loaded.default ?? loaded, file);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let cached: JarShopConfig | undefined;
|
|
54
|
+
|
|
55
|
+
export function loadJarShopConfig(): JarShopConfig {
|
|
56
|
+
cached ??= readJarShopConfig(locateJarShopConfig());
|
|
57
|
+
return cached;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function loadDefaultMarket(): JarShopMarket {
|
|
61
|
+
return defaultMarket(loadJarShopConfig());
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The market of a Vendure request context. A Channel that no market claims,
|
|
66
|
+
* such as one an operator created by hand, is treated as the default market.
|
|
67
|
+
*/
|
|
68
|
+
export function marketForChannel(
|
|
69
|
+
channelToken: string | undefined,
|
|
70
|
+
): JarShopMarket {
|
|
71
|
+
const config = loadJarShopConfig();
|
|
72
|
+
return marketForChannelToken(config, channelToken) ?? defaultMarket(config);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The market of an order. Vendure also assigns every order to its default
|
|
77
|
+
* Channel, so a configured non-default market wins over the default one.
|
|
78
|
+
*/
|
|
79
|
+
export function marketForOrderChannels(
|
|
80
|
+
channelTokens: readonly string[],
|
|
81
|
+
): JarShopMarket {
|
|
82
|
+
const config = loadJarShopConfig();
|
|
83
|
+
const fallback = defaultMarket(config);
|
|
84
|
+
const markets = channelTokens.flatMap(
|
|
85
|
+
(token) => marketForChannelToken(config, token) ?? [],
|
|
86
|
+
);
|
|
87
|
+
return markets.find((market) => market !== fallback) ?? fallback;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The storefront origin for links in emails and payment returns. A market's
|
|
92
|
+
* first domain is used outside development; development and single-domain
|
|
93
|
+
* deployments use JARSHOP_STOREFRONT_URL.
|
|
94
|
+
*/
|
|
95
|
+
export function storefrontOriginForMarket(
|
|
96
|
+
market: JarShopMarket,
|
|
97
|
+
environment: NodeJS.ProcessEnv = process.env,
|
|
98
|
+
): URL {
|
|
99
|
+
const configured = new URL(
|
|
100
|
+
environment.JARSHOP_STOREFRONT_URL ?? "http://localhost:3001",
|
|
101
|
+
);
|
|
102
|
+
const domain = market.domains[0];
|
|
103
|
+
if (environment.APP_ENV === "dev" || !domain) return configured;
|
|
104
|
+
return new URL(`https://${domain}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function storefrontMarketUrl(
|
|
108
|
+
market: JarShopMarket,
|
|
109
|
+
language: string,
|
|
110
|
+
pathname: string,
|
|
111
|
+
environment: NodeJS.ProcessEnv = process.env,
|
|
112
|
+
): string {
|
|
113
|
+
const prefix = resolveMarketLanguage(market, language);
|
|
114
|
+
return new URL(
|
|
115
|
+
`/${prefix}/${pathname.replace(/^\/+/u, "")}`,
|
|
116
|
+
storefrontOriginForMarket(market, environment),
|
|
117
|
+
).toString();
|
|
118
|
+
}
|