@huloglobal/vendure-plugin-quotations 0.1.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 +20 -0
- package/LICENSE +685 -0
- package/README.md +48 -0
- package/dist/crons.d.ts +15 -0
- package/dist/crons.d.ts.map +1 -0
- package/dist/crons.js +63 -0
- package/dist/crons.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +63 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +177 -0
- package/dist/plugin.js.map +1 -0
- package/dist/pricing.d.ts +22 -0
- package/dist/pricing.d.ts.map +1 -0
- package/dist/pricing.js +46 -0
- package/dist/pricing.js.map +1 -0
- package/dist/quotation.controller.d.ts +36 -0
- package/dist/quotation.controller.d.ts.map +1 -0
- package/dist/quotation.controller.js +453 -0
- package/dist/quotation.controller.js.map +1 -0
- package/dist/quotation.service.d.ts +79 -0
- package/dist/quotation.service.d.ts.map +1 -0
- package/dist/quotation.service.js +676 -0
- package/dist/quotation.service.js.map +1 -0
- package/dist/templates.d.ts +10 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +164 -0
- package/dist/templates.js.map +1 -0
- package/dist/types.d.ts +72 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +25 -0
- package/dist/types.js.map +1 -0
- package/package.json +39 -0
- package/ui/components/quotations.component.ts +804 -0
- package/ui/quotations.module.ts +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @huloglobal/vendure-plugin-quotations
|
|
2
|
+
|
|
3
|
+
End-to-end quotation engine for [Vendure](https://www.vendure.io/):
|
|
4
|
+
|
|
5
|
+
- **Build** quotes from your catalogue (live prices, per-line + quote-level
|
|
6
|
+
discounts, VAT, validity) or free-text lines — multi-channel, branded.
|
|
7
|
+
- **Send** a branded email with a signed customer link.
|
|
8
|
+
- **Track** viewed / accepted / declined — acceptance captures a typed-name
|
|
9
|
+
signature; every step lands in a per-quote audit trail.
|
|
10
|
+
- **Chase** automatically: one reminder for unopened quotes and an
|
|
11
|
+
expires-soon nudge, plus auto-expiry.
|
|
12
|
+
- **Convert** accepted quotes to Vendure draft orders at the exact quoted
|
|
13
|
+
total (a pricing surcharge reconciles quoted vs catalogue pricing).
|
|
14
|
+
|
|
15
|
+
Works on MySQL, MariaDB and PostgreSQL. Admin UI included (Quotes,
|
|
16
|
+
editor with catalogue search, Settings). Licence activation in the admin,
|
|
17
|
+
one-click in-app updates.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn add @huloglobal/vendure-plugin-quotations
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
// vendure-config.ts
|
|
27
|
+
import { QuotationsPlugin } from '@huloglobal/vendure-plugin-quotations';
|
|
28
|
+
|
|
29
|
+
plugins: [
|
|
30
|
+
QuotationsPlugin.init({
|
|
31
|
+
publicBaseUrl: 'https://shop.example.com',
|
|
32
|
+
licenceKey: process.env.HULO_LICENCE_KEY_QUOTATIONS, // optional — or activate in the admin
|
|
33
|
+
}),
|
|
34
|
+
AdminUiPlugin.init({
|
|
35
|
+
app: compileUiExtensions({ extensions: [QuotationsPlugin.uiExtensions /* … */] }),
|
|
36
|
+
}),
|
|
37
|
+
]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
SMTP comes from `SMTP_SERVER` / `SMTP_PORT` / `SMTP_USER` / `SMTP_PASSWORD`
|
|
41
|
+
/ `SMTP_FROM` (or pass `smtp` in `init()`).
|
|
42
|
+
|
|
43
|
+
## Licensing
|
|
44
|
+
|
|
45
|
+
Every install starts a 14-day, fully-featured evaluation. Afterwards the
|
|
46
|
+
plugin drops to the free tier: drafting, pricing and previews stay free —
|
|
47
|
+
**sending, chasers and order conversion require a licence** from
|
|
48
|
+
https://huloglobal.com/vendure-plugins/quotations/.
|
package/dist/crons.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ProcessContext } from '@vendure/core';
|
|
2
|
+
import { QuotationService } from './quotation.service';
|
|
3
|
+
export declare class QuotationCrons {
|
|
4
|
+
private service;
|
|
5
|
+
private processContext;
|
|
6
|
+
constructor(service: QuotationService, processContext: ProcessContext);
|
|
7
|
+
/** Concurrency guard — duplicate same-tick invocations exit immediately
|
|
8
|
+
* (schedule explorers have been observed double-firing handlers, and
|
|
9
|
+
* overlapping runs could double-send chaser emails). */
|
|
10
|
+
private runInFlight;
|
|
11
|
+
/** Hourly: expire overdue quotes (free tier — data correctness), then
|
|
12
|
+
* send chasers/expiry reminders (premium only — they email customers). */
|
|
13
|
+
hourly(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=crons.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crons.d.ts","sourceRoot":"","sources":["../src/crons.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,cAAc,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAKvD,qBACa,cAAc;IACX,OAAO,CAAC,OAAO;IAAoB,OAAO,CAAC,cAAc;gBAAjD,OAAO,EAAE,gBAAgB,EAAU,cAAc,EAAE,cAAc;IAErF;;6DAEyD;IACzD,OAAO,CAAC,WAAW,CAAS;IAE5B;+EAC2E;IAErE,MAAM;CAiBf"}
|
package/dist/crons.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.QuotationCrons = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const schedule_1 = require("@nestjs/schedule");
|
|
15
|
+
const core_1 = require("@vendure/core");
|
|
16
|
+
const quotation_service_1 = require("./quotation.service");
|
|
17
|
+
const plugin_1 = require("./plugin");
|
|
18
|
+
const loggerCtx = 'Quotations';
|
|
19
|
+
let QuotationCrons = class QuotationCrons {
|
|
20
|
+
constructor(service, processContext) {
|
|
21
|
+
this.service = service;
|
|
22
|
+
this.processContext = processContext;
|
|
23
|
+
/** Concurrency guard — duplicate same-tick invocations exit immediately
|
|
24
|
+
* (schedule explorers have been observed double-firing handlers, and
|
|
25
|
+
* overlapping runs could double-send chaser emails). */
|
|
26
|
+
this.runInFlight = false;
|
|
27
|
+
}
|
|
28
|
+
/** Hourly: expire overdue quotes (free tier — data correctness), then
|
|
29
|
+
* send chasers/expiry reminders (premium only — they email customers). */
|
|
30
|
+
async hourly() {
|
|
31
|
+
if (this.processContext.isServer)
|
|
32
|
+
return;
|
|
33
|
+
if ((0, plugin_1.getOptions)().disableCron)
|
|
34
|
+
return;
|
|
35
|
+
if (this.runInFlight)
|
|
36
|
+
return;
|
|
37
|
+
this.runInFlight = true;
|
|
38
|
+
try {
|
|
39
|
+
await this.service.expireOverdue();
|
|
40
|
+
if (plugin_1.QuotationsPlugin.hasPremiumAccess()) {
|
|
41
|
+
const r = await this.service.runChasers();
|
|
42
|
+
if (r.chasers || r.expiryReminders) {
|
|
43
|
+
core_1.Logger.info(`sent ${r.chasers} chaser(s) + ${r.expiryReminders} expiry reminder(s)`, loggerCtx);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
this.runInFlight = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.QuotationCrons = QuotationCrons;
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, schedule_1.Cron)(schedule_1.CronExpression.EVERY_HOUR),
|
|
55
|
+
__metadata("design:type", Function),
|
|
56
|
+
__metadata("design:paramtypes", []),
|
|
57
|
+
__metadata("design:returntype", Promise)
|
|
58
|
+
], QuotationCrons.prototype, "hourly", null);
|
|
59
|
+
exports.QuotationCrons = QuotationCrons = __decorate([
|
|
60
|
+
(0, common_1.Injectable)(),
|
|
61
|
+
__metadata("design:paramtypes", [quotation_service_1.QuotationService, core_1.ProcessContext])
|
|
62
|
+
], QuotationCrons);
|
|
63
|
+
//# sourceMappingURL=crons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crons.js","sourceRoot":"","sources":["../src/crons.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAAwD;AACxD,wCAAuD;AACvD,2DAAuD;AACvD,qCAAwD;AAExD,MAAM,SAAS,GAAG,YAAY,CAAC;AAGxB,IAAM,cAAc,GAApB,MAAM,cAAc;IACvB,YAAoB,OAAyB,EAAU,cAA8B;QAAjE,YAAO,GAAP,OAAO,CAAkB;QAAU,mBAAc,GAAd,cAAc,CAAgB;QAErF;;iEAEyD;QACjD,gBAAW,GAAG,KAAK,CAAC;IAL4D,CAAC;IAOzF;+EAC2E;IAErE,AAAN,KAAK,CAAC,MAAM;QACR,IAAI,IAAI,CAAC,cAAc,CAAC,QAAQ;YAAE,OAAO;QACzC,IAAI,IAAA,mBAAU,GAAE,CAAC,WAAW;YAAE,OAAO;QACrC,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO;QAC7B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YACnC,IAAI,yBAAgB,CAAC,gBAAgB,EAAE,EAAE,CAAC;gBACtC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;gBAC1C,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;oBACjC,aAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,gBAAgB,CAAC,CAAC,eAAe,qBAAqB,EAAE,SAAS,CAAC,CAAC;gBACpG,CAAC;YACL,CAAC;QACL,CAAC;gBAAS,CAAC;YACP,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QAC7B,CAAC;IACL,CAAC;CACJ,CAAA;AA5BY,wCAAc;AAWjB;IADL,IAAA,eAAI,EAAC,yBAAc,CAAC,UAAU,CAAC;;;;4CAiB/B;yBA3BQ,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAEoB,oCAAgB,EAA0B,qBAAc;GAD5E,cAAc,CA4B1B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { QuotationsPlugin, getOptions } from './plugin';
|
|
2
|
+
export type { QuotationsInitOptions } from './plugin';
|
|
3
|
+
export { QuotationService } from './quotation.service';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export { quoteTotals, lineTotal, formatMoney } from './pricing';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACxD,YAAY,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.formatMoney = exports.lineTotal = exports.quoteTotals = exports.QuotationService = exports.getOptions = exports.QuotationsPlugin = void 0;
|
|
18
|
+
var plugin_1 = require("./plugin");
|
|
19
|
+
Object.defineProperty(exports, "QuotationsPlugin", { enumerable: true, get: function () { return plugin_1.QuotationsPlugin; } });
|
|
20
|
+
Object.defineProperty(exports, "getOptions", { enumerable: true, get: function () { return plugin_1.getOptions; } });
|
|
21
|
+
var quotation_service_1 = require("./quotation.service");
|
|
22
|
+
Object.defineProperty(exports, "QuotationService", { enumerable: true, get: function () { return quotation_service_1.QuotationService; } });
|
|
23
|
+
__exportStar(require("./types"), exports);
|
|
24
|
+
var pricing_1 = require("./pricing");
|
|
25
|
+
Object.defineProperty(exports, "quoteTotals", { enumerable: true, get: function () { return pricing_1.quoteTotals; } });
|
|
26
|
+
Object.defineProperty(exports, "lineTotal", { enumerable: true, get: function () { return pricing_1.lineTotal; } });
|
|
27
|
+
Object.defineProperty(exports, "formatMoney", { enumerable: true, get: function () { return pricing_1.formatMoney; } });
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAwD;AAA/C,0GAAA,gBAAgB,OAAA;AAAE,oGAAA,UAAU,OAAA;AAErC,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AACzB,0CAAwB;AACxB,qCAAgE;AAAvD,sGAAA,WAAW,OAAA;AAAE,oGAAA,SAAS,OAAA;AAAE,sGAAA,WAAW,OAAA"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Type } from '@vendure/core';
|
|
2
|
+
import { LicenceStatus, UpdateChecker, EvaluationState } from '@huloglobal/vendure-licence-sdk';
|
|
3
|
+
import { QuotationService } from './quotation.service';
|
|
4
|
+
import { QuotationsPluginOptions } from './types';
|
|
5
|
+
export interface QuotationsInitOptions extends QuotationsPluginOptions {
|
|
6
|
+
/** JWT licence from huloglobal.com. Without it the plugin runs in the
|
|
7
|
+
* FREE tier: draft, price and preview quotes only — sending, chasers
|
|
8
|
+
* and order conversion require a licence (or the 14-day evaluation). */
|
|
9
|
+
licenceKey?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function getOptions(): QuotationsInitOptions;
|
|
12
|
+
/**
|
|
13
|
+
* `@huloglobal/vendure-plugin-quotations`
|
|
14
|
+
*
|
|
15
|
+
* End-to-end quotation engine for Vendure: build quotes from the
|
|
16
|
+
* catalogue (or free-text lines) with per-line and quote-level
|
|
17
|
+
* discounts, VAT and validity; email the customer a branded, signed
|
|
18
|
+
* quote link; track viewed/accepted/declined with a typed-name
|
|
19
|
+
* signature; auto-expire, chase unopened quotes, remind before expiry;
|
|
20
|
+
* convert accepted quotes to draft orders at the exact quoted total.
|
|
21
|
+
*/
|
|
22
|
+
export declare class QuotationsPlugin {
|
|
23
|
+
private service;
|
|
24
|
+
private static revocation;
|
|
25
|
+
private static updateChecker;
|
|
26
|
+
private static heartbeat;
|
|
27
|
+
private static licenceStatus;
|
|
28
|
+
private static evalClient;
|
|
29
|
+
static getUpdateChecker(): UpdateChecker | null;
|
|
30
|
+
static getPackageVersion(): string;
|
|
31
|
+
static getPackageName(): string;
|
|
32
|
+
static getLicenceStatus(): LicenceStatus | null;
|
|
33
|
+
static isLicensed(): boolean;
|
|
34
|
+
static getEvalState(): EvaluationState | null;
|
|
35
|
+
static getEvalInstanceId(): string | null;
|
|
36
|
+
/** Licensed installs AND installs inside the 14-day server-anchored
|
|
37
|
+
* evaluation window get the full feature set. */
|
|
38
|
+
static hasPremiumAccess(): boolean;
|
|
39
|
+
private static licenceHost;
|
|
40
|
+
/** Verify + apply a licence key at runtime (admin-UI activation).
|
|
41
|
+
* Identical checks to boot-time verification: signature, pluginId,
|
|
42
|
+
* domain binding, expiry, revocation list. Only applied when valid. */
|
|
43
|
+
static activateRuntimeLicence(key: string): LicenceStatus;
|
|
44
|
+
/** Drop an admin-activated key at runtime: back to unlicensed state
|
|
45
|
+
* (an env/init key, if any, is re-verified by the caller flow) and
|
|
46
|
+
* the evaluation clock resumes from wherever the server says it is. */
|
|
47
|
+
static deactivateRuntimeLicence(): void;
|
|
48
|
+
constructor(service: QuotationService);
|
|
49
|
+
/** Apply an admin-activated licence key persisted in the DB. Runs
|
|
50
|
+
* after DI is up; an explicitly configured env/init key wins. */
|
|
51
|
+
onApplicationBootstrap(): Promise<void>;
|
|
52
|
+
static init(options?: QuotationsInitOptions): Type<QuotationsPlugin>;
|
|
53
|
+
static uiExtensions: {
|
|
54
|
+
extensionPath: string;
|
|
55
|
+
ngModules: {
|
|
56
|
+
type: "lazy";
|
|
57
|
+
route: string;
|
|
58
|
+
ngModuleFileName: string;
|
|
59
|
+
ngModuleName: string;
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,IAAI,EAAiB,MAAM,eAAe,CAAC;AACxE,OAAO,EAC8B,aAAa,EAAqB,aAAa,EACpB,eAAe,EAC9E,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAmBlD,MAAM,WAAW,qBAAsB,SAAQ,uBAAuB;IAClE;;6EAEyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,wBAAgB,UAAU,IAAI,qBAAqB,CAA0B;AAE7E;;;;;;;;;GASG;AACH,qBAMa,gBAAgB;IAuDb,OAAO,CAAC,OAAO;IAtD3B,OAAO,CAAC,MAAM,CAAC,UAAU,CAAkC;IAC3D,OAAO,CAAC,MAAM,CAAC,aAAa,CAA8B;IAC1D,OAAO,CAAC,MAAM,CAAC,SAAS,CAA0B;IAClD,OAAO,CAAC,MAAM,CAAC,aAAa,CAA8B;IAC1D,OAAO,CAAC,MAAM,CAAC,UAAU,CAAiC;IAE1D,MAAM,CAAC,gBAAgB;IACvB,MAAM,CAAC,iBAAiB;IACxB,MAAM,CAAC,cAAc;IACrB,MAAM,CAAC,gBAAgB;IACvB,MAAM,CAAC,UAAU,IAAI,OAAO;IAC5B,MAAM,CAAC,YAAY,IAAI,eAAe,GAAG,IAAI;IAC7C,MAAM,CAAC,iBAAiB,IAAI,MAAM,GAAG,IAAI;IACzC;sDACkD;IAClD,MAAM,CAAC,gBAAgB,IAAI,OAAO;IAMlC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAM;IAEhC;;4EAEwE;IACxE,MAAM,CAAC,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa;IAYzD;;4EAEwE;IACxE,MAAM,CAAC,wBAAwB,IAAI,IAAI;gBAanB,OAAO,EAAE,gBAAgB;IAQ7C;sEACkE;IAC5D,sBAAsB;IAU5B,MAAM,CAAC,IAAI,CAAC,OAAO,GAAE,qBAA0B,GAAG,IAAI,CAAC,gBAAgB,CAAC;IAmCxE,MAAM,CAAC,YAAY;;;;;;;;MAKjB;CACL"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var QuotationsPlugin_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.QuotationsPlugin = void 0;
|
|
14
|
+
exports.getOptions = getOptions;
|
|
15
|
+
const core_1 = require("@vendure/core");
|
|
16
|
+
const vendure_licence_sdk_1 = require("@huloglobal/vendure-licence-sdk");
|
|
17
|
+
const quotation_service_1 = require("./quotation.service");
|
|
18
|
+
const quotation_controller_1 = require("./quotation.controller");
|
|
19
|
+
const crons_1 = require("./crons");
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
21
|
+
const PKG_VERSION = require('../package.json').version;
|
|
22
|
+
const PKG_NAME = '@huloglobal/vendure-plugin-quotations';
|
|
23
|
+
const PLUGIN_ID = 'vendure-plugin-quotations';
|
|
24
|
+
const HULO_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
25
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoLmNM5UljRqe71drM6lR
|
|
26
|
+
Ba5vXrLOcV3GAHkYvnVFQSqdE0avrge/jsD7WdA6x8qQFNRugxQcxDJa2l0+C+BH
|
|
27
|
+
SbU9TimGwhA1yusHHfuz9LAXks5IQ48+2e6Pulh7iThXPJUnIKqKZUN5HhL79aaK
|
|
28
|
+
vrZKIgSfVhwE5PMPXWZ+Ij5IRf74PLIUn1Er75qhBXlDJ4vF8y8/3owURNC1XiUB
|
|
29
|
+
DGElwV/LYNoqAQei4oixe4EAxPGvFi11pgHiGuRxuWckA88y6ZHLt6urfAY9sCkj
|
|
30
|
+
kF+2dc2yS3j7lD+SYAaV5LQYYjePP1CYvxCZ7HHRKqthHopxY1hsK2tBtni3f7/c
|
|
31
|
+
UwIDAQAB
|
|
32
|
+
-----END PUBLIC KEY-----`;
|
|
33
|
+
const REVOCATION_URL = process.env.HULO_LICENCE_REVOCATION_URL || 'https://elite.charity/licence/revoked.json';
|
|
34
|
+
let cachedOptions = {};
|
|
35
|
+
function getOptions() { return cachedOptions; }
|
|
36
|
+
/**
|
|
37
|
+
* `@huloglobal/vendure-plugin-quotations`
|
|
38
|
+
*
|
|
39
|
+
* End-to-end quotation engine for Vendure: build quotes from the
|
|
40
|
+
* catalogue (or free-text lines) with per-line and quote-level
|
|
41
|
+
* discounts, VAT and validity; email the customer a branded, signed
|
|
42
|
+
* quote link; track viewed/accepted/declined with a typed-name
|
|
43
|
+
* signature; auto-expire, chase unopened quotes, remind before expiry;
|
|
44
|
+
* convert accepted quotes to draft orders at the exact quoted total.
|
|
45
|
+
*/
|
|
46
|
+
let QuotationsPlugin = QuotationsPlugin_1 = class QuotationsPlugin {
|
|
47
|
+
static getUpdateChecker() { return QuotationsPlugin_1.updateChecker; }
|
|
48
|
+
static getPackageVersion() { return PKG_VERSION; }
|
|
49
|
+
static getPackageName() { return PKG_NAME; }
|
|
50
|
+
static getLicenceStatus() { return QuotationsPlugin_1.licenceStatus; }
|
|
51
|
+
static isLicensed() { var _a; return !!((_a = QuotationsPlugin_1.licenceStatus) === null || _a === void 0 ? void 0 : _a.valid); }
|
|
52
|
+
static getEvalState() { var _a, _b; return (_b = (_a = QuotationsPlugin_1.evalClient) === null || _a === void 0 ? void 0 : _a.getState()) !== null && _b !== void 0 ? _b : null; }
|
|
53
|
+
static getEvalInstanceId() { var _a, _b; return (_b = (_a = QuotationsPlugin_1.evalClient) === null || _a === void 0 ? void 0 : _a.getInstanceId()) !== null && _b !== void 0 ? _b : null; }
|
|
54
|
+
/** Licensed installs AND installs inside the 14-day server-anchored
|
|
55
|
+
* evaluation window get the full feature set. */
|
|
56
|
+
static hasPremiumAccess() {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
if ((_a = QuotationsPlugin_1.licenceStatus) === null || _a === void 0 ? void 0 : _a.valid)
|
|
59
|
+
return true;
|
|
60
|
+
const ev = (_b = QuotationsPlugin_1.evalClient) === null || _b === void 0 ? void 0 : _b.getState();
|
|
61
|
+
return !!(ev === null || ev === void 0 ? void 0 : ev.active);
|
|
62
|
+
}
|
|
63
|
+
/** Verify + apply a licence key at runtime (admin-UI activation).
|
|
64
|
+
* Identical checks to boot-time verification: signature, pluginId,
|
|
65
|
+
* domain binding, expiry, revocation list. Only applied when valid. */
|
|
66
|
+
static activateRuntimeLicence(key) {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
const status = (0, vendure_licence_sdk_1.verifyLicence)({
|
|
69
|
+
licenceKey: key, pluginId: PLUGIN_ID, host: QuotationsPlugin_1.licenceHost,
|
|
70
|
+
publicKey: HULO_PUBLIC_KEY, revokedIds: (_a = QuotationsPlugin_1.revocation) === null || _a === void 0 ? void 0 : _a.getRevokedIds(),
|
|
71
|
+
});
|
|
72
|
+
if (status.valid) {
|
|
73
|
+
QuotationsPlugin_1.licenceStatus = status;
|
|
74
|
+
(_b = QuotationsPlugin_1.evalClient) === null || _b === void 0 ? void 0 : _b.stop();
|
|
75
|
+
}
|
|
76
|
+
return status;
|
|
77
|
+
}
|
|
78
|
+
/** Drop an admin-activated key at runtime: back to unlicensed state
|
|
79
|
+
* (an env/init key, if any, is re-verified by the caller flow) and
|
|
80
|
+
* the evaluation clock resumes from wherever the server says it is. */
|
|
81
|
+
static deactivateRuntimeLicence() {
|
|
82
|
+
QuotationsPlugin_1.licenceStatus = {
|
|
83
|
+
valid: false,
|
|
84
|
+
message: 'No licence key configured. The plugin will run in unlicensed (degraded) mode.',
|
|
85
|
+
};
|
|
86
|
+
if (QuotationsPlugin_1.evalClient) {
|
|
87
|
+
QuotationsPlugin_1.evalClient.start();
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
QuotationsPlugin_1.evalClient = new vendure_licence_sdk_1.EvaluationClient({ packageName: PKG_NAME, packageVersion: PKG_VERSION });
|
|
91
|
+
QuotationsPlugin_1.evalClient.start();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
constructor(service) {
|
|
95
|
+
var _a;
|
|
96
|
+
this.service = service;
|
|
97
|
+
this.service.setOptions(cachedOptions);
|
|
98
|
+
// Anonymous aggregates for the (opt-in) evaluation reminder emails —
|
|
99
|
+
// "you sent N invitations during your trial" converts far better
|
|
100
|
+
// than generic copy. Numbers only, never personal data.
|
|
101
|
+
(_a = QuotationsPlugin_1.evalClient) === null || _a === void 0 ? void 0 : _a.setStatsProvider(() => this.service.evalStats());
|
|
102
|
+
}
|
|
103
|
+
/** Apply an admin-activated licence key persisted in the DB. Runs
|
|
104
|
+
* after DI is up; an explicitly configured env/init key wins. */
|
|
105
|
+
async onApplicationBootstrap() {
|
|
106
|
+
if (QuotationsPlugin_1.isLicensed())
|
|
107
|
+
return;
|
|
108
|
+
const stored = await this.service.loadStoredLicenceKey();
|
|
109
|
+
if (stored) {
|
|
110
|
+
const st = QuotationsPlugin_1.activateRuntimeLicence(stored);
|
|
111
|
+
// eslint-disable-next-line no-console
|
|
112
|
+
if (st.valid)
|
|
113
|
+
console.log(`[${PKG_NAME}] licence restored from admin activation — ${st.message}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
static init(options = {}) {
|
|
117
|
+
cachedOptions = options;
|
|
118
|
+
(0, vendure_licence_sdk_1.warnIfIncompatibleVendure)({ pluginPackageName: PKG_NAME, pluginPackageVersion: PKG_VERSION, supportedRange: { min: '3.5.0', max: '4.0.0' } });
|
|
119
|
+
if (!QuotationsPlugin_1.revocation) {
|
|
120
|
+
QuotationsPlugin_1.revocation = new vendure_licence_sdk_1.RevocationChecker(REVOCATION_URL);
|
|
121
|
+
QuotationsPlugin_1.revocation.start();
|
|
122
|
+
}
|
|
123
|
+
if (!QuotationsPlugin_1.updateChecker) {
|
|
124
|
+
QuotationsPlugin_1.updateChecker = new vendure_licence_sdk_1.UpdateChecker(PKG_NAME, PKG_VERSION);
|
|
125
|
+
QuotationsPlugin_1.updateChecker.start();
|
|
126
|
+
}
|
|
127
|
+
const host = (options.publicBaseUrl || '').replace(/^https?:\/\//, '').replace(/\/.*$/, '');
|
|
128
|
+
QuotationsPlugin_1.licenceHost = host;
|
|
129
|
+
QuotationsPlugin_1.licenceStatus = (0, vendure_licence_sdk_1.verifyLicence)({
|
|
130
|
+
licenceKey: options.licenceKey, pluginId: PLUGIN_ID, host,
|
|
131
|
+
publicKey: HULO_PUBLIC_KEY, revokedIds: QuotationsPlugin_1.revocation.getRevokedIds(),
|
|
132
|
+
});
|
|
133
|
+
if (!QuotationsPlugin_1.licenceStatus.valid) {
|
|
134
|
+
// Unlicensed: start the server-anchored 14-day full-featured
|
|
135
|
+
// evaluation. All premium paths stay enabled while it runs;
|
|
136
|
+
// when it ends the plugin drops to the free tier (configure,
|
|
137
|
+
// preview + test-send only).
|
|
138
|
+
if (!QuotationsPlugin_1.evalClient) {
|
|
139
|
+
QuotationsPlugin_1.evalClient = new vendure_licence_sdk_1.EvaluationClient({ packageName: PKG_NAME, packageVersion: PKG_VERSION });
|
|
140
|
+
QuotationsPlugin_1.evalClient.start();
|
|
141
|
+
}
|
|
142
|
+
// eslint-disable-next-line no-console
|
|
143
|
+
console.warn(`[${PKG_NAME}] ${QuotationsPlugin_1.licenceStatus.message} — running the 14-day FULL-FEATURED evaluation; afterwards the plugin drops to the free tier (draft + preview only — sending, chasers and order conversion pause). Keep it: https://huloglobal.com/vendure-plugins/quotations/`);
|
|
144
|
+
}
|
|
145
|
+
if (!QuotationsPlugin_1.heartbeat) {
|
|
146
|
+
QuotationsPlugin_1.heartbeat = new vendure_licence_sdk_1.Heartbeat({
|
|
147
|
+
packageName: PKG_NAME, packageVersion: PKG_VERSION,
|
|
148
|
+
licenceKey: options.licenceKey, publicKeyFingerprint: (0, vendure_licence_sdk_1.fingerprintPublicKey)(HULO_PUBLIC_KEY),
|
|
149
|
+
});
|
|
150
|
+
QuotationsPlugin_1.heartbeat.start();
|
|
151
|
+
}
|
|
152
|
+
return QuotationsPlugin_1;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
exports.QuotationsPlugin = QuotationsPlugin;
|
|
156
|
+
QuotationsPlugin.revocation = null;
|
|
157
|
+
QuotationsPlugin.updateChecker = null;
|
|
158
|
+
QuotationsPlugin.heartbeat = null;
|
|
159
|
+
QuotationsPlugin.licenceStatus = null;
|
|
160
|
+
QuotationsPlugin.evalClient = null;
|
|
161
|
+
QuotationsPlugin.licenceHost = '';
|
|
162
|
+
QuotationsPlugin.uiExtensions = {
|
|
163
|
+
extensionPath: __dirname + '/../ui',
|
|
164
|
+
ngModules: [
|
|
165
|
+
{ type: 'lazy', route: 'quotations', ngModuleFileName: 'quotations.module.ts', ngModuleName: 'QuotationsModule' },
|
|
166
|
+
],
|
|
167
|
+
};
|
|
168
|
+
exports.QuotationsPlugin = QuotationsPlugin = QuotationsPlugin_1 = __decorate([
|
|
169
|
+
(0, core_1.VendurePlugin)({
|
|
170
|
+
imports: [core_1.PluginCommonModule],
|
|
171
|
+
controllers: [quotation_controller_1.QuotationController],
|
|
172
|
+
providers: [quotation_service_1.QuotationService, crons_1.QuotationCrons],
|
|
173
|
+
compatibility: '^3.0.0',
|
|
174
|
+
}),
|
|
175
|
+
__metadata("design:paramtypes", [quotation_service_1.QuotationService])
|
|
176
|
+
], QuotationsPlugin);
|
|
177
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAoCA,gCAA6E;AApC7E,wCAAwE;AACxE,yEAGyC;AAEzC,2DAAuD;AACvD,iEAA6D;AAC7D,mCAAyC;AAGzC,8DAA8D;AAC9D,MAAM,WAAW,GAAW,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC;AAC/D,MAAM,QAAQ,GAAG,uCAAuC,CAAC;AACzD,MAAM,SAAS,GAAG,2BAA2B,CAAC;AAE9C,MAAM,eAAe,GAAG;;;;;;;;yBAQC,CAAC;AAE1B,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,4CAA4C,CAAC;AAS/G,IAAI,aAAa,GAA0B,EAAE,CAAC;AAC9C,SAAgB,UAAU,KAA4B,OAAO,aAAa,CAAC,CAAC,CAAC;AAE7E;;;;;;;;;GASG;AAOI,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAOzB,MAAM,CAAC,gBAAgB,KAAK,OAAO,kBAAgB,CAAC,aAAa,CAAC,CAAC,CAAC;IACpE,MAAM,CAAC,iBAAiB,KAAK,OAAO,WAAW,CAAC,CAAC,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AAW,EAAE,CAAC,0CAAmB,CAAC;QAClC,SAAS,EAAE,CAAC,oCAAgB,EAAE,sBAAc,CAAC;QAC7C,aAAa,EAAE,QAAQ;KAC1B,CAAC;qCAwD+B,oCAAgB;GAvDpC,gBAAgB,CAoH5B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DiscountType, QuoteLineInput } from './types';
|
|
2
|
+
/** Round half-up to an integer (money stays in minor units throughout). */
|
|
3
|
+
export declare function roundPence(v: number): number;
|
|
4
|
+
export interface LineTotals {
|
|
5
|
+
/** after the per-line discount, ex-VAT */
|
|
6
|
+
totalPence: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function lineTotal(line: QuoteLineInput): number;
|
|
9
|
+
export interface QuoteTotals {
|
|
10
|
+
subTotalPence: number;
|
|
11
|
+
discountPence: number;
|
|
12
|
+
vatPence: number;
|
|
13
|
+
totalPence: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* subtotal (Σ discounted lines, ex-VAT)
|
|
17
|
+
* − quote-level discount (percent of subtotal, or fixed pence, clamped)
|
|
18
|
+
* + VAT on the discounted amount
|
|
19
|
+
*/
|
|
20
|
+
export declare function quoteTotals(lines: QuoteLineInput[], discountType: DiscountType, discountValue: number, vatRate: number): QuoteTotals;
|
|
21
|
+
export declare function formatMoney(pence: number, currency: string): string;
|
|
22
|
+
//# sourceMappingURL=pricing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../src/pricing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEvD,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,MAAM,WAAW,UAAU;IACvB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAKtD;AAED,MAAM,WAAW,WAAW;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACvB,KAAK,EAAE,cAAc,EAAE,EACvB,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GAChB,WAAW,CAab;AAMD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAInE"}
|
package/dist/pricing.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.roundPence = roundPence;
|
|
4
|
+
exports.lineTotal = lineTotal;
|
|
5
|
+
exports.quoteTotals = quoteTotals;
|
|
6
|
+
exports.formatMoney = formatMoney;
|
|
7
|
+
/** Round half-up to an integer (money stays in minor units throughout). */
|
|
8
|
+
function roundPence(v) {
|
|
9
|
+
return Math.round(v + Number.EPSILON);
|
|
10
|
+
}
|
|
11
|
+
function lineTotal(line) {
|
|
12
|
+
const qty = Math.max(0, Math.floor(line.quantity || 0));
|
|
13
|
+
const unit = Math.max(0, Math.floor(line.unitPricePence || 0));
|
|
14
|
+
const disc = Math.min(100, Math.max(0, Number(line.lineDiscountPercent || 0)));
|
|
15
|
+
return roundPence(qty * unit * (1 - disc / 100));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* subtotal (Σ discounted lines, ex-VAT)
|
|
19
|
+
* − quote-level discount (percent of subtotal, or fixed pence, clamped)
|
|
20
|
+
* + VAT on the discounted amount
|
|
21
|
+
*/
|
|
22
|
+
function quoteTotals(lines, discountType, discountValue, vatRate) {
|
|
23
|
+
const subTotalPence = lines.reduce((s, l) => s + lineTotal(l), 0);
|
|
24
|
+
let discountPence = 0;
|
|
25
|
+
if (discountType === 'percent') {
|
|
26
|
+
const pct = Math.min(100, Math.max(0, Number(discountValue || 0)));
|
|
27
|
+
discountPence = roundPence((subTotalPence * pct) / 100);
|
|
28
|
+
}
|
|
29
|
+
else if (discountType === 'fixed') {
|
|
30
|
+
discountPence = Math.min(subTotalPence, Math.max(0, Math.floor(discountValue || 0)));
|
|
31
|
+
}
|
|
32
|
+
const netPence = subTotalPence - discountPence;
|
|
33
|
+
const rate = Math.min(100, Math.max(0, Number(vatRate || 0)));
|
|
34
|
+
const vatPence = roundPence((netPence * rate) / 100);
|
|
35
|
+
return { subTotalPence, discountPence, vatPence, totalPence: netPence + vatPence };
|
|
36
|
+
}
|
|
37
|
+
const CURRENCY_SYMBOLS = {
|
|
38
|
+
GBP: '£', USD: '$', EUR: '€', AUD: 'A$', CAD: 'C$', NZD: 'NZ$', CHF: 'CHF ', SEK: 'kr ',
|
|
39
|
+
};
|
|
40
|
+
function formatMoney(pence, currency) {
|
|
41
|
+
var _a;
|
|
42
|
+
const sym = (_a = CURRENCY_SYMBOLS[currency]) !== null && _a !== void 0 ? _a : `${currency} `;
|
|
43
|
+
const sign = pence < 0 ? '−' : '';
|
|
44
|
+
return `${sign}${sym}${(Math.abs(pence) / 100).toFixed(2)}`;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=pricing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.js","sourceRoot":"","sources":["../src/pricing.ts"],"names":[],"mappings":";;AAGA,gCAEC;AAOD,8BAKC;AAcD,kCAkBC;AAMD,kCAIC;AAzDD,2EAA2E;AAC3E,SAAgB,UAAU,CAAC,CAAS;IAChC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC;AAOD,SAAgB,SAAS,CAAC,IAAoB;IAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,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AAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACzF,CAAC;IACD,MAAM,QAAQ,GAAG,aAAa,GAAG,aAAa,CAAC;IAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,MAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;IACrD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAAC;AACvF,CAAC;AAED,MAAM,gBAAgB,GAA2B;IAC7C,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK;CAC1F,CAAC;AAEF,SAAgB,WAAW,CAAC,KAAa,EAAE,QAAgB;;IACvD,MAAM,GAAG,GAAG,MAAA,gBAAgB,CAAC,QAAQ,CAAC,mCAAI,GAAG,QAAQ,GAAG,CAAC;IACzD,MAAM,IAAI,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAClC,OAAO,GAAG,IAAI,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Response } from 'express';
|
|
2
|
+
import { RequestContext } from '@vendure/core';
|
|
3
|
+
import { QuotationService } from './quotation.service';
|
|
4
|
+
export declare class QuotationController {
|
|
5
|
+
private service;
|
|
6
|
+
constructor(service: QuotationService);
|
|
7
|
+
publicQuote(token: string, res: Response): Promise<Response<any, Record<string, any>>>;
|
|
8
|
+
publicRespond(token: string, body: any, res: Response): Promise<Response<any, Record<string, any>>>;
|
|
9
|
+
private notFoundHtml;
|
|
10
|
+
meta(ctx: RequestContext, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
|
|
11
|
+
licenceStatus(ctx: RequestContext, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
|
|
12
|
+
/** Admin-UI licence activation: verify + persist a key at runtime. */
|
|
13
|
+
licenceActivate(ctx: RequestContext, res: Response, body: any): Promise<Response<any, Record<string, any>> | undefined>;
|
|
14
|
+
licenceDeactivate(ctx: RequestContext, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
|
|
15
|
+
/** One-click in-app update (installs a registry-verified version). */
|
|
16
|
+
updateRun(ctx: RequestContext, res: Response, body: any): Promise<Response<any, Record<string, any>> | undefined>;
|
|
17
|
+
/** Opt-in evaluation reminder lead — forwarded to the licence server. */
|
|
18
|
+
evalRemindMe(ctx: RequestContext, res: Response, body: any): Promise<Response<any, Record<string, any>> | undefined>;
|
|
19
|
+
getConfig(ctx: RequestContext, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
|
|
20
|
+
saveConfig(ctx: RequestContext, res: Response, body: any): Promise<Response<any, Record<string, any>> | undefined>;
|
|
21
|
+
list(ctx: RequestContext, res: Response, query: any): Promise<Response<any, Record<string, any>> | undefined>;
|
|
22
|
+
get(ctx: RequestContext, res: Response, id: string): Promise<Response<any, Record<string, any>> | undefined>;
|
|
23
|
+
create(ctx: RequestContext, res: Response, body: any): Promise<Response<any, Record<string, any>> | undefined>;
|
|
24
|
+
update(ctx: RequestContext, res: Response, id: string, body: any): Promise<Response<any, Record<string, any>> | undefined>;
|
|
25
|
+
remove(ctx: RequestContext, res: Response, id: string): Promise<Response<any, Record<string, any>> | undefined>;
|
|
26
|
+
cancel(ctx: RequestContext, res: Response, id: string): Promise<Response<any, Record<string, any>> | undefined>;
|
|
27
|
+
duplicate(ctx: RequestContext, res: Response, id: string, body: any): Promise<Response<any, Record<string, any>> | undefined>;
|
|
28
|
+
/** Send (or re-send) the quote email. Premium-gated. */
|
|
29
|
+
send(ctx: RequestContext, res: Response, id: string): Promise<Response<any, Record<string, any>> | undefined>;
|
|
30
|
+
/** Convert an accepted quote to a draft order. Premium-gated. */
|
|
31
|
+
convert(ctx: RequestContext, res: Response, id: string): Promise<Response<any, Record<string, any>> | undefined>;
|
|
32
|
+
stats(ctx: RequestContext, res: Response, channelId?: string): Promise<Response<any, Record<string, any>> | undefined>;
|
|
33
|
+
variants(ctx: RequestContext, res: Response, channelId?: string, q?: string): Promise<Response<any, Record<string, any>> | undefined>;
|
|
34
|
+
private actor;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=quotation.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quotation.controller.d.ts","sourceRoot":"","sources":["../src/quotation.controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAW,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAmB,cAAc,EAAE,MAAM,eAAe,CAAC;AAGhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAqBvD,qBACa,mBAAmB;IAChB,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,gBAAgB;IAIvC,WAAW,CAAiB,KAAK,EAAE,MAAM,EAAS,GAAG,EAAE,QAAQ;IAQ/D,aAAa,CAAiB,KAAK,EAAE,MAAM,EAAU,IAAI,EAAE,GAAG,EAAS,GAAG,EAAE,QAAQ;IAc1F,OAAO,CAAC,YAAY;IASd,IAAI,CAAQ,GAAG,EAAE,cAAc,EAAS,GAAG,EAAE,QAAQ;IAiBrD,aAAa,CAAQ,GAAG,EAAE,cAAc,EAAS,GAAG,EAAE,QAAQ;IAIpE,sEAAsE;IAEhE,eAAe,CAAQ,GAAG,EAAE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