@tryghost/cache-purge 0.3.7 → 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/README.md +20 -0
- package/cjs/index.js +39 -0
- package/es/index.js +29 -0
- package/package.json +30 -8
- package/src/index.ts +38 -0
- package/types/index.d.ts +17 -0
- package/types/index.d.ts.map +1 -0
- package/lib/cache-purge.js +0 -13
package/README.md
CHANGED
|
@@ -14,6 +14,26 @@ or
|
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
|
+
The package ships TypeScript types and both ESM and CommonJS builds.
|
|
18
|
+
|
|
19
|
+
### ESM / TypeScript
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import cachePurge from '@tryghost/cache-purge';
|
|
23
|
+
|
|
24
|
+
await cachePurge(hmacKey, 'cache.example.com', {
|
|
25
|
+
domain: 'example.com',
|
|
26
|
+
type: 'site',
|
|
27
|
+
source: 'admin',
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The module's single export is a callable function (it uses `export =`), so the
|
|
32
|
+
default import above requires `esModuleInterop` (or `allowSyntheticDefaultImports`).
|
|
33
|
+
Without those flags, import it with `import cachePurge = require('@tryghost/cache-purge')`.
|
|
34
|
+
|
|
35
|
+
### CommonJS
|
|
36
|
+
|
|
17
37
|
```js
|
|
18
38
|
const cachePurge = require('@tryghost/cache-purge');
|
|
19
39
|
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var signedRequest = __toESM(require("@tryghost/signed-request"));
|
|
25
|
+
function exec(hmac, server, options) {
|
|
26
|
+
if (!options.protocol) {
|
|
27
|
+
options.protocol = "https://";
|
|
28
|
+
}
|
|
29
|
+
const useId = Boolean(options.id);
|
|
30
|
+
const identifier = useId ? options.id : options.domain;
|
|
31
|
+
if (!identifier) {
|
|
32
|
+
throw new Error('A "domain" or "id" is required to purge the cache');
|
|
33
|
+
}
|
|
34
|
+
const target = `${useId ? "id" : "domain"}=${encodeURIComponent(identifier)}`;
|
|
35
|
+
const path = `/cache?${target}&type=${encodeURIComponent(options.type)}`;
|
|
36
|
+
return signedRequest.exec(hmac, server, path, options);
|
|
37
|
+
}
|
|
38
|
+
exec.exec = exec;
|
|
39
|
+
module.exports = exec;
|
package/es/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
+
try {
|
|
4
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
5
|
+
} catch (e) {
|
|
6
|
+
throw mod = 0, e;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
import * as signedRequest from "@tryghost/signed-request";
|
|
10
|
+
var require_index = __commonJS({
|
|
11
|
+
"src/index.ts"(exports, module) {
|
|
12
|
+
function exec(hmac, server, options) {
|
|
13
|
+
if (!options.protocol) {
|
|
14
|
+
options.protocol = "https://";
|
|
15
|
+
}
|
|
16
|
+
const useId = Boolean(options.id);
|
|
17
|
+
const identifier = useId ? options.id : options.domain;
|
|
18
|
+
if (!identifier) {
|
|
19
|
+
throw new Error('A "domain" or "id" is required to purge the cache');
|
|
20
|
+
}
|
|
21
|
+
const target = `${useId ? "id" : "domain"}=${encodeURIComponent(identifier)}`;
|
|
22
|
+
const path = `/cache?${target}&type=${encodeURIComponent(options.type)}`;
|
|
23
|
+
return signedRequest.exec(hmac, server, path, options);
|
|
24
|
+
}
|
|
25
|
+
exec.exec = exec;
|
|
26
|
+
module.exports = exec;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
export default require_index();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/cache-purge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"repository": {
|
|
@@ -8,28 +8,50 @@
|
|
|
8
8
|
"url": "ssh://git@github.com/TryGhost/Pro-Packages",
|
|
9
9
|
"directory": "packages/cache-purge"
|
|
10
10
|
},
|
|
11
|
+
"source": "src/index.ts",
|
|
11
12
|
"files": [
|
|
12
|
-
"
|
|
13
|
-
"
|
|
13
|
+
"cjs",
|
|
14
|
+
"es",
|
|
15
|
+
"types",
|
|
16
|
+
"src"
|
|
14
17
|
],
|
|
15
|
-
"main": "
|
|
18
|
+
"main": "cjs/index.js",
|
|
19
|
+
"module": "es/index.js",
|
|
20
|
+
"types": "types/index.d.ts",
|
|
16
21
|
"publishConfig": {
|
|
17
22
|
"access": "public"
|
|
18
23
|
},
|
|
19
24
|
"dependencies": {
|
|
20
|
-
"@tryghost/signed-request": "^0.
|
|
25
|
+
"@tryghost/signed-request": "^1.0.0"
|
|
21
26
|
},
|
|
22
27
|
"devDependencies": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
28
|
+
"@types/node": "25.9.4",
|
|
29
|
+
"esbuild": "0.28.1",
|
|
30
|
+
"typescript": "6.0.3"
|
|
25
31
|
},
|
|
26
32
|
"engines": {
|
|
27
33
|
"node": ">=20.20.0"
|
|
28
34
|
},
|
|
35
|
+
"nx": {
|
|
36
|
+
"targets": {
|
|
37
|
+
"build": {
|
|
38
|
+
"outputs": [
|
|
39
|
+
"{projectRoot}/cjs",
|
|
40
|
+
"{projectRoot}/es",
|
|
41
|
+
"{projectRoot}/types"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
29
46
|
"scripts": {
|
|
30
47
|
"dev": "echo \"Implement me!\"",
|
|
48
|
+
"pretest": "NODE_ENV=production pnpm run build",
|
|
49
|
+
"build": "pnpm run build:cjs && pnpm run build:es && pnpm run build:types",
|
|
50
|
+
"build:cjs": "esbuild src/index.ts --target=es2020 --outdir=cjs --format=cjs",
|
|
51
|
+
"build:es": "esbuild src/index.ts --target=es2020 --outdir=es --format=esm",
|
|
52
|
+
"build:types": "tsc --emitDeclarationOnly --declaration --declarationMap --outDir types",
|
|
31
53
|
"test": "NODE_ENV=testing vitest run --coverage",
|
|
32
54
|
"lint": "oxlint -c ../../.oxlintrc.json .",
|
|
33
|
-
"posttest": "pnpm lint"
|
|
55
|
+
"posttest": "pnpm run lint"
|
|
34
56
|
}
|
|
35
57
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as signedRequest from '@tryghost/signed-request';
|
|
2
|
+
import type { Response, SignedRequestOptions } from '@tryghost/signed-request';
|
|
3
|
+
|
|
4
|
+
interface CachePurgeOptions extends Omit<SignedRequestOptions, 'protocol'> {
|
|
5
|
+
/** Request protocol. Defaults to `https://` when omitted. */
|
|
6
|
+
protocol?: string;
|
|
7
|
+
/** Cache type to purge, e.g. `all`, `page`, or `site`. */
|
|
8
|
+
type: string;
|
|
9
|
+
/** Site id to purge. Takes precedence over `domain` when set. */
|
|
10
|
+
id?: string;
|
|
11
|
+
/** Domain to purge. Used when no `id` is provided. */
|
|
12
|
+
domain?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function exec<T = unknown>(
|
|
16
|
+
hmac: string,
|
|
17
|
+
server: string,
|
|
18
|
+
options: CachePurgeOptions,
|
|
19
|
+
): Promise<Response<T>> {
|
|
20
|
+
if (!options.protocol) {
|
|
21
|
+
options.protocol = 'https://';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const useId = Boolean(options.id);
|
|
25
|
+
const identifier = useId ? options.id : options.domain;
|
|
26
|
+
if (!identifier) {
|
|
27
|
+
throw new Error('A "domain" or "id" is required to purge the cache');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const target = `${useId ? 'id' : 'domain'}=${encodeURIComponent(identifier)}`;
|
|
31
|
+
const path = `/cache?${target}&type=${encodeURIComponent(options.type)}`;
|
|
32
|
+
|
|
33
|
+
return signedRequest.exec<T>(hmac, server, path, options);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exec.exec = exec;
|
|
37
|
+
|
|
38
|
+
export = exec;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Response, SignedRequestOptions } from '@tryghost/signed-request';
|
|
2
|
+
interface CachePurgeOptions extends Omit<SignedRequestOptions, 'protocol'> {
|
|
3
|
+
/** Request protocol. Defaults to `https://` when omitted. */
|
|
4
|
+
protocol?: string;
|
|
5
|
+
/** Cache type to purge, e.g. `all`, `page`, or `site`. */
|
|
6
|
+
type: string;
|
|
7
|
+
/** Site id to purge. Takes precedence over `domain` when set. */
|
|
8
|
+
id?: string;
|
|
9
|
+
/** Domain to purge. Used when no `id` is provided. */
|
|
10
|
+
domain?: string;
|
|
11
|
+
}
|
|
12
|
+
declare function exec<T = unknown>(hmac: string, server: string, options: CachePurgeOptions): Promise<Response<T>>;
|
|
13
|
+
declare namespace exec {
|
|
14
|
+
var exec: typeof import(".");
|
|
15
|
+
}
|
|
16
|
+
export = exec;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAE/E,UAAU,iBAAkB,SAAQ,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC;IACtE,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,iBAAS,IAAI,CAAC,CAAC,GAAG,OAAO,EACrB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,iBAAiB,GAC3B,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAetB;kBAnBQ,IAAI;;;AAuBb,SAAS,IAAI,CAAC"}
|
package/lib/cache-purge.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const signedRequest = require('@tryghost/signed-request');
|
|
2
|
-
const exec = function (hmac, server, options) {
|
|
3
|
-
if (!options.protocol) {
|
|
4
|
-
options.protocol = 'https://';
|
|
5
|
-
}
|
|
6
|
-
let path = '/cache?';
|
|
7
|
-
path += options.id ? 'id=' + options.id : 'domain=' + options.domain;
|
|
8
|
-
path += '&type=' + options.type;
|
|
9
|
-
|
|
10
|
-
return signedRequest.exec(hmac, server, path, options);
|
|
11
|
-
};
|
|
12
|
-
module.exports = exec;
|
|
13
|
-
module.exports.exec = exec;
|