@deenruv/stellate-plugin 1.0.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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ # License 1
2
+
3
+ The MIT License
4
+
5
+ Copyright (c) 2025-present Aexol
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+
13
+ # License 2
14
+
15
+ The MIT License
16
+
17
+ Copyright (c) 2018-2025 Michael Bromley
18
+
19
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # @deenruv/stellate-plugin
2
+
3
+ Integrates your Deenruv server with [Stellate](https://stellate.co/) (formerly GraphCDN) for GraphQL edge caching with automatic cache purging based on Deenruv events.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @deenruv/stellate-plugin
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ ```typescript
14
+ import { StellatePlugin, defaultPurgeRules } from '@deenruv/stellate-plugin';
15
+
16
+ const config = {
17
+ plugins: [
18
+ StellatePlugin.init({
19
+ serviceName: 'my-deenruv-service',
20
+ apiToken: process.env.STELLATE_PURGE_API_TOKEN,
21
+ devMode: !isProduction,
22
+ debugLogging: false,
23
+ purgeRules: [
24
+ ...defaultPurgeRules,
25
+ // Add custom purge rules here
26
+ ],
27
+ }),
28
+ ],
29
+ };
30
+ ```
31
+
32
+ **Options:**
33
+
34
+ | Option | Type | Default | Description |
35
+ |--------|------|---------|-------------|
36
+ | `serviceName` | `string` | *required* | Stellate service name (`<serviceName>.stellate.sh`) |
37
+ | `apiToken` | `string` | *required* | Stellate Purging API token |
38
+ | `purgeRules` | `PurgeRule[]` | *required* | Array of rules defining which events trigger cache purges |
39
+ | `defaultBufferTimeMs` | `number` | `2000` | Buffer time for batching purge requests |
40
+ | `devMode` | `boolean` | `false` | When `true`, no calls are made to the Stellate Purge API |
41
+ | `debugLogging` | `boolean` | `false` | Logs purge API calls (generates verbose debug-level logging) |
42
+
43
+ ## Features
44
+
45
+ - Automatic cache purging based on Deenruv events (Product, Collection, etc.)
46
+ - Batched and debounced purge requests for efficiency
47
+ - Built-in default purge rules for standard Deenruv entity types
48
+ - Custom `PurgeRule` support for plugin-defined entities
49
+ - Dev mode to prevent API calls during development
50
+ - `cacheIdentifier` field on `SearchResponse` for storefront cache keys
51
+
52
+ ## Admin UI
53
+
54
+ Server-only plugin. No Admin UI extensions.
55
+
56
+ ## API Extensions
57
+
58
+ The Shop API `SearchResponse` type is extended with a `cacheIdentifier` field:
59
+
60
+ ```graphql
61
+ type SearchResponseCacheIdentifier {
62
+ collectionSlug: String
63
+ }
64
+
65
+ extend type SearchResponse {
66
+ cacheIdentifier: SearchResponseCacheIdentifier
67
+ }
68
+ ```
69
+
70
+ In your storefront, include `cacheIdentifier` in search queries to enable proper cache invalidation:
71
+
72
+ ```graphql
73
+ query SearchProducts($input: SearchInput!) {
74
+ search(input: $input) {
75
+ cacheIdentifier {
76
+ collectionSlug
77
+ }
78
+ items {
79
+ # ...
80
+ }
81
+ }
82
+ }
83
+ ```
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./src/stellate-plugin";
2
+ export * from "./src/service/stellate.service";
3
+ export * from "./src/default-purge-rules";
4
+ export * from "./src/purge-rule";
5
+ export * from "./src/types";
6
+ export * from "./src/constants";
package/lib/index.js ADDED
@@ -0,0 +1,23 @@
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
+ __exportStar(require("./src/stellate-plugin"), exports);
18
+ __exportStar(require("./src/service/stellate.service"), exports);
19
+ __exportStar(require("./src/default-purge-rules"), exports);
20
+ __exportStar(require("./src/purge-rule"), exports);
21
+ __exportStar(require("./src/types"), exports);
22
+ __exportStar(require("./src/constants"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,iEAA+C;AAC/C,4DAA0C;AAC1C,mDAAiC;AACjC,8CAA4B;AAC5B,kDAAgC"}
@@ -0,0 +1 @@
1
+ export declare const shopApiExtensions: import("graphql").DocumentNode;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.shopApiExtensions = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ exports.shopApiExtensions = (0, graphql_tag_1.default) `
9
+ """
10
+ This type is here to allow us to easily purge the Stellate cache
11
+ of any search results where the collectionSlug is used. We cannot rely on
12
+ simply purging the SearchResult type, because in the case of an empty 'items'
13
+ array, Stellate cannot know that that particular query now needs to be purged.
14
+ """
15
+ type SearchResponseCacheIdentifier {
16
+ collectionSlug: String
17
+ }
18
+
19
+ extend type SearchResponse {
20
+ cacheIdentifier: SearchResponseCacheIdentifier
21
+ }
22
+ `;
23
+ //# sourceMappingURL=api-extensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-extensions.js","sourceRoot":"","sources":["../../../src/api/api-extensions.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA8B;AAEjB,QAAA,iBAAiB,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;;;CAcnC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { GraphQLResolveInfo } from "graphql/type";
2
+ export declare class SearchResponseFieldResolver {
3
+ cacheIdentifier(info: GraphQLResolveInfo): {
4
+ collectionSlug: any;
5
+ };
6
+ }
@@ -0,0 +1,35 @@
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 __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SearchResponseFieldResolver = void 0;
16
+ const graphql_1 = require("@nestjs/graphql");
17
+ let SearchResponseFieldResolver = class SearchResponseFieldResolver {
18
+ cacheIdentifier(info) {
19
+ var _a;
20
+ const collectionSlug = (_a = info.variableValues.input) === null || _a === void 0 ? void 0 : _a.collectionSlug;
21
+ return { collectionSlug };
22
+ }
23
+ };
24
+ exports.SearchResponseFieldResolver = SearchResponseFieldResolver;
25
+ __decorate([
26
+ (0, graphql_1.ResolveField)(),
27
+ __param(0, (0, graphql_1.Info)()),
28
+ __metadata("design:type", Function),
29
+ __metadata("design:paramtypes", [Object]),
30
+ __metadata("design:returntype", void 0)
31
+ ], SearchResponseFieldResolver.prototype, "cacheIdentifier", null);
32
+ exports.SearchResponseFieldResolver = SearchResponseFieldResolver = __decorate([
33
+ (0, graphql_1.Resolver)("SearchResponse")
34
+ ], SearchResponseFieldResolver);
35
+ //# sourceMappingURL=search-response.resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-response.resolver.js","sourceRoot":"","sources":["../../../src/api/search-response.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAA+D;AAIxD,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAEtC,eAAe,CAAS,IAAwB;;QAC9C,MAAM,cAAc,GAAG,MAAC,IAAI,CAAC,cAAc,CAAC,KAAa,0CAAE,cAAc,CAAC;QAC1E,OAAO,EAAE,cAAc,EAAE,CAAC;IAC5B,CAAC;CACF,CAAA;AANY,kEAA2B;AAEtC;IADC,IAAA,sBAAY,GAAE;IACE,WAAA,IAAA,cAAI,GAAE,CAAA;;;;kEAGtB;sCALU,2BAA2B;IADvC,IAAA,kBAAQ,EAAC,gBAAgB,CAAC;GACd,2BAA2B,CAMvC"}
@@ -0,0 +1,2 @@
1
+ export declare const STELLATE_PLUGIN_OPTIONS = "STELLATE_PLUGIN_OPTIONS";
2
+ export declare const loggerCtx = "StellatePlugin";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loggerCtx = exports.STELLATE_PLUGIN_OPTIONS = void 0;
4
+ exports.STELLATE_PLUGIN_OPTIONS = "STELLATE_PLUGIN_OPTIONS";
5
+ exports.loggerCtx = "StellatePlugin";
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,uBAAuB,GAAG,yBAAyB,CAAC;AACpD,QAAA,SAAS,GAAG,gBAAgB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { CollectionEvent, CollectionModificationEvent, ProductChannelEvent, ProductEvent, ProductVariantChannelEvent, ProductVariantEvent, StockMovementEvent, TaxRateEvent } from "@deenruv/core";
2
+ import { PurgeRule } from "./purge-rule";
3
+ export declare const purgeProductsOnProductEvent: PurgeRule<ProductEvent>;
4
+ export declare const purgeProductVariantsOnProductVariantEvent: PurgeRule<ProductVariantEvent>;
5
+ export declare const purgeProductsOnChannelEvent: PurgeRule<ProductChannelEvent>;
6
+ export declare const purgeProductVariantsOnChannelEvent: PurgeRule<ProductVariantChannelEvent>;
7
+ export declare const purgeProductVariantsOnStockMovementEvent: PurgeRule<StockMovementEvent>;
8
+ export declare const purgeCollectionsOnCollectionModificationEvent: PurgeRule<CollectionModificationEvent>;
9
+ export declare const purgeCollectionsOnCollectionEvent: PurgeRule<CollectionEvent>;
10
+ export declare const purgeAllOnTaxRateEvent: PurgeRule<TaxRateEvent>;
11
+ export declare const defaultPurgeRules: (PurgeRule<ProductEvent> | PurgeRule<ProductVariantEvent> | PurgeRule<ProductChannelEvent> | PurgeRule<ProductVariantChannelEvent> | PurgeRule<StockMovementEvent> | PurgeRule<CollectionModificationEvent> | PurgeRule<CollectionEvent> | PurgeRule<TaxRateEvent>)[];
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultPurgeRules = exports.purgeAllOnTaxRateEvent = exports.purgeCollectionsOnCollectionEvent = exports.purgeCollectionsOnCollectionModificationEvent = exports.purgeProductVariantsOnStockMovementEvent = exports.purgeProductVariantsOnChannelEvent = exports.purgeProductsOnChannelEvent = exports.purgeProductVariantsOnProductVariantEvent = exports.purgeProductsOnProductEvent = void 0;
4
+ const core_1 = require("@deenruv/core");
5
+ const constants_1 = require("./constants");
6
+ const purge_rule_1 = require("./purge-rule");
7
+ exports.purgeProductsOnProductEvent = new purge_rule_1.PurgeRule({
8
+ eventType: core_1.ProductEvent,
9
+ handler: ({ events, stellateService }) => {
10
+ const products = events.map((e) => e.product);
11
+ stellateService.purgeProducts(products);
12
+ stellateService.purgeSearchResults(products);
13
+ },
14
+ });
15
+ exports.purgeProductVariantsOnProductVariantEvent = new purge_rule_1.PurgeRule({
16
+ eventType: core_1.ProductVariantEvent,
17
+ handler: ({ events, stellateService }) => {
18
+ const variants = events.map((e) => e.variants).flat();
19
+ stellateService.purgeProductVariants(variants);
20
+ stellateService.purgeSearchResults(variants);
21
+ },
22
+ });
23
+ exports.purgeProductsOnChannelEvent = new purge_rule_1.PurgeRule({
24
+ eventType: core_1.ProductChannelEvent,
25
+ handler: ({ events, stellateService }) => {
26
+ const products = events.map((e) => e.product);
27
+ stellateService.purgeProducts(products);
28
+ stellateService.purgeSearchResults(products);
29
+ },
30
+ });
31
+ exports.purgeProductVariantsOnChannelEvent = new purge_rule_1.PurgeRule({
32
+ eventType: core_1.ProductVariantChannelEvent,
33
+ handler: ({ events, stellateService }) => {
34
+ const variants = events.map((e) => e.productVariant);
35
+ stellateService.purgeProductVariants(variants);
36
+ stellateService.purgeSearchResults(variants);
37
+ },
38
+ });
39
+ exports.purgeProductVariantsOnStockMovementEvent = new purge_rule_1.PurgeRule({
40
+ eventType: core_1.StockMovementEvent,
41
+ handler: ({ events, stellateService }) => {
42
+ const variants = events
43
+ .map((e) => e.stockMovements.map((m) => m.productVariant))
44
+ .flat();
45
+ stellateService.purgeProductVariants(variants);
46
+ stellateService.purgeSearchResults(variants);
47
+ },
48
+ });
49
+ exports.purgeCollectionsOnCollectionModificationEvent = new purge_rule_1.PurgeRule({
50
+ eventType: core_1.CollectionModificationEvent,
51
+ handler: ({ events, stellateService }) => {
52
+ const collectionsToPurge = events
53
+ .filter((e) => e.productVariantIds.length)
54
+ .map((e) => e.collection);
55
+ core_1.Logger.debug(`purgeCollectionsOnCollectionModificationEvent, collectionsToPurge: ${collectionsToPurge
56
+ .map((c) => c.id)
57
+ .join(", ")}`, constants_1.loggerCtx);
58
+ if (collectionsToPurge.length) {
59
+ stellateService.purgeCollections(collectionsToPurge);
60
+ stellateService.purgeSearchResponseCacheIdentifiers(collectionsToPurge);
61
+ }
62
+ },
63
+ });
64
+ exports.purgeCollectionsOnCollectionEvent = new purge_rule_1.PurgeRule({
65
+ eventType: core_1.CollectionEvent,
66
+ handler: ({ events, stellateService }) => {
67
+ const collections = events.map((e) => e.entity);
68
+ stellateService.purgeCollections(collections);
69
+ },
70
+ });
71
+ exports.purgeAllOnTaxRateEvent = new purge_rule_1.PurgeRule({
72
+ eventType: core_1.TaxRateEvent,
73
+ handler: ({ stellateService }) => {
74
+ stellateService.purgeAllOfType("ProductVariant");
75
+ stellateService.purgeAllOfType("Product");
76
+ stellateService.purgeAllOfType("SearchResponse");
77
+ },
78
+ });
79
+ exports.defaultPurgeRules = [
80
+ exports.purgeAllOnTaxRateEvent,
81
+ exports.purgeCollectionsOnCollectionEvent,
82
+ exports.purgeCollectionsOnCollectionModificationEvent,
83
+ exports.purgeProductsOnChannelEvent,
84
+ exports.purgeProductsOnProductEvent,
85
+ exports.purgeProductVariantsOnChannelEvent,
86
+ exports.purgeProductVariantsOnProductVariantEvent,
87
+ exports.purgeProductVariantsOnStockMovementEvent,
88
+ ];
89
+ //# sourceMappingURL=default-purge-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-purge-rules.js","sourceRoot":"","sources":["../../src/default-purge-rules.ts"],"names":[],"mappings":";;;AAAA,wCAUuB;AAEvB,2CAAwC;AACxC,6CAAyC;AAE5B,QAAA,2BAA2B,GAAG,IAAI,sBAAS,CAAC;IACvD,SAAS,EAAE,mBAAY;IACvB,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE,EAAE;QACvC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC9C,eAAe,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACxC,eAAe,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;CACF,CAAC,CAAC;AAEU,QAAA,yCAAyC,GAAG,IAAI,sBAAS,CAAC;IACrE,SAAS,EAAE,0BAAmB;IAC9B,OAAO,EAAE,CAAC,EAAE,MAAM,EA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,MAAM,CAAC,CAAC;QAChD,eAAe,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAChD,CAAC;CACF,CAAC,CAAC;AAEU,QAAA,sBAAsB,GAAG,IAAI,sBAAS,CAAC;IAClD,SAAS,EAAE,mBAAY;IACvB,OAAO,EAAE,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE;QAC/B,eAAe,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC;QACjD,eAAe,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QAC1C,eAAe,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC;IACnD,CAAC;CACF,CAAC,CAAC;AAEU,QAAA,iBAAiB,GAAG;IAC/B,8BAAsB;IACtB,yCAAiC;IACjC,qDAA6C;IAC7C,mCAA2B;IAC3B,mCAA2B;IAC3B,0CAAkC;IAClC,iDAAyC;IACzC,gDAAwC;CACzC,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { Type } from "@deenruv/common/lib/shared-types";
2
+ import { DeenruvEvent, Injector } from "@deenruv/core";
3
+ import { StellateService } from "./service/stellate.service";
4
+ /**
5
+ * @description
6
+ * Configures a {@link PurgeRule}.
7
+ *
8
+ * @docsCategory core plugins/StellatePlugin
9
+ * @docsPage PurgeRule
10
+ */
11
+ export interface PurgeRuleConfig<Event extends DeenruvEvent> {
12
+ /**
13
+ * @description
14
+ * Specifies which DeenruvEvent will trigger this purge rule.
15
+ */
16
+ eventType: Type<Event>;
17
+ /**
18
+ * @description
19
+ * How long to buffer events for in milliseconds before executing the handler. This allows
20
+ * us to efficiently batch calls to the Stellate Purge API.
21
+ *
22
+ * @default 5000
23
+ */
24
+ bufferTime?: number;
25
+ /**
26
+ * @description
27
+ * The function to invoke when the specified event is published. This function should use the
28
+ * {@link StellateService} instance to call the Stellate Purge API.
29
+ */
30
+ handler: (handlerArgs: {
31
+ events: Event[];
32
+ stellateService: StellateService;
33
+ injector: Injector;
34
+ }) => void | Promise<void>;
35
+ }
36
+ /**
37
+ * @description
38
+ * Defines a rule that listens for a particular DeenruvEvent and uses that to
39
+ * make calls to the [Stellate Purging API](https://docs.stellate.co/docs/purging-api) via
40
+ * the provided {@link StellateService} instance.
41
+ *
42
+ * @docsCategory core plugins/StellatePlugin
43
+ * @docsPage PurgeRule
44
+ * @docsWeight 0
45
+ */
46
+ export declare class PurgeRule<Event extends DeenruvEvent = DeenruvEvent> {
47
+ private config;
48
+ get eventType(): Type<Event>;
49
+ get bufferTimeMs(): number | undefined;
50
+ handle(handlerArgs: {
51
+ events: Event[];
52
+ stellateService: StellateService;
53
+ injector: Injector;
54
+ }): void | Promise<void>;
55
+ constructor(config: PurgeRuleConfig<Event>);
56
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PurgeRule = void 0;
4
+ /**
5
+ * @description
6
+ * Defines a rule that listens for a particular DeenruvEvent and uses that to
7
+ * make calls to the [Stellate Purging API](https://docs.stellate.co/docs/purging-api) via
8
+ * the provided {@link StellateService} instance.
9
+ *
10
+ * @docsCategory core plugins/StellatePlugin
11
+ * @docsPage PurgeRule
12
+ * @docsWeight 0
13
+ */
14
+ class PurgeRule {
15
+ get eventType() {
16
+ return this.config.eventType;
17
+ }
18
+ get bufferTimeMs() {
19
+ return this.config.bufferTime;
20
+ }
21
+ handle(handlerArgs) {
22
+ return this.config.handler(handlerArgs);
23
+ }
24
+ constructor(config) {
25
+ this.config = config;
26
+ }
27
+ }
28
+ exports.PurgeRule = PurgeRule;
29
+ //# sourceMappingURL=purge-rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"purge-rule.js","sourceRoot":"","sources":["../../src/purge-rule.ts"],"names":[],"mappings":";;;AAsCA;;;;;;;;;GASG;AACH,MAAa,SAAS;IACpB,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/B,CAAC;IACD,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;IAChC,CAAC;IACD,MAAM,CAAC,WAIN;QACC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC;IACD,YAAoB,MAA8B;QAA9B,WAAM,GAAN,MAAM,CAAwB;IAAG,CAAC;CACvD;AAfD,8BAeC"}
@@ -0,0 +1,50 @@
1
+ import { Collection, ID, Product, ProductVariant } from "@deenruv/core";
2
+ import { StellatePluginOptions } from "../types";
3
+ type CachedType = "Product" | "ProductVariant" | "Collection" | "SearchResponse" | "SearchResult" | "SearchResponseCacheIdentifier" | string;
4
+ /**
5
+ * @description
6
+ * The StellateService is used to purge the Stellate cache when certain events occur.
7
+ *
8
+ * @docsCategory core plugins/StellatePlugin
9
+ */
10
+ export declare class StellateService {
11
+ private options;
12
+ private readonly purgeApiUrl;
13
+ constructor(options: StellatePluginOptions);
14
+ /**
15
+ * @description
16
+ * Purges the cache for the given Products.
17
+ */
18
+ purgeProducts(products: Product[]): Promise<void>;
19
+ /**
20
+ * @description
21
+ * Purges the cache for the given ProductVariants.
22
+ */
23
+ purgeProductVariants(productVariants: ProductVariant[]): Promise<void>;
24
+ /**
25
+ * @description
26
+ * Purges the cache for SearchResults which contain the given Products or ProductVariants.
27
+ */
28
+ purgeSearchResults(items: Array<ProductVariant | Product>): Promise<void>;
29
+ /**
30
+ * @description
31
+ * Purges the entire cache for the given type.
32
+ */
33
+ purgeAllOfType(type: CachedType): Promise<void>;
34
+ /**
35
+ * @description
36
+ * Purges the cache for the given Collections.
37
+ */
38
+ purgeCollections(collections: Collection[]): Promise<void>;
39
+ /**
40
+ * @description
41
+ * Purges the cache of SearchResults for the given Collections based on slug.
42
+ */
43
+ purgeSearchResponseCacheIdentifiers(collections: Collection[]): Promise<void>;
44
+ /**
45
+ * @description
46
+ * Purges the cache for the given type and keys.
47
+ */
48
+ purge(type: CachedType, keys?: ID[], keyName?: string): Promise<void> | undefined;
49
+ }
50
+ export {};
@@ -0,0 +1,145 @@
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 __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.StellateService = void 0;
19
+ const common_1 = require("@nestjs/common");
20
+ const core_1 = require("@deenruv/core");
21
+ const node_fetch_1 = __importDefault(require("node-fetch"));
22
+ const constants_1 = require("../constants");
23
+ /**
24
+ * @description
25
+ * The StellateService is used to purge the Stellate cache when certain events occur.
26
+ *
27
+ * @docsCategory core plugins/StellatePlugin
28
+ */
29
+ let StellateService = class StellateService {
30
+ constructor(options) {
31
+ this.options = options;
32
+ this.purgeApiUrl = `https://admin.stellate.co/${options.serviceName}`;
33
+ }
34
+ /**
35
+ * @description
36
+ * Purges the cache for the given Products.
37
+ */
38
+ async purgeProducts(products) {
39
+ core_1.Logger.verbose(`Purging cache: Product(${products.map((p) => p.id).join(", ")})`, constants_1.loggerCtx);
40
+ await this.purge("Product", products.map((p) => p.id));
41
+ }
42
+ /**
43
+ * @description
44
+ * Purges the cache for the given ProductVariants.
45
+ */
46
+ async purgeProductVariants(productVariants) {
47
+ core_1.Logger.verbose(`Purging cache: ProductVariant(${productVariants.map((p) => p.id).join(", ")})`, constants_1.loggerCtx);
48
+ await this.purge("ProductVariant", productVariants.map((p) => p.id));
49
+ }
50
+ /**
51
+ * @description
52
+ * Purges the cache for SearchResults which contain the given Products or ProductVariants.
53
+ */
54
+ async purgeSearchResults(items) {
55
+ const productIds = items.map((item) => item instanceof core_1.Product ? item.id : item.productId);
56
+ core_1.Logger.verbose(`Purging cache: SearchResult(${productIds.join(", ")})`, constants_1.loggerCtx);
57
+ await this.purge("SearchResult", productIds, "productId");
58
+ }
59
+ /**
60
+ * @description
61
+ * Purges the entire cache for the given type.
62
+ */
63
+ async purgeAllOfType(type) {
64
+ core_1.Logger.verbose(`Purging cache: All ${type}s`, constants_1.loggerCtx);
65
+ await this.purge(type);
66
+ }
67
+ /**
68
+ * @description
69
+ * Purges the cache for the given Collections.
70
+ */
71
+ async purgeCollections(collections) {
72
+ core_1.Logger.verbose(`Purging cache: Collection(${collections.map((c) => c.id).join(", ")})`, constants_1.loggerCtx);
73
+ await this.purge("Collection", collections.map((p) => p.id));
74
+ }
75
+ /**
76
+ * @description
77
+ * Purges the cache of SearchResults for the given Collections based on slug.
78
+ */
79
+ async purgeSearchResponseCacheIdentifiers(collections) {
80
+ const slugs = collections.map((c) => { var _a, _b, _c; return (_a = c.slug) !== null && _a !== void 0 ? _a : (_c = (_b = c.translations) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.slug; });
81
+ if (slugs.length) {
82
+ core_1.Logger.verbose(`Purging cache: SearchResponseCacheIdentifier(${slugs.join(", ")})`, constants_1.loggerCtx);
83
+ await this.purge("SearchResponseCacheIdentifier", slugs);
84
+ }
85
+ }
86
+ /**
87
+ * @description
88
+ * Purges the cache for the given type and keys.
89
+ */
90
+ purge(type, keys, keyName = "id") {
91
+ var _a, _b, _c;
92
+ const payload = {
93
+ query: `
94
+ mutation PurgeType($type: String!, $keyFields: [KeyFieldInput!]) {
95
+ _purgeType(type: $type, keyFields: $keyFields)
96
+ }
97
+ `,
98
+ variables: {
99
+ type,
100
+ keyFields: keys === null || keys === void 0 ? void 0 : keys.filter((id) => !!id).map((id) => ({ name: keyName, value: id.toString() })),
101
+ },
102
+ };
103
+ if (this.options.debugLogging === true) {
104
+ const keyFieldsLength = (_b = (_a = payload.variables.keyFields) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
105
+ if (5 < keyFieldsLength) {
106
+ payload.variables.keyFields = (_c = payload.variables.keyFields) === null || _c === void 0 ? void 0 : _c.slice(0, 5);
107
+ }
108
+ core_1.Logger.debug("Purge arguments:\n" + JSON.stringify(payload.variables, null, 2), constants_1.loggerCtx);
109
+ if (5 < keyFieldsLength) {
110
+ core_1.Logger.debug(`(A further ${keyFieldsLength - 5} keyFields truncated)`, constants_1.loggerCtx);
111
+ }
112
+ }
113
+ if (this.options.devMode === true) {
114
+ // no-op
115
+ }
116
+ else {
117
+ return (0, node_fetch_1.default)(this.purgeApiUrl, {
118
+ method: "POST",
119
+ headers: {
120
+ "Content-Type": "application/json",
121
+ "stellate-token": this.options.apiToken,
122
+ },
123
+ body: JSON.stringify(payload),
124
+ timeout: 5000,
125
+ })
126
+ .then((res) => res.json())
127
+ .then((json) => {
128
+ var _a, _b, _c;
129
+ if (((_a = json.data) === null || _a === void 0 ? void 0 : _a._purgeType) !== true) {
130
+ const errors = (_b = json.errors) === null || _b === void 0 ? void 0 : _b.map((e) => e.message);
131
+ core_1.Logger.error(`Purge failed: ${(_c = errors.join(", ")) !== null && _c !== void 0 ? _c : JSON.stringify(json)}`, constants_1.loggerCtx);
132
+ }
133
+ })
134
+ .catch((err) => {
135
+ core_1.Logger.error(`Purge error: ${err.message}`, constants_1.loggerCtx);
136
+ });
137
+ }
138
+ }
139
+ };
140
+ exports.StellateService = StellateService;
141
+ exports.StellateService = StellateService = __decorate([
142
+ __param(0, (0, common_1.Inject)(constants_1.STELLATE_PLUGIN_OPTIONS)),
143
+ __metadata("design:paramtypes", [Object])
144
+ ], StellateService);
145
+ //# sourceMappingURL=stellate.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stellate.service.js","sourceRoot":"","sources":["../../../src/service/stellate.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAwC;AACxC,wCAAgF;AAChF,4DAA+B;AAE/B,4CAAkE;AAYlE;;;;;GAKG;AACH,IAAa,eAAe,GAA5B,MAAa,eAAe;IAG1B,YAC2C,OAA8B;QAA9B,YAAO,GAAP,OAAO,CAAuB;QAEvE,IAAI,CAAC,WAAW,GAAG,6BAA6B,OAAO,CAAC,WAAW,EAAE,CAAC;IACxE,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,aAAa,CAAC,QAAmB;QACrC,aAAM,CAAC,OAAO,CACZ,0BAA0B,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EACjE,qBAAS,CACV,CAAC;QACF,MAAM,IAAI,CAAC,KAAK,CACd,SAAS,EACT,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAC1B,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,oBAAoB,CAAC,eAAiC;QAC1D,aAAM,CAAC,OAAO,CACZ,iCAAiC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAC/E,qBAAS,CACV,CAAC;QACF,MAAM,IAAI,CAAC,KAAK,CACd,gBAAgB,EAChB,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACjC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,kBAAkB,CAAC,KAAsC;QAC7D,M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1,244 @@
1
+ import { OnApplicationBootstrap } from "@nestjs/common";
2
+ import { ModuleRef } from "@nestjs/core";
3
+ import { EventBus } from "@deenruv/core";
4
+ import { StellateService } from "./service/stellate.service";
5
+ import { StellatePluginOptions } from "./types";
6
+ /**
7
+ * @description
8
+ * A plugin to integrate the [Stellate](https://stellate.co/) GraphQL caching service with your Deenruv server.
9
+ * The main purpose of this plugin is to ensure that cached data gets correctly purged in
10
+ * response to events inside Deenruv. For example, changes to a Product's description should
11
+ * purge any associated record for that Product in Stellate's cache.
12
+ *
13
+ * ## Pre-requisites
14
+ *
15
+ * You will first need to [set up a free Stellate account](https://stellate.co/signup).
16
+ *
17
+ * You will also need to generate an **API token** for the Stellate Purging API. For instructions on how to generate the token,
18
+ * see the [Stellate Purging API docs](https://docs.stellate.co/docs/purging-api#authentication).
19
+ *
20
+ * ## Installation
21
+ *
22
+ * ```
23
+ * npm install \@deenruv/stellate-plugin
24
+ * ```
25
+ *
26
+ * ## Configuration
27
+ *
28
+ * The plugin is configured via the `StellatePlugin.init()` method. This method accepts an options object
29
+ * which defines the Stellate service name and API token, as well as an array of {@link PurgeRule}s which
30
+ * define how the plugin will respond to Deenruv events in order to trigger calls to the
31
+ * Stellate [Purging API](https://stellate.co/docs/graphql-edge-cache/purging-api).
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { StellatePlugin, defaultPurgeRules } from '\@deenruv/stellate-plugin';
36
+ * import { Deenruv } from '\@deenruv/core';
37
+ *
38
+ * export const config: Deenruv = {
39
+ * // ...
40
+ * plugins: [
41
+ * StellatePlugin.init({
42
+ * // The Stellate service name, i.e. `<serviceName>.stellate.sh`
43
+ * serviceName: 'my-service',
44
+ * // The API token for the Stellate Purging API. See the "pre-requisites" section above.
45
+ * apiToken: process.env.STELLATE_PURGE_API_TOKEN,
46
+ * devMode: !isProd || process.env.STELLATE_DEBUG_MODE ? true : false,
47
+ * debugLogging: process.env.STELLATE_DEBUG_MODE ? true : false,
48
+ * purgeRules: [
49
+ * ...defaultPurgeRules,
50
+ * // custom purge rules can be added here
51
+ * ],
52
+ * }),
53
+ * ],
54
+ * };
55
+ * ```
56
+ *
57
+ * In your Stellate dashboard, you can use the following configuration example as a sensible default for a
58
+ * Deenruv application:
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import { Config } from "stellate";
63
+ *
64
+ * const config: Config = {
65
+ * config: {
66
+ * name: "my-Deenruv-server",
67
+ * originUrl: "https://my-Deenruv-server.com/shop-api",
68
+ * ignoreOriginCacheControl: true,
69
+ * passThroughOnly: false,
70
+ * scopes: {
71
+ * SESSION_BOUND: "header:authorization|cookie:session",
72
+ * },
73
+ * headers: {
74
+ * "access-control-expose-headers": "Deenruv-auth-token",
75
+ * },
76
+ * rootTypeNames: {
77
+ * query: "Query",
78
+ * mutation: "Mutation",
79
+ * },
80
+ * keyFields: {
81
+ * types: {
82
+ * SearchResult: ["productId"],
83
+ * SearchResponseCacheIdentifier: ["collectionSlug"],
84
+ * },
85
+ * },
86
+ * rules: [
87
+ * {
88
+ * types: [
89
+ * "Product",
90
+ * "Collection",
91
+ * "ProductVariant",
92
+ * "SearchResponse",
93
+ * ],
94
+ * maxAge: 900,
95
+ * swr: 900,
96
+ * description: "Cache Products & Collections",
97
+ * },
98
+ * {
99
+ * types: ["Channel"],
100
+ * maxAge: 9000,
101
+ * swr: 9000,
102
+ * description: "Cache active channel",
103
+ * },
104
+ * {
105
+ * types: ["Order", "Customer", "User"],
106
+ * maxAge: 0,
107
+ * swr: 0,
108
+ * description: "Do not cache user data",
109
+ * },
110
+ * ],
111
+ * },
112
+ * };
113
+ * export default config;
114
+ * ```
115
+ *
116
+ * ## Storefront setup
117
+ *
118
+ * In your storefront, you should point your GraphQL client to the Stellate GraphQL API endpoint, which is
119
+ * `https://<service-name>.stellate.sh`.
120
+ *
121
+ * Wherever you are using the `search` query (typically in product listing & search pages), you should also add the
122
+ * `cacheIdentifier` field to the query. This will ensure that the Stellate cache is correctly purged when
123
+ * a Product or Collection is updated.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * import { graphql } from '../generated/gql';
128
+ *
129
+ * export const searchProductsDocument = graphql(`
130
+ * query SearchProducts($input: SearchInput!) {
131
+ * search(input: $input) {
132
+ * // highlight-start
133
+ * cacheIdentifier {
134
+ * collectionSlug
135
+ * }
136
+ * // highlight-end
137
+ * items {
138
+ * # ...
139
+ * }
140
+ * }
141
+ * }
142
+ * }`);
143
+ * ```
144
+ *
145
+ * ## Custom PurgeRules
146
+ *
147
+ * The configuration above only accounts for caching of some of the built-in Deenruv entity types. If you have
148
+ * custom entity types, you may well want to add them to the Stellate cache. In this case, you'll also need a way to
149
+ * purge those entities from the cache when they are updated. This is where the {@link PurgeRule} comes in.
150
+ *
151
+ * Let's imagine that you have built a simple CMS plugin for Deenruv which exposes an `Article` entity in your Shop API, and
152
+ * you have added this to your Stellate configuration:
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * import { Config } from "stellate";
157
+ *
158
+ * const config: Config = {
159
+ * config: {
160
+ * // ...
161
+ * rules: [
162
+ * // ...
163
+ * {
164
+ * types: ["Article"],
165
+ * maxAge: 900,
166
+ * swr: 900,
167
+ * description: "Cache Articles",
168
+ * },
169
+ * ],
170
+ * },
171
+ * // ...
172
+ * };
173
+ * export default config;
174
+ * ```
175
+ *
176
+ * You can then add a custom {@link PurgeRule} to the StellatePlugin configuration:
177
+ *
178
+ * @example
179
+ * ```ts
180
+ * import { StellatePlugin, defaultPurgeRules } from "\@deenruv/stellate-plugin";
181
+ * import { Deenruv } from "\@deenruv/core";
182
+ * import { ArticleEvent } from "./plugins/cms/events/article-event";
183
+ *
184
+ * export const config: Deenruv = {
185
+ * // ...
186
+ * plugins: [
187
+ * StellatePlugin.init({
188
+ * // ...
189
+ * purgeRules: [
190
+ * ...defaultPurgeRules,
191
+ * new PurgeRule({
192
+ * eventType: ArticleEvent,
193
+ * handler: async ({ events, stellateService }) => {
194
+ * const articleIds = events.map((e) => e.article.id);
195
+ * stellateService.purge("Article", articleIds);
196
+ * },
197
+ * }),
198
+ * ],
199
+ * }),
200
+ * ],
201
+ * };
202
+ * ```
203
+ *
204
+ * ## DevMode & Debug Logging
205
+ *
206
+ * In development, you can set `devMode: true`, which will prevent any calls being made to the Stellate Purging API.
207
+ *
208
+ * If you want to log the calls that _would_ be made to the Stellate Purge API when in devMode, you can set `debugLogging: true`.
209
+ * Note that debugLogging generates a lot of debug-level logging, so it is recommended to only enable this when needed.
210
+ *
211
+ * @example
212
+ * ```ts
213
+ * import { StellatePlugin, defaultPurgeRules } from '\@deenruv/stellate-plugin';
214
+ * import { Deenruv } from '\@deenruv/core';
215
+ *
216
+ * export const config: Deenruv = {
217
+ * // ...
218
+ * plugins: [
219
+ * StellatePlugin.init({
220
+ * // ...
221
+ * devMode: !process.env.PRODUCTION,
222
+ * debugLogging: process.env.STELLATE_DEBUG_MODE ? true : false,
223
+ * purgeRules: [
224
+ * ...defaultPurgeRules,
225
+ * ],
226
+ * }),
227
+ * ],
228
+ * };
229
+ * ```
230
+ *
231
+ *
232
+ * @since 2.1.5
233
+ * @docsCategory core plugins/StellatePlugin
234
+ */
235
+ export declare class StellatePlugin implements OnApplicationBootstrap {
236
+ private options;
237
+ private eventBus;
238
+ private stellateService;
239
+ private moduleRef;
240
+ static options: StellatePluginOptions;
241
+ static init(options: StellatePluginOptions): typeof StellatePlugin;
242
+ constructor(options: StellatePluginOptions, eventBus: EventBus, stellateService: StellateService, moduleRef: ModuleRef);
243
+ onApplicationBootstrap(): void;
244
+ }
@@ -0,0 +1,299 @@
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 __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.StellatePlugin = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const core_1 = require("@nestjs/core");
18
+ const core_2 = require("@deenruv/core");
19
+ const operators_1 = require("rxjs/operators");
20
+ const api_extensions_1 = require("./api/api-extensions");
21
+ const search_response_resolver_1 = require("./api/search-response.resolver");
22
+ const constants_1 = require("./constants");
23
+ const stellate_service_1 = require("./service/stellate.service");
24
+ const StellateOptionsProvider = {
25
+ provide: constants_1.STELLATE_PLUGIN_OPTIONS,
26
+ useFactory: () => StellatePlugin.options,
27
+ };
28
+ /**
29
+ * @description
30
+ * A plugin to integrate the [Stellate](https://stellate.co/) GraphQL caching service with your Deenruv server.
31
+ * The main purpose of this plugin is to ensure that cached data gets correctly purged in
32
+ * response to events inside Deenruv. For example, changes to a Product's description should
33
+ * purge any associated record for that Product in Stellate's cache.
34
+ *
35
+ * ## Pre-requisites
36
+ *
37
+ * You will first need to [set up a free Stellate account](https://stellate.co/signup).
38
+ *
39
+ * You will also need to generate an **API token** for the Stellate Purging API. For instructions on how to generate the token,
40
+ * see the [Stellate Purging API docs](https://docs.stellate.co/docs/purging-api#authentication).
41
+ *
42
+ * ## Installation
43
+ *
44
+ * ```
45
+ * npm install \@deenruv/stellate-plugin
46
+ * ```
47
+ *
48
+ * ## Configuration
49
+ *
50
+ * The plugin is configured via the `StellatePlugin.init()` method. This method accepts an options object
51
+ * which defines the Stellate service name and API token, as well as an array of {@link PurgeRule}s which
52
+ * define how the plugin will respond to Deenruv events in order to trigger calls to the
53
+ * Stellate [Purging API](https://stellate.co/docs/graphql-edge-cache/purging-api).
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { StellatePlugin, defaultPurgeRules } from '\@deenruv/stellate-plugin';
58
+ * import { Deenruv } from '\@deenruv/core';
59
+ *
60
+ * export const config: Deenruv = {
61
+ * // ...
62
+ * plugins: [
63
+ * StellatePlugin.init({
64
+ * // The Stellate service name, i.e. `<serviceName>.stellate.sh`
65
+ * serviceName: 'my-service',
66
+ * // The API token for the Stellate Purging API. See the "pre-requisites" section above.
67
+ * apiToken: process.env.STELLATE_PURGE_API_TOKEN,
68
+ * devMode: !isProd || process.env.STELLATE_DEBUG_MODE ? true : false,
69
+ * debugLogging: process.env.STELLATE_DEBUG_MODE ? true : false,
70
+ * purgeRules: [
71
+ * ...defaultPurgeRules,
72
+ * // custom purge rules can be added here
73
+ * ],
74
+ * }),
75
+ * ],
76
+ * };
77
+ * ```
78
+ *
79
+ * In your Stellate dashboard, you can use the following configuration example as a sensible default for a
80
+ * Deenruv application:
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { Config } from "stellate";
85
+ *
86
+ * const config: Config = {
87
+ * config: {
88
+ * name: "my-Deenruv-server",
89
+ * originUrl: "https://my-Deenruv-server.com/shop-api",
90
+ * ignoreOriginCacheControl: true,
91
+ * passThroughOnly: false,
92
+ * scopes: {
93
+ * SESSION_BOUND: "header:authorization|cookie:session",
94
+ * },
95
+ * headers: {
96
+ * "access-control-expose-headers": "Deenruv-auth-token",
97
+ * },
98
+ * rootTypeNames: {
99
+ * query: "Query",
100
+ * mutation: "Mutation",
101
+ * },
102
+ * keyFields: {
103
+ * types: {
104
+ * SearchResult: ["productId"],
105
+ * SearchResponseCacheIdentifier: ["collectionSlug"],
106
+ * },
107
+ * },
108
+ * rules: [
109
+ * {
110
+ * types: [
111
+ * "Product",
112
+ * "Collection",
113
+ * "ProductVariant",
114
+ * "SearchResponse",
115
+ * ],
116
+ * maxAge: 900,
117
+ * swr: 900,
118
+ * description: "Cache Products & Collections",
119
+ * },
120
+ * {
121
+ * types: ["Channel"],
122
+ * maxAge: 9000,
123
+ * swr: 9000,
124
+ * description: "Cache active channel",
125
+ * },
126
+ * {
127
+ * types: ["Order", "Customer", "User"],
128
+ * maxAge: 0,
129
+ * swr: 0,
130
+ * description: "Do not cache user data",
131
+ * },
132
+ * ],
133
+ * },
134
+ * };
135
+ * export default config;
136
+ * ```
137
+ *
138
+ * ## Storefront setup
139
+ *
140
+ * In your storefront, you should point your GraphQL client to the Stellate GraphQL API endpoint, which is
141
+ * `https://<service-name>.stellate.sh`.
142
+ *
143
+ * Wherever you are using the `search` query (typically in product listing & search pages), you should also add the
144
+ * `cacheIdentifier` field to the query. This will ensure that the Stellate cache is correctly purged when
145
+ * a Product or Collection is updated.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * import { graphql } from '../generated/gql';
150
+ *
151
+ * export const searchProductsDocument = graphql(`
152
+ * query SearchProducts($input: SearchInput!) {
153
+ * search(input: $input) {
154
+ * // highlight-start
155
+ * cacheIdentifier {
156
+ * collectionSlug
157
+ * }
158
+ * // highlight-end
159
+ * items {
160
+ * # ...
161
+ * }
162
+ * }
163
+ * }
164
+ * }`);
165
+ * ```
166
+ *
167
+ * ## Custom PurgeRules
168
+ *
169
+ * The configuration above only accounts for caching of some of the built-in Deenruv entity types. If you have
170
+ * custom entity types, you may well want to add them to the Stellate cache. In this case, you'll also need a way to
171
+ * purge those entities from the cache when they are updated. This is where the {@link PurgeRule} comes in.
172
+ *
173
+ * Let's imagine that you have built a simple CMS plugin for Deenruv which exposes an `Article` entity in your Shop API, and
174
+ * you have added this to your Stellate configuration:
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * import { Config } from "stellate";
179
+ *
180
+ * const config: Config = {
181
+ * config: {
182
+ * // ...
183
+ * rules: [
184
+ * // ...
185
+ * {
186
+ * types: ["Article"],
187
+ * maxAge: 900,
188
+ * swr: 900,
189
+ * description: "Cache Articles",
190
+ * },
191
+ * ],
192
+ * },
193
+ * // ...
194
+ * };
195
+ * export default config;
196
+ * ```
197
+ *
198
+ * You can then add a custom {@link PurgeRule} to the StellatePlugin configuration:
199
+ *
200
+ * @example
201
+ * ```ts
202
+ * import { StellatePlugin, defaultPurgeRules } from "\@deenruv/stellate-plugin";
203
+ * import { Deenruv } from "\@deenruv/core";
204
+ * import { ArticleEvent } from "./plugins/cms/events/article-event";
205
+ *
206
+ * export const config: Deenruv = {
207
+ * // ...
208
+ * plugins: [
209
+ * StellatePlugin.init({
210
+ * // ...
211
+ * purgeRules: [
212
+ * ...defaultPurgeRules,
213
+ * new PurgeRule({
214
+ * eventType: ArticleEvent,
215
+ * handler: async ({ events, stellateService }) => {
216
+ * const articleIds = events.map((e) => e.article.id);
217
+ * stellateService.purge("Article", articleIds);
218
+ * },
219
+ * }),
220
+ * ],
221
+ * }),
222
+ * ],
223
+ * };
224
+ * ```
225
+ *
226
+ * ## DevMode & Debug Logging
227
+ *
228
+ * In development, you can set `devMode: true`, which will prevent any calls being made to the Stellate Purging API.
229
+ *
230
+ * If you want to log the calls that _would_ be made to the Stellate Purge API when in devMode, you can set `debugLogging: true`.
231
+ * Note that debugLogging generates a lot of debug-level logging, so it is recommended to only enable this when needed.
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * import { StellatePlugin, defaultPurgeRules } from '\@deenruv/stellate-plugin';
236
+ * import { Deenruv } from '\@deenruv/core';
237
+ *
238
+ * export const config: Deenruv = {
239
+ * // ...
240
+ * plugins: [
241
+ * StellatePlugin.init({
242
+ * // ...
243
+ * devMode: !process.env.PRODUCTION,
244
+ * debugLogging: process.env.STELLATE_DEBUG_MODE ? true : false,
245
+ * purgeRules: [
246
+ * ...defaultPurgeRules,
247
+ * ],
248
+ * }),
249
+ * ],
250
+ * };
251
+ * ```
252
+ *
253
+ *
254
+ * @since 2.1.5
255
+ * @docsCategory core plugins/StellatePlugin
256
+ */
257
+ let StellatePlugin = class StellatePlugin {
258
+ static init(options) {
259
+ this.options = options;
260
+ return this;
261
+ }
262
+ constructor(options, eventBus, stellateService, moduleRef) {
263
+ this.options = options;
264
+ this.eventBus = eventBus;
265
+ this.stellateService = stellateService;
266
+ this.moduleRef = moduleRef;
267
+ }
268
+ onApplicationBootstrap() {
269
+ var _a, _b, _c;
270
+ const injector = new core_2.Injector(this.moduleRef);
271
+ for (const purgeRule of (_a = this.options.purgeRules) !== null && _a !== void 0 ? _a : []) {
272
+ const source$ = this.eventBus.ofType(purgeRule.eventType);
273
+ source$
274
+ .pipe((0, operators_1.buffer)(source$.pipe((0, operators_1.debounceTime)((_c = (_b = purgeRule.bufferTimeMs) !== null && _b !== void 0 ? _b : this.options.defaultBufferTimeMs) !== null && _c !== void 0 ? _c : 2000))))
275
+ .subscribe((events) => purgeRule.handle({
276
+ events,
277
+ injector,
278
+ stellateService: this.stellateService,
279
+ }));
280
+ }
281
+ }
282
+ };
283
+ exports.StellatePlugin = StellatePlugin;
284
+ exports.StellatePlugin = StellatePlugin = __decorate([
285
+ (0, core_2.DeenruvPlugin)({
286
+ imports: [core_2.PluginCommonModule],
287
+ providers: [StellateOptionsProvider, stellate_service_1.StellateService],
288
+ shopApiExtensions: {
289
+ schema: api_extensions_1.shopApiExtensions,
290
+ resolvers: [search_response_resolver_1.SearchResponseFieldResolver],
291
+ },
292
+ compatibility: "^0.0.0",
293
+ }),
294
+ __param(0, (0, common_1.Inject)(constants_1.STELLATE_PLUGIN_OPTIONS)),
295
+ __metadata("design:paramtypes", [Object, core_2.EventBus,
296
+ stellate_service_1.StellateService,
297
+ core_1.ModuleRef])
298
+ ], StellatePlugin);
299
+ //# sourceMappingURL=stellate-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stellate-plugin.js","sourceRoot":"","sources":["../../src/stellate-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAgE;AAChE,uCAAyC;AACzC,wCAKuB;AACvB,8CAAsD;AAEtD,yDAAyD;AACzD,6EAA6E;AAC7E,2CAAsD;AACtD,iEAA6D;AAG7D,MAAM,uBA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AAC,MAAM,EAAE,EAAE,CACpB,SAAS,CAAC,MAAM,CAAC;gBACf,MAAM;gBACN,QAAQ;gBACR,eAAe,EAAE,IAAI,CAAC,eAAe;aACtC,CAAC,CACH,CAAC;QACN,CAAC;IACH,CAAC;CACF,CAAA;AAzCY,wCAAc;yBAAd,cAAc;IAT1B,IAAA,oBAAa,EAAC;QACb,OAAO,EAAE,CAAC,yBAAkB,CAAC;QAC7B,SAAS,EAAE,CAAC,uBAAuB,EAAE,kCAAe,CAAC;QACrD,iBAAiB,EAAE;YACjB,MAAM,EAAE,kCAAiB;YACzB,SAAS,EAAE,CAAC,sDAA2B,CAAC;SACzC;QACD,aAAa,EAAE,QAAQ;KACxB,CAAC;IAUG,WAAA,IAAA,eAAM,EAAC,mCAAuB,CAAC,CAAA;6CACd,eAAQ;QACD,kCAAe;QACrB,gBAAS;GAZnB,cAAc,CAyC1B"}
@@ -0,0 +1,51 @@
1
+ import { PurgeRule } from "./purge-rule";
2
+ /**
3
+ * @description
4
+ * Configuration options for the StellatePlugin.
5
+ *
6
+ * @docsCategory core plugins/StellatePlugin
7
+ */
8
+ export interface StellatePluginOptions {
9
+ /**
10
+ * @description
11
+ * The Stellate service name, i.e. `<service-name>.stellate.sh`
12
+ */
13
+ serviceName: string;
14
+ /**
15
+ * @description
16
+ * The Stellate Purging API token. For instructions on how to generate the token,
17
+ * see the [Stellate docs](https://docs.stellate.co/docs/purging-api#authentication)
18
+ */
19
+ apiToken: string;
20
+ /**
21
+ * @description
22
+ * An array of {@link PurgeRule} instances which are used to define how the plugin will
23
+ * respond to Deenruv events in order to trigger calls to the Stellate Purging API.
24
+ */
25
+ purgeRules: PurgeRule[];
26
+ /**
27
+ * @description
28
+ * When events are published, the PurgeRules will buffer those events in order to efficiently
29
+ * batch requests to the Stellate Purging API. You may wish to change the default, e.g. if you are
30
+ * running in a serverless environment and cannot introduce pauses after the main request has completed.
31
+ *
32
+ * @default 2000
33
+ */
34
+ defaultBufferTimeMs?: number;
35
+ /**
36
+ * @description
37
+ * When set to `true`, calls will not be made to the Stellate Purge API.
38
+ *
39
+ * @default false
40
+ */
41
+ devMode?: boolean;
42
+ /**
43
+ * @description
44
+ * If set to true, the plugin will log the calls that would be made
45
+ * to the Stellate Purge API. Note, this generates a
46
+ * lot of debug-level logging.
47
+ *
48
+ * @default false
49
+ */
50
+ debugLogging?: boolean;
51
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@deenruv/stellate-plugin",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib/**/*"
9
+ ],
10
+ "homepage": "https://deenruv.com/",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "dependencies": {
15
+ "@nestjs/common": "^10.3.10",
16
+ "@nestjs/core": "^10.3.10",
17
+ "@nestjs/graphql": "^12.2.0",
18
+ "graphql-tag": "^2.12.6",
19
+ "node-fetch": "^2.7.0"
20
+ },
21
+ "peerDependencies": {
22
+ "@deenruv/core": "^0.1.0",
23
+ "rxjs": "7.8.1"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node-fetch": "^2.6.11",
27
+ "rimraf": "^5.0.5",
28
+ "rxjs": "7.8.1",
29
+ "@deenruv/core": "^1.0.0",
30
+ "@deenruv/common": "^1.0.0"
31
+ },
32
+ "scripts": {
33
+ "watch": "tsc -p ./tsconfig.build.json --watch",
34
+ "build": "rimraf lib && tsc -p ./tsconfig.build.json",
35
+ "lint": "eslint .",
36
+ "lint:fix": "eslint --fix ."
37
+ }
38
+ }