@tryghost/adapter-base-scheduling 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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013-2026 Ghost Foundation
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @tryghost/adapter-base-scheduling
2
+
3
+ The adapter-base-scheduling package for Ghost.
4
+
5
+ ## Develop
6
+
7
+ This is a workspace package in the Ghost monorepo. From the repo root:
8
+
9
+ ```bash
10
+ pnpm --filter @tryghost/adapter-base-scheduling build # compile to build/ with tsc (ESM)
11
+ pnpm --filter @tryghost/adapter-base-scheduling test # type-check + unit tests
12
+ pnpm --filter @tryghost/adapter-base-scheduling dev # rebuild on change
13
+ ```
14
+
15
+ In-monorepo consumers resolve this package via the `source` export condition
16
+ (raw `src/*.ts`, no build needed in dev/test). Production and any published
17
+ tarball use the compiled `build/` output.
18
+
19
+ This package is ESM-only and compiled with `tsc` (`module: nodenext`). Relative
20
+ imports in `src/` must carry an explicit extension; write the real `.ts` one —
21
+ `import {x} from './x.ts'` — and `tsc` rewrites it to `.js` on emit
22
+ (`rewriteRelativeImportExtensions`).
23
+
24
+ `ghost/core` is CommonJS but consumes this package via `require()`, which works
25
+ on Ghost's Node version (22.13+/24) through Node's `require(esm)` support. That
26
+ support has one hard constraint: **no top-level `await`** anywhere in this
27
+ package's module graph — it makes the graph async and `require()` of it throws
28
+ `ERR_REQUIRE_ASYNC_MODULE`. Keep module-level initialization synchronous. (An
29
+ ESLint rule enforces this.)
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Shape of a job the scheduler adapter queues. Time is a unix timestamp;
3
+ * url carries a JWT-signed admin token; extra forwards through to the
4
+ * HTTP callback the adapter fires.
5
+ */
6
+ export interface SchedulerJob {
7
+ time: number;
8
+ url: string;
9
+ extra: {
10
+ httpMethod: string;
11
+ oldTime?: number | null;
12
+ };
13
+ }
14
+ /**
15
+ * Options passed to `rescheduleAll` by the adapter when it calls the method on
16
+ * each registered rescheduler. The previous key is provided so that the
17
+ * rescheduler can unschedule any jobs that were queued under the old key.
18
+ */
19
+ export interface RescheduleOpts {
20
+ previousKey?: {
21
+ id: string;
22
+ secret: string;
23
+ };
24
+ }
25
+ /**
26
+ * Implemented by scheduler-using subsystems (post-scheduling, automations,
27
+ * gift reminders). The adapter calls `rescheduleAll` on every registered
28
+ * rescheduler when something requires the queue to be rebuilt — currently
29
+ * after an internal API key rotation.
30
+ */
31
+ export interface Rescheduler {
32
+ rescheduleAll(opts?: RescheduleOpts): Promise<void>;
33
+ }
34
+ /**
35
+ * The contract Ghost expects of any concrete scheduling adapter. Adapters
36
+ * that extend `SchedulingBase` inherit `register` and `rescheduleAll` for
37
+ * free; the three runtime methods (`schedule`, `unschedule`, `run`) are
38
+ * the ones each adapter implementation must provide.
39
+ */
40
+ export interface SchedulerAdapter {
41
+ run(): void | Promise<void>;
42
+ schedule(job: SchedulerJob): void | Promise<void>;
43
+ unschedule(job: SchedulerJob, opts?: {
44
+ bootstrap?: boolean;
45
+ }): void | Promise<void>;
46
+ register(rescheduler: Rescheduler): void;
47
+ }
48
+ export declare abstract class SchedulingBase implements SchedulerAdapter {
49
+ #private;
50
+ readonly requiredFns: readonly ['run', 'schedule', 'unschedule'];
51
+ constructor();
52
+ register(rescheduler: Rescheduler): void;
53
+ /**
54
+ * Ask every registered rescheduler to rebuild its queue under the current
55
+ * key. Best-effort: a failure in one doesn't block the others.
56
+ */
57
+ rescheduleAll(opts?: RescheduleOpts): Promise<PromiseSettledResult<void>[]>;
58
+ abstract run(): void | Promise<void>;
59
+ abstract schedule(job: SchedulerJob): void | Promise<void>;
60
+ abstract unschedule(job: SchedulerJob, opts?: {
61
+ bootstrap?: boolean;
62
+ }): void | Promise<void>;
63
+ }
64
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE;QACH,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC3B,CAAC;CACL;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC3B,WAAW,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,CAAC;CAC/C;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IACxB,aAAa,CAAC,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvD;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC7B,GAAG,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClF,QAAQ,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;CAC5C;AAED,8BAAsB,cAAe,YAAW,gBAAgB;;IAC5D,SAAiB,WAAW,EAAE,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;IAIzE,cAKC;IAED,QAAQ,CAAC,WAAW,EAAE,WAAW,QAEhC;IAED;;;OAGG;IACG,aAAa,CAAC,IAAI,CAAC,EAAE,cAAc,yCAiBxC;IAED,QAAQ,CAAC,GAAG,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1D,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7F"}
package/build/base.js ADDED
@@ -0,0 +1,32 @@
1
+ import logging from '@tryghost/logging';
2
+ export class SchedulingBase {
3
+ #reschedulers = new Set();
4
+ constructor() {
5
+ Object.defineProperty(this, 'requiredFns', {
6
+ value: Object.freeze(['run', 'schedule', 'unschedule']),
7
+ writable: false,
8
+ });
9
+ }
10
+ register(rescheduler) {
11
+ this.#reschedulers.add(rescheduler);
12
+ }
13
+ /**
14
+ * Ask every registered rescheduler to rebuild its queue under the current
15
+ * key. Best-effort: a failure in one doesn't block the others.
16
+ */
17
+ async rescheduleAll(opts) {
18
+ const reschedulers = Array.from(this.#reschedulers);
19
+ const results = await Promise.allSettled(reschedulers.map(r => r.rescheduleAll(opts)));
20
+ results.forEach((result, i) => {
21
+ if (result.status === 'rejected') {
22
+ logging.error({
23
+ event: { name: 'scheduler.reschedule_all.failed' },
24
+ err: result.reason,
25
+ rescheduler: reschedulers[i].constructor?.name || 'unknown'
26
+ }, 'Rescheduler failed');
27
+ }
28
+ });
29
+ return results;
30
+ }
31
+ }
32
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAiDxC,MAAM,OAAgB,cAAc;IAGhC,aAAa,GAAG,IAAI,GAAG,EAAe,CAAC;IAEvC;QACI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE;YACvC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;YACvD,QAAQ,EAAE,KAAK;SAClB,CAAC,CAAA;IACN,CAAC;IAED,QAAQ,CAAC,WAAwB;QAC7B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,aAAa,CAAC,IAAqB;QACrC,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,CACpC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAC/C,CAAC;QAEF,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC1B,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;gBAC/B,OAAO,CAAC,KAAK,CAAC;oBACV,KAAK,EAAE,EAAC,IAAI,EAAE,iCAAiC,EAAC;oBAChD,GAAG,EAAE,MAAM,CAAC,MAAM;oBAClB,WAAW,EAAE,YAAY,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,IAAI,IAAI,SAAS;iBAC/D,EAAE,oBAAoB,CAAC,CAAC;YAC7B,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACnB,CAAC;CAKJ"}
@@ -0,0 +1,2 @@
1
+ export * from "./base.ts";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
package/build/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./base.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@tryghost/adapter-base-scheduling",
3
+ "version": "0.1.0",
4
+ "description": "The adapter-base-scheduling package for Ghost.",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/TryGhost/Ghost.git",
9
+ "directory": "packages/adapters/scheduling-base"
10
+ },
11
+ "author": "Ghost Foundation",
12
+ "license": "MIT",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./build/index.d.ts",
16
+ "default": "./build/index.js"
17
+ }
18
+ },
19
+ "main": "build/index.js",
20
+ "types": "build/index.d.ts",
21
+ "files": [
22
+ "build"
23
+ ],
24
+ "dependencies": {
25
+ "@tryghost/logging": "4.2.1"
26
+ },
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "test:unit": "NODE_ENV=testing vitest run --coverage",
30
+ "test": "pnpm run '/^test:/'",
31
+ "test:types": "tsc --noEmit -p test/tsconfig.json",
32
+ "lint:code": "eslint src/ --cache",
33
+ "lint:test": "eslint test/ --cache",
34
+ "lint": "pnpm run '/^lint:/'"
35
+ }
36
+ }