From 9a1eaa2a0dae20a37549fab852af5599a500ca5d Mon Sep 17 00:00:00 2001 From: rgehbt <74761884+Gehbt@users.noreply.github.com> Date: Fri, 22 Aug 2025 19:47:25 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#73397=20feat(l?= =?UTF-8?q?oader-utils):=20=20Update=20to=20v3=20by=20@Gehbt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/loader-utils/index.d.ts | 65 ++++++++++---------- types/loader-utils/loader-utils-tests.ts | 75 ++++-------------------- types/loader-utils/package.json | 4 +- 3 files changed, 47 insertions(+), 97 deletions(-) diff --git a/types/loader-utils/index.d.ts b/types/loader-utils/index.d.ts index 31eea02b23f63e..06299e6f9752cf 100644 --- a/types/loader-utils/index.d.ts +++ b/types/loader-utils/index.d.ts @@ -1,11 +1,15 @@ /// -import { loader } from "webpack"; +import { LoaderContext } from "webpack"; export type Readonly = { readonly [P in keyof T]: T[P]; }; +export interface LoaderInterpolateOption { + customInterpolateName?: typeof interpolateName; +} + export interface InterpolateOption { context?: string | undefined; content?: string | Buffer | undefined; @@ -16,36 +20,26 @@ export interface OptionObject { [key: string]: null | false | true | string; } -export type HashType = "sha1" | "md4" | "md5" | "sha256" | "sha512"; - -export type DigestType = "hex" | "base26" | "base32" | "base36" | "base49" | "base52" | "base58" | "base62" | "base64"; - -/** - * Recommended way to retrieve the options of a loader invocation - * {@link https://github.com/webpack/loader-utils#getoptions} - */ -export function getOptions(loaderContext: loader.LoaderContext): Readonly; - +export type InterpolateNameType = string | ((resourcePath: string, resourceQuery?: string) => string); + +export type HashType = "xxhash64" | "sha1" | "md4" | "native-md4" | "md5" | "sha256" | "sha512"; + +export type DigestType = + | "hex" + | "base26" + | "base32" + | "base36" + | "base49" + | "base52" + | "base58" + | "base62" + | "base64" + | "base64safe"; /** - * Parses a passed string (e.g. loaderContext.resourceQuery) as a query string, and returns an object. - * {@link https://github.com/webpack/loader-utils#parsequery} + * {@link https://https://github.com/webpack/loader-utils#urltorequest} */ -export function parseQuery(optionString: string): OptionObject; - -/** - * Turns a request into a string that can be used inside require() or import while avoiding absolute paths. Use it instead of JSON.stringify(...) if you're generating code inside a loader. - * {@link https://github.com/webpack/loader-utils#stringifyrequest} - */ -export function stringifyRequest(loaderContext: loader.LoaderContext, resource: string): string; - -export function getRemainingRequest(loaderContext: loader.LoaderContext): string; - -export function getCurrentRequest(loaderContext: loader.LoaderContext): string; - export function isUrlRequest(url: string, root?: string): boolean; -export function parseString(str: string): string; - /** * Converts some resource URL to a webpack module request. * {@link https://github.com/webpack/loader-utils#urltorequest} @@ -57,12 +51,17 @@ export function urlToRequest(url: string, root?: string): string; * The template and regular expression are set as query params called name and regExp on the current loader's context. * {@link https://github.com/webpack/loader-utils#interpolatename} */ -export function interpolateName(loaderContext: loader.LoaderContext, name: string, options?: any): string; +export function interpolateName( + loaderContext: LoaderContext, + name: InterpolateNameType, + options?: InterpolateOption, +): string; /** - * @param buffer - * @param [hashType='md4'] - * @param [digestType='hex'] - * @param [maxLength=9999] + * @param buffer the content that should be hashed + * @param [hashType='xxhash64'] one of `xxhash64`, `sha1`, `md4`, `md5`, `sha256`, `sha512` or any other node.js supported hash type + * @param [digestType='hex'] one of `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`, `base64safe` + * @param [maxLength=9999] the maximum length in chars + * {@link https://github.com/webpack/loader-utils#gethashdigest} */ -export function getHashDigest(buffer: Buffer, hashType: HashType, digestType: DigestType, maxLength: number): string; +export function getHashDigest(buffer: Buffer, hashType?: HashType, digestType?: DigestType, maxLength?: number): string; diff --git a/types/loader-utils/loader-utils-tests.ts b/types/loader-utils/loader-utils-tests.ts index bb273358c328cd..dc23a884619ea9 100644 --- a/types/loader-utils/loader-utils-tests.ts +++ b/types/loader-utils/loader-utils-tests.ts @@ -1,72 +1,23 @@ -import { - getCurrentRequest, - getHashDigest, - getOptions, - getRemainingRequest, - interpolateName, - isUrlRequest, - parseQuery, - parseString, - stringifyRequest, - urlToRequest, -} from "loader-utils"; -import { loader } from "webpack"; - -parseQuery("?{data:{a:1},isJSON5:true}"); -parseString(`"123"`); // "123" -parseString(`'123'`); // "123" -parseString(`123`); // "123" -const jsonStr = JSON.stringify({ a: 1, b: 2 }); -const parsed = parseString(jsonStr); -jsonStr === parsed; // true - -function loader(this: loader.LoaderContext) { - getOptions(this); +import { getHashDigest, interpolateName, isUrlRequest, type LoaderInterpolateOption, urlToRequest } from "loader-utils"; +import type { LoaderContext } from "webpack"; +function loader(this: LoaderContext) { // get options readonly - const options = getOptions(this); + const options = this.getOptions(this); // @ts-expect-error options.prop = {}; - getRemainingRequest(this); - - getCurrentRequest(this); - - stringifyRequest(this, "./test.js"); - // "\"./test.js\"" - - stringifyRequest(this, ".\\test.js"); - // "\"./test.js\"" - - stringifyRequest(this, "test"); - // "\"test\"" - - stringifyRequest(this, "test/lib/index.js"); - // "\"test/lib/index.js\"" - - stringifyRequest(this, "otherLoader?andConfig!test?someConfig"); - // "\"otherLoader?andConfig!test?someConfig\"" - - stringifyRequest(this, "C:\\module\\test.js"); - // "\"../../test.js\"" (on Windows, in case the module and the request are on the same drive) - - stringifyRequest(this, "C:\\module\\test.js"); - // "\"C:\\module\\test.js\"" (on Windows, in case the module and the request are on different drives) - - stringifyRequest(this, "\\\\network-drive\\test.js"); - // "\"\\\\network-drive\\\\test.js\"" (on Windows, in case the module and the request are on different drives) + urlToRequest("path/to/module.js"); // "./path/to/module.js" + urlToRequest("~path/to/module.js"); // "path/to/module.js" + urlToRequest("/path/to/module.js", "./root"); // "./root/path/to/module.js" + urlToRequest("/path/to/module.js", "~"); // "path/to/module.js" + isUrlRequest("path/to/module.js"); + isUrlRequest("~path/to/module.js"); + isUrlRequest("/path/to/module.js", "./root"); + isUrlRequest("/path/to/module.js", "~"); } -urlToRequest("path/to/module.js"); // "./path/to/module.js" -urlToRequest("~path/to/module.js"); // "path/to/module.js" -urlToRequest("/path/to/module.js", "./root"); // "./root/path/to/module.js" -urlToRequest("/path/to/module.js", "~"); // "path/to/module.js" -isUrlRequest("path/to/module.js"); -isUrlRequest("~path/to/module.js"); -isUrlRequest("/path/to/module.js", "./root"); -isUrlRequest("/path/to/module.js", "~"); - -function loader2(this: loader.LoaderContext) { +function loader2(this: LoaderContext) { // loaderContext.resourcePath = "/app/js/javascript.js" interpolateName(this, "js/[hash].script.[ext]", { content: "" }); // => js/9473fdd0d880a43c21b7778d34872157.script.js diff --git a/types/loader-utils/package.json b/types/loader-utils/package.json index b90bae0ef91ba6..8afd00102a7006 100644 --- a/types/loader-utils/package.json +++ b/types/loader-utils/package.json @@ -1,13 +1,13 @@ { "private": true, "name": "@types/loader-utils", - "version": "2.0.9999", + "version": "3.0.9999", "projects": [ "https://github.com/webpack/loader-utils#readme" ], "dependencies": { "@types/node": "*", - "@types/webpack": "^4" + "webpack": "^5" }, "devDependencies": { "@types/loader-utils": "workspace:." From 5f171744624a01ef55d13444420a429c878f2cca Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com> Date: Fri, 22 Aug 2025 17:42:41 +0200 Subject: [PATCH 2/4] [react] Use string union for `textAnchor` and `dominatBaseline` (#73510) --- types/react/index.d.ts | 18 ++++++++++++++++-- types/react/ts5.0/index.d.ts | 18 ++++++++++++++++-- types/react/ts5.0/v18/index.d.ts | 18 ++++++++++++++++-- types/react/ts5.0/v18/ts5.0/index.d.ts | 18 ++++++++++++++++-- types/react/v15/index.d.ts | 18 ++++++++++++++++-- types/react/v16/index.d.ts | 18 ++++++++++++++++-- types/react/v17/index.d.ts | 18 ++++++++++++++++-- types/react/v18/index.d.ts | 18 ++++++++++++++++-- types/react/v18/test/elementAttributes.tsx | 6 ++++++ types/react/v18/ts5.0/index.d.ts | 18 ++++++++++++++++-- 10 files changed, 150 insertions(+), 18 deletions(-) diff --git a/types/react/index.d.ts b/types/react/index.d.ts index 403c8ec589ce8c..4257ab17ca7534 100644 --- a/types/react/index.d.ts +++ b/types/react/index.d.ts @@ -3572,7 +3572,21 @@ declare namespace React { direction?: number | string | undefined; display?: number | string | undefined; divisor?: number | string | undefined; - dominantBaseline?: number | string | undefined; + dominantBaseline?: + | "auto" + | "use-script" + | "no-change" + | "reset-size" + | "ideographic" + | "alphabetic" + | "hanging" + | "mathematical" + | "central" + | "middle" + | "text-after-edge" + | "text-before-edge" + | "inherit" + | undefined; dur?: number | string | undefined; dx?: number | string | undefined; dy?: number | string | undefined; @@ -3719,7 +3733,7 @@ declare namespace React { tableValues?: number | string | undefined; targetX?: number | string | undefined; targetY?: number | string | undefined; - textAnchor?: string | undefined; + textAnchor?: "start" | "middle" | "end" | "inherit" | undefined; textDecoration?: number | string | undefined; textLength?: number | string | undefined; textRendering?: number | string | undefined; diff --git a/types/react/ts5.0/index.d.ts b/types/react/ts5.0/index.d.ts index 4832244eec0217..5ef7d86674a808 100644 --- a/types/react/ts5.0/index.d.ts +++ b/types/react/ts5.0/index.d.ts @@ -3570,7 +3570,21 @@ declare namespace React { direction?: number | string | undefined; display?: number | string | undefined; divisor?: number | string | undefined; - dominantBaseline?: number | string | undefined; + dominantBaseline?: + | "auto" + | "use-script" + | "no-change" + | "reset-size" + | "ideographic" + | "alphabetic" + | "hanging" + | "mathematical" + | "central" + | "middle" + | "text-after-edge" + | "text-before-edge" + | "inherit" + | undefined; dur?: number | string | undefined; dx?: number | string | undefined; dy?: number | string | undefined; @@ -3717,7 +3731,7 @@ declare namespace React { tableValues?: number | string | undefined; targetX?: number | string | undefined; targetY?: number | string | undefined; - textAnchor?: string | undefined; + textAnchor?: "start" | "middle" | "end" | "inherit" | undefined; textDecoration?: number | string | undefined; textLength?: number | string | undefined; textRendering?: number | string | undefined; diff --git a/types/react/ts5.0/v18/index.d.ts b/types/react/ts5.0/v18/index.d.ts index 59cc15c7baddec..62cdeb3edf6805 100644 --- a/types/react/ts5.0/v18/index.d.ts +++ b/types/react/ts5.0/v18/index.d.ts @@ -3733,7 +3733,21 @@ declare namespace React { direction?: number | string | undefined; display?: number | string | undefined; divisor?: number | string | undefined; - dominantBaseline?: number | string | undefined; + dominantBaseline?: + | "auto" + | "use-script" + | "no-change" + | "reset-size" + | "ideographic" + | "alphabetic" + | "hanging" + | "mathematical" + | "central" + | "middle" + | "text-after-edge" + | "text-before-edge" + | "inherit" + | undefined; dur?: number | string | undefined; dx?: number | string | undefined; dy?: number | string | undefined; @@ -3880,7 +3894,7 @@ declare namespace React { tableValues?: number | string | undefined; targetX?: number | string | undefined; targetY?: number | string | undefined; - textAnchor?: string | undefined; + textAnchor?: "start" | "middle" | "end" | "inherit" | undefined; textDecoration?: number | string | undefined; textLength?: number | string | undefined; textRendering?: number | string | undefined; diff --git a/types/react/ts5.0/v18/ts5.0/index.d.ts b/types/react/ts5.0/v18/ts5.0/index.d.ts index a558f37123865a..34fa5c8a9f78a4 100644 --- a/types/react/ts5.0/v18/ts5.0/index.d.ts +++ b/types/react/ts5.0/v18/ts5.0/index.d.ts @@ -3734,7 +3734,21 @@ declare namespace React { direction?: number | string | undefined; display?: number | string | undefined; divisor?: number | string | undefined; - dominantBaseline?: number | string | undefined; + dominantBaseline?: + | "auto" + | "use-script" + | "no-change" + | "reset-size" + | "ideographic" + | "alphabetic" + | "hanging" + | "mathematical" + | "central" + | "middle" + | "text-after-edge" + | "text-before-edge" + | "inherit" + | undefined; dur?: number | string | undefined; dx?: number | string | undefined; dy?: number | string | undefined; @@ -3881,7 +3895,7 @@ declare namespace React { tableValues?: number | string | undefined; targetX?: number | string | undefined; targetY?: number | string | undefined; - textAnchor?: string | undefined; + textAnchor?: "start" | "middle" | "end" | "inherit" | undefined; textDecoration?: number | string | undefined; textLength?: number | string | undefined; textRendering?: number | string | undefined; diff --git a/types/react/v15/index.d.ts b/types/react/v15/index.d.ts index 1574dc66f6495f..893b21d879bd37 100644 --- a/types/react/v15/index.d.ts +++ b/types/react/v15/index.d.ts @@ -3311,7 +3311,21 @@ declare namespace React { direction?: number | string | undefined; display?: number | string | undefined; divisor?: number | string | undefined; - dominantBaseline?: number | string | undefined; + dominantBaseline?: + | "auto" + | "use-script" + | "no-change" + | "reset-size" + | "ideographic" + | "alphabetic" + | "hanging" + | "mathematical" + | "central" + | "middle" + | "text-after-edge" + | "text-before-edge" + | "inherit" + | undefined; dur?: number | string | undefined; dx?: number | string | undefined; dy?: number | string | undefined; @@ -3457,7 +3471,7 @@ declare namespace React { tableValues?: number | string | undefined; targetX?: number | string | undefined; targetY?: number | string | undefined; - textAnchor?: string | undefined; + textAnchor?: "start" | "middle" | "end" | "inherit" | undefined; textDecoration?: number | string | undefined; textLength?: number | string | undefined; textRendering?: number | string | undefined; diff --git a/types/react/v16/index.d.ts b/types/react/v16/index.d.ts index 509c2b647f9f39..b6200c03ec623b 100644 --- a/types/react/v16/index.d.ts +++ b/types/react/v16/index.d.ts @@ -2601,7 +2601,21 @@ declare namespace React { direction?: number | string | undefined; display?: number | string | undefined; divisor?: number | string | undefined; - dominantBaseline?: number | string | undefined; + dominantBaseline?: + | "auto" + | "use-script" + | "no-change" + | "reset-size" + | "ideographic" + | "alphabetic" + | "hanging" + | "mathematical" + | "central" + | "middle" + | "text-after-edge" + | "text-before-edge" + | "inherit" + | undefined; dur?: number | string | undefined; dx?: number | string | undefined; dy?: number | string | undefined; @@ -2748,7 +2762,7 @@ declare namespace React { tableValues?: number | string | undefined; targetX?: number | string | undefined; targetY?: number | string | undefined; - textAnchor?: string | undefined; + textAnchor?: "start" | "middle" | "end" | "inherit" | undefined; textDecoration?: number | string | undefined; textLength?: number | string | undefined; textRendering?: number | string | undefined; diff --git a/types/react/v17/index.d.ts b/types/react/v17/index.d.ts index fec1856e91040b..ebb3e0ec94e96a 100644 --- a/types/react/v17/index.d.ts +++ b/types/react/v17/index.d.ts @@ -2630,7 +2630,21 @@ declare namespace React { direction?: number | string | undefined; display?: number | string | undefined; divisor?: number | string | undefined; - dominantBaseline?: number | string | undefined; + dominantBaseline?: + | "auto" + | "use-script" + | "no-change" + | "reset-size" + | "ideographic" + | "alphabetic" + | "hanging" + | "mathematical" + | "central" + | "middle" + | "text-after-edge" + | "text-before-edge" + | "inherit" + | undefined; dur?: number | string | undefined; dx?: number | string | undefined; dy?: number | string | undefined; @@ -2777,7 +2791,7 @@ declare namespace React { tableValues?: number | string | undefined; targetX?: number | string | undefined; targetY?: number | string | undefined; - textAnchor?: string | undefined; + textAnchor?: "start" | "middle" | "end" | "inherit" | undefined; textDecoration?: number | string | undefined; textLength?: number | string | undefined; textRendering?: number | string | undefined; diff --git a/types/react/v18/index.d.ts b/types/react/v18/index.d.ts index 77a5847d205dcc..d2c0f651054705 100644 --- a/types/react/v18/index.d.ts +++ b/types/react/v18/index.d.ts @@ -3751,7 +3751,21 @@ declare namespace React { direction?: number | string | undefined; display?: number | string | undefined; divisor?: number | string | undefined; - dominantBaseline?: number | string | undefined; + dominantBaseline?: + | "auto" + | "use-script" + | "no-change" + | "reset-size" + | "ideographic" + | "alphabetic" + | "hanging" + | "mathematical" + | "central" + | "middle" + | "text-after-edge" + | "text-before-edge" + | "inherit" + | undefined; dur?: number | string | undefined; dx?: number | string | undefined; dy?: number | string | undefined; @@ -3898,7 +3912,7 @@ declare namespace React { tableValues?: number | string | undefined; targetX?: number | string | undefined; targetY?: number | string | undefined; - textAnchor?: string | undefined; + textAnchor?: "start" | "middle" | "end" | "inherit" | undefined; textDecoration?: number | string | undefined; textLength?: number | string | undefined; textRendering?: number | string | undefined; diff --git a/types/react/v18/test/elementAttributes.tsx b/types/react/v18/test/elementAttributes.tsx index 142b91db53c432..8a1986527b4581 100644 --- a/types/react/v18/test/elementAttributes.tsx +++ b/types/react/v18/test/elementAttributes.tsx @@ -46,6 +46,12 @@ const testCases = [ + ,
{}} name="foo" />, , diff --git a/types/react/v18/ts5.0/index.d.ts b/types/react/v18/ts5.0/index.d.ts index e36e98548708fd..23b01b94b8dacd 100644 --- a/types/react/v18/ts5.0/index.d.ts +++ b/types/react/v18/ts5.0/index.d.ts @@ -3752,7 +3752,21 @@ declare namespace React { direction?: number | string | undefined; display?: number | string | undefined; divisor?: number | string | undefined; - dominantBaseline?: number | string | undefined; + dominantBaseline?: + | "auto" + | "use-script" + | "no-change" + | "reset-size" + | "ideographic" + | "alphabetic" + | "hanging" + | "mathematical" + | "central" + | "middle" + | "text-after-edge" + | "text-before-edge" + | "inherit" + | undefined; dur?: number | string | undefined; dx?: number | string | undefined; dy?: number | string | undefined; @@ -3899,7 +3913,7 @@ declare namespace React { tableValues?: number | string | undefined; targetX?: number | string | undefined; targetY?: number | string | undefined; - textAnchor?: string | undefined; + textAnchor?: "start" | "middle" | "end" | "inherit" | undefined; textDecoration?: number | string | undefined; textLength?: number | string | undefined; textRendering?: number | string | undefined; From 3fdccb9d28435e83988068ef10679e176f4e3ede Mon Sep 17 00:00:00 2001 From: "Usman S. (Max Programming)" <51731966+max-programming@users.noreply.github.com> Date: Fri, 22 Aug 2025 21:12:58 +0530 Subject: [PATCH 3/4] [react] Added `fetchPriority` prop in script tag (#73404) Co-authored-by: Sebastian Sebbie Silbermann --- types/react/index.d.ts | 1 + types/react/ts5.0/index.d.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/types/react/index.d.ts b/types/react/index.d.ts index 4257ab17ca7534..6672da41683eec 100644 --- a/types/react/index.d.ts +++ b/types/react/index.d.ts @@ -3365,6 +3365,7 @@ declare namespace React { charSet?: string | undefined; crossOrigin?: CrossOrigin; defer?: boolean | undefined; + fetchPriority?: "high" | "low" | "auto" | undefined; integrity?: string | undefined; noModule?: boolean | undefined; referrerPolicy?: HTMLAttributeReferrerPolicy | undefined; diff --git a/types/react/ts5.0/index.d.ts b/types/react/ts5.0/index.d.ts index 5ef7d86674a808..e4fda43ef985e6 100644 --- a/types/react/ts5.0/index.d.ts +++ b/types/react/ts5.0/index.d.ts @@ -3363,6 +3363,7 @@ declare namespace React { charSet?: string | undefined; crossOrigin?: CrossOrigin; defer?: boolean | undefined; + fetchPriority?: "high" | "low" | "auto" | undefined; integrity?: string | undefined; noModule?: boolean | undefined; referrerPolicy?: HTMLAttributeReferrerPolicy | undefined; From 041179dd313a766365b51bae114c1904f4965855 Mon Sep 17 00:00:00 2001 From: Jose Javier <54906072+Josejj10@users.noreply.github.com> Date: Fri, 22 Aug 2025 11:14:42 -0500 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#73384=20Added?= =?UTF-8?q?=20Type=20Definition=20for=20@tryghost/admin-api=20version=201.?= =?UTF-8?q?14.0=20by=20@Josejj10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/tryghost__admin-api/.npmignore | 5 + types/tryghost__admin-api/index.d.ts | 725 ++++++++++++++++++ types/tryghost__admin-api/package.json | 20 + .../tryghost__admin-api-tests.ts | 36 + types/tryghost__admin-api/tsconfig.json | 19 + 5 files changed, 805 insertions(+) create mode 100644 types/tryghost__admin-api/.npmignore create mode 100644 types/tryghost__admin-api/index.d.ts create mode 100644 types/tryghost__admin-api/package.json create mode 100644 types/tryghost__admin-api/tryghost__admin-api-tests.ts create mode 100644 types/tryghost__admin-api/tsconfig.json diff --git a/types/tryghost__admin-api/.npmignore b/types/tryghost__admin-api/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/tryghost__admin-api/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/tryghost__admin-api/index.d.ts b/types/tryghost__admin-api/index.d.ts new file mode 100644 index 00000000000000..d0635c74ae0014 --- /dev/null +++ b/types/tryghost__admin-api/index.d.ts @@ -0,0 +1,725 @@ +/// +type ArrayOrValue = T | T[]; +type Nullable = T | null; + +// ============================================== +// Interfaces to extend the GhostAdminAPI types +// - Pagination +// - Identification +// - Metadata +// - Excerpt +// - CodeInjection +// - SocialMedia (Facebook, Twitter) +// - Settings +// - Email +// ============================================== + +interface Pagination { + page: number; + limit: number; + pages: number; + total: number; + next: Nullable; + prev: Nullable; +} + +interface Identification { + slug: string; + id: string; +} + +interface Dates { + created_at?: string | undefined; + updated_at?: Nullable | undefined; +} + +interface Metadata { + meta_title?: Nullable | undefined; + meta_description?: Nullable | undefined; +} + +interface Excerpt { + excerpt?: string | undefined; + custom_excerpt?: string | undefined; +} + +interface CodeInjection { + codeinjection_head?: Nullable | undefined; + codeinjection_foot?: Nullable | undefined; +} + +/** Metadata for Facebook */ +interface Facebook { + og_image?: Nullable | undefined; + og_title?: Nullable | undefined; + og_description?: Nullable | undefined; +} + +/** Metadata for Twitter */ +interface Twitter { + twitter_image?: Nullable | undefined; + twitter_title?: Nullable | undefined; + twitter_description?: Nullable | undefined; +} + +interface SocialMedia extends Facebook, Twitter {} + +interface Email extends Dates { + id: string | undefined; + uuid?: string | undefined; + status?: string | undefined; + recipient_filter?: string | undefined; + error?: string | null | undefined; + error_data?: string | undefined; + email_count?: number | undefined; + delivered_count?: number | undefined; + opened_count?: number | undefined; + failed_count?: number | undefined; + subject?: string | undefined; + from?: string | undefined; + reply_to?: string | undefined; + html?: string | undefined; + plaintext?: string | undefined; + track_opens: boolean; + submitted_at?: Nullable | undefined; +} + +// ================= +// Ghost Data Types: +// - Role +// - Author +// - Tag +// - Post +// - Page +// ================= + +// ================= +// Author & Role +// ================= +interface Role extends Dates { + id?: string | undefined; + name?: string | undefined; + description?: string | undefined; +} + +interface AuthorPostRequest { + id?: string | undefined; + name?: string | undefined; +} + +interface AuthorRequest extends Partial, Metadata, Dates { + name?: string | undefined; + profile_image?: Nullable | undefined; + cover_image?: Nullable | undefined; + bio?: Nullable | undefined; + website?: Nullable | undefined; + location?: Nullable | undefined; + facebook?: Nullable | undefined; + twitter?: Nullable | undefined; + url?: Nullable | undefined; + email?: Nullable | undefined; + last_seen?: Nullable | undefined; + tour?: Nullable | undefined; + status?: string | undefined; + accessibility?: Nullable | undefined; + roles?: Nullable | undefined; +} + +interface AuthorResponse extends Identification, Metadata, Dates { + name?: string | undefined; + profile_image?: Nullable | undefined; + cover_image?: Nullable | undefined; + bio?: Nullable | undefined; + website?: Nullable | undefined; + location?: Nullable | undefined; + facebook?: Nullable | undefined; + twitter?: Nullable | undefined; + url?: Nullable | undefined; + email?: Nullable | undefined; + last_seen?: Nullable | undefined; + tour?: Nullable | undefined; + status?: string | undefined; + accessibility?: Nullable | undefined; + roles?: Nullable | undefined; +} + +// ================= +// Tag +// ================= + +type TagVisibility = "public" | "internal"; + +interface TagPostRequest { + id?: string | undefined; + name?: string | undefined; + description?: string | undefined; +} + +interface TagRequest extends Partial, Metadata, SocialMedia, CodeInjection { + name?: string | undefined; + description?: Nullable | undefined; + feature_image?: Nullable | undefined; + canonical_url?: Nullable | undefined; + accent_color?: Nullable | undefined; + visibility?: TagVisibility | undefined; + url?: string | undefined; + parent?: string | undefined; +} + +interface TagResponse extends Identification, Metadata, SocialMedia, CodeInjection, Dates { + name?: string | undefined; + description?: Nullable | undefined; + feature_image?: Nullable | undefined; + canonical_url?: Nullable | undefined; + accent_color?: Nullable | undefined; + visibility?: TagVisibility | undefined; + url?: string | undefined; + parent?: string | undefined; +} + +// ================= +// Webhook +// ================= + +type WebhookEvents = + | "site.changed" + | "post.added" + | "post.deleted" + | "post.edited" + | "post.published" + | "post.published.edited" + | "post.unpublished" + | "post.scheduled" + | "post.unscheduled" + | "post.rescheduled" + | "page.added" + | "page.deleted" + | "page.edited" + | "page.published" + | "page.published.edited" + | "page.unpublished" + | "page.scheduled" + | "page.unscheduled" + | "page.rescheduled" + | "tag.added" + | "tag.edited" + | "tag.deleted" + | "post.tag.attached" + | "post.tag.detached" + | "page.tag.attached" + | "page.tag.detached" + | "member.added" + | "member.edited" + | "member.deleted"; + +interface WebhookRequest extends Dates { + event: WebhookEvents; + target_url: string; + name?: string | undefined; + api_version?: string | undefined; + secret?: string | undefined; + integration_id?: string | undefined; +} + +type WebhookEditRequest = Partial; + +interface WebhookResponse extends WebhookRequest { + id?: string | undefined; + status?: string | undefined; + last_triggered_at?: Nullable | undefined; + last_triggered_status?: Nullable | undefined; + last_triggered_error?: Nullable | undefined; +} + +// ================= +// Newsletter +// ================= + +interface NewsletterMember { + id?: string | undefined; +} + +interface NewsletterRequest extends Partial { + name?: string | undefined; + description?: Nullable | undefined; + sender_name?: string | undefined; + sender_email?: Nullable | undefined; + sender_reply_to?: string | undefined; + visibility?: string | undefined; + subscribe_on_signup?: boolean | undefined; + sort_order?: number | undefined; + header_image?: Nullable | undefined; + show_header_icon?: boolean | undefined; + show_header_title?: boolean | undefined; + title_font_category?: string | undefined; + title_alignment?: string | undefined; + show_feature_image?: boolean | undefined; + body_font_category?: string | undefined; + footer_content?: Nullable | undefined; + show_badge?: boolean | undefined; + show_header_name?: boolean | undefined; +} +interface NewsletterResponse extends Identification, Dates { + uuid?: string | undefined; + name?: string | undefined; + description?: Nullable | undefined; + sender_name?: string | undefined; + sender_email?: Nullable | undefined; + sender_reply_to?: string | undefined; + status?: string | undefined; + visibility?: string | undefined; + subscribe_on_signup?: boolean | undefined; + sort_order?: number | undefined; + header_image?: Nullable | undefined; + show_header_icon?: boolean | undefined; + show_header_title?: boolean | undefined; + title_font_category?: string | undefined; + title_alignment?: string | undefined; + show_feature_image?: boolean | undefined; + body_font_category?: string | undefined; + footer_content?: Nullable | undefined; + show_badge?: boolean | undefined; + show_header_name?: boolean | undefined; +} + +// ====================== +// Member & Subscription +// ====================== + +interface Subscription { + id?: string | undefined; + customer?: { + id?: string | undefined; + name?: string | undefined; + email?: string | undefined; + }; + status?: string | undefined; + start_date?: string | undefined; + default_payment_card_last4?: string | undefined; + cancel_at_period_end?: boolean | undefined; + cancellation_reason?: string | null | undefined; + current_period_end?: string | undefined; + price?: { + id?: string | undefined; + price_id?: string | undefined; + nickname?: string | undefined; + amount?: number | undefined; + interval?: string | undefined; + type?: string | undefined; + currency?: string | undefined; + }; + tier?: any; + offer?: any; +} + +interface MemberLabel extends Dates { + id?: string | undefined; + name?: string | undefined; + slug?: string | undefined; +} + +interface MemberRequest { + email: string | undefined; + name?: string | undefined; + note?: Nullable | undefined; + labels?: MemberLabel[] | undefined; + newsletters?: NewsletterMember[] | undefined; +} + +interface MemberResponse extends Dates { + id?: string | undefined; + uuid?: string | undefined; + email?: string | undefined; + name?: string | undefined; + note?: Nullable | undefined; + geolocation?: Nullable | undefined; + labels?: MemberLabel[] | undefined; + subscriptions?: Subscription[] | undefined; + avatar_image?: Nullable | undefined; + email_count?: number | undefined; + email_opened_count?: number | undefined; + email_open_rate?: Nullable | undefined; + last_seen_at?: Nullable | undefined; + status?: string | undefined; + newsletters?: NewsletterMember[] | undefined; +} + +// ================= +// User +// ================= + +interface UserRequest { + name?: string | undefined; + email?: string | undefined; + profile_image?: Nullable | undefined; + cover_image?: Nullable | undefined; + bio?: Nullable | undefined; + website?: Nullable | undefined; + location?: Nullable | undefined; + facebook?: Nullable | undefined; + twitter?: Nullable | undefined; + accessibility?: Nullable | undefined; + tour?: Nullable | undefined; + comment_notifications?: boolean | undefined; + free_member_signup_notification?: boolean | undefined; + paid_subscription_started_notification?: boolean | undefined; + paid_subscription_canceled_notification?: boolean | undefined; + mention_notifications?: boolean | undefined; + milestone_notifications?: boolean | undefined; + roles?: Nullable | undefined; +} + +interface UserResponse extends Metadata, Dates { + id?: string | undefined; + name?: string | undefined; + email?: string | undefined; + profile_image?: Nullable | undefined; + cover_image?: Nullable | undefined; + bio?: Nullable | undefined; + website?: Nullable | undefined; + location?: Nullable | undefined; + facebook?: Nullable | undefined; + twitter?: Nullable | undefined; + accessibility?: Nullable | undefined; + status?: string | undefined; + tour?: Nullable | undefined; + comment_notifications?: boolean | undefined; + free_member_signup_notification?: boolean | undefined; + paid_subscription_started_notification?: boolean | undefined; + paid_subscription_canceled_notification?: boolean | undefined; + mention_notifications?: boolean | undefined; + milestone_notifications?: boolean | undefined; + permissions?: any[] | undefined; + roles?: Nullable | undefined; + count?: { + posts?: number | undefined; + }; + url?: string | undefined; +} + +// ================= +// Post & Page +// ================= + +type PostStatus = "draft" | "published" | "scheduled" | "archived" | "deleted"; +type PostVisibility = "public" | "members" | "paid"; + +interface PostOrPageRequest extends Partial, Excerpt, CodeInjection, Metadata, SocialMedia { + /* Title is required */ + title: string; + + // Identification + featured?: boolean | undefined; + + // Post or Page + html?: Nullable | undefined; + lexical?: object | string | undefined; + + // Image + feature_image?: Nullable | undefined; + feature_image_alt?: Nullable | undefined; + feature_image_caption?: Nullable | undefined; + + // Custom Template for posts and pages + custom_template?: Nullable | undefined; + + // Tags + tags?: (TagPostRequest | string)[] | undefined; + + // Authors + authors?: (AuthorPostRequest | string)[] | undefined; + + // Email + email?: Nullable | undefined; + email_only?: Nullable | undefined; + + // URLs + url?: string | undefined; + canonical_url?: Nullable | undefined; +} + +interface PostOrPageResponse extends Identification, Excerpt, CodeInjection, Metadata, SocialMedia, Dates { + // Identification + uuid?: string | undefined; + comment_id?: string | undefined; + featured?: boolean | undefined; + + // Post or Page + title?: string | undefined; + html?: Nullable | undefined; + lexical?: object | string | undefined; + + // Access + status?: PostStatus | undefined; + visibility?: PostVisibility | undefined; + + // Image + feature_image?: Nullable | undefined; + feature_image_alt?: Nullable | undefined; + feature_image_caption?: Nullable | undefined; + + // Dates + published_at?: Nullable | undefined; + + // Custom Template for posts and pages + custom_template?: Nullable | undefined; + + // Tags - Only shown when using Include param + tags?: TagResponse[] | undefined; + primary_tag?: Nullable | undefined; + + // Authors - Only shown when using Include Param + authors?: AuthorResponse[] | undefined; + primary_author?: Nullable | undefined; + + // Newsletter - Only shown when using Include param + newsletter?: Nullable | undefined; + + // Email + email?: Nullable | undefined; + email_only?: Nullable | undefined; + + // URLs + url?: string | undefined; + canonical_url?: Nullable | undefined; +} + +// ================= +// Config & Site +// ================= + +interface ConfigResponse { + title?: string | undefined; + description?: string | undefined; + logo?: string | undefined; + icon?: string | undefined; +} + +interface SiteResponse { + title?: string | undefined; + description?: string | undefined; + logo?: string | undefined; + url?: string | undefined; + version?: string | undefined; +} + +// ================= +// Query Params +// ================= + +type IncludeParam = string; + +type FormatParam = "html" | "plaintext"; + +type FilterParam = string; + +type LimitParam = number | string; + +type PageParam = number; + +type OrderParam = string; + +interface Params { + include?: ArrayOrValue | undefined; + formats?: ArrayOrValue | undefined; + filter?: ArrayOrValue | undefined; + limit?: ArrayOrValue | undefined; + page?: ArrayOrValue | undefined; + order?: ArrayOrValue | undefined; +} + +// ================= +// Functions +// ================= + +interface BrowseFunction { + (options?: Params): Promise; +} + +interface ReadFunction { + ( + data: + | { id: string; slug?: never; email?: any } + | { id?: any; slug: string; email?: any } + | { id?: any; slug?: any; email: string }, + options?: Params, + ): Promise; +} + +interface SiteReadFunction { + (): Promise; +} + +interface AddFunction { + (data: { [key: string]: string } & (U extends undefined ? { [key: string]: string } : U)): Promise; +} +interface EditFunction { + (data: { id: string } & (U extends undefined ? { [key: string]: string } : U)): Promise; +} +interface DeleteFunction<> { + (data: { id: string } | { email: string }): Promise; +} + +interface UploadFunction { + (data: FormData | ({ file: any; [key: string]: string } & T)): Promise; +} + +interface ActivateFunction { + (name: string): Promise; +} + +interface BrowseResults extends Array { + meta: { pagination: Pagination }; +} + +// ================= +// Interfaces +// ================= + +type PostsOrPages = BrowseResults; + +type Members = BrowseResults; + +type Users = BrowseResults; + +type Tags = BrowseResults; + +type Newsletters = BrowseResults; + +// ================= +// SDK options +// ================= + +interface MakeRequestOptions { + url: string; + method: string; + data?: object; + params?: object; + headers?: object; +} + +interface GenerateTokenOptions { + /** + * API key to sign JWT with + */ + key: string; + /** + * Token audience + */ + audience: string; +} + +interface GhostAdminAPIOptions { + url: string; + /** + * Version of GhostAdminAPI + * - A version string in in 'v{major}.{minor}' format. + * - A boolean value identifying presence of Accept-Version header + * Should be in 'v{major}.{minor}' format. Default is 'v5.0' + * + * * Deprecated options: 'v1', 'v2', 'v3', 'v4', 'v5', 'canary' + */ + version: string; + /** + * Flag controlling if the 'User-Agent' header should be sent with a request + * @default true + */ + userAgent?: string | boolean; + key: string; + /** @deprecated since version v2 */ + host?: string | undefined; + /** @default "ghost" */ + ghostPath?: string | undefined; + makeRequest?: (options: MakeRequestOptions) => Promise; + generateToken?: (options: GenerateTokenOptions) => string | undefined; +} + +// ================= +// SDK +// ================= + +interface GhostAPI { + posts: { + /* Must include either data.id or data.slug or data.email */ + read: ReadFunction; + browse: BrowseFunction; + add: AddFunction; + edit: EditFunction; + delete: DeleteFunction; + }; + pages: { + /* Must include either data.id or data.slug or data.email */ + read: ReadFunction; + browse: BrowseFunction; + add: AddFunction; + edit: EditFunction; + delete: DeleteFunction; + }; + tags: { + /* Must include either data.id or data.slug or data.email */ + read: ReadFunction; + browse: BrowseFunction; + edit: EditFunction; + add: AddFunction; + delete: DeleteFunction; + }; + webhooks: { + edit: EditFunction; + add: AddFunction; + delete: DeleteFunction; + }; + members: { + /* Must include either data.id or data.slug or data.email */ + read: ReadFunction; + browse: BrowseFunction; + add: AddFunction; + edit: EditFunction; + delete: DeleteFunction; + }; + users: { + /* Must include either data.id or data.slug or data.email */ + read: ReadFunction; + browse: BrowseFunction; + edit: EditFunction; + delete: DeleteFunction; + // Adding a user is not available in Ghost Admin API Client + // See more: https://ghost.org/docs/admin-api/#endpoints + // add: AddFunction + }; + newsletters: { + /* Must include either data.id or data.slug or data.email */ + read: ReadFunction; + browse: BrowseFunction; + edit: EditFunction; + add: AddFunction; + delete: DeleteFunction; + }; + images: { + upload: UploadFunction; + }; + subscribers: {}; + media: { + upload: UploadFunction<{ purpose?: string; thumbnail?: string }>; + }; + files: { + upload: UploadFunction<{ ref?: string }>; + }; + config: { + /* Not documented in Ghost Admin API, but present on the admin-api library */ + read: ReadFunction; + }; + site: { + read: SiteReadFunction; + }; + themes: { + upload: UploadFunction; + activate: ActivateFunction; + }; +} + +declare var GhostAdminAPI: { + (options: GhostAdminAPIOptions): GhostAPI; + new(options: GhostAdminAPIOptions): GhostAPI; +}; + +export = GhostAdminAPI; diff --git a/types/tryghost__admin-api/package.json b/types/tryghost__admin-api/package.json new file mode 100644 index 00000000000000..d76a16fd23481f --- /dev/null +++ b/types/tryghost__admin-api/package.json @@ -0,0 +1,20 @@ +{ + "private": true, + "name": "@types/tryghost__admin-api", + "version": "0.0.9999", + "projects": [ + "https://github.com/TryGhost/Ghost-SDK/tree/master/packages/admin-api" + ], + "dependencies": { + "@types/node": "*" + }, + "devDependencies": { + "@types/tryghost__admin-api": "workspace:." + }, + "owners": [ + { + "name": "Jose Javier", + "githubUsername": "josejj10" + } + ] +} diff --git a/types/tryghost__admin-api/tryghost__admin-api-tests.ts b/types/tryghost__admin-api/tryghost__admin-api-tests.ts new file mode 100644 index 00000000000000..2fdc85570fea1a --- /dev/null +++ b/types/tryghost__admin-api/tryghost__admin-api-tests.ts @@ -0,0 +1,36 @@ +import GhostAdminAPI = require("@tryghost/admin-api"); + +// Accept arbitrary version strings +const api = new GhostAdminAPI({ url: "test", version: "v5.9999", key: "" }); // $ExpectType GhostAPI + +const postsBrowsePromise = api.posts.browse(); // $ExpectType Promise + +postsBrowsePromise.then((posts) => { + api.posts.read(posts[0], { include: "authors" }); // $ExpectType Promise +}); + +const tagsBrowsePromise = api.tags.browse(); // $ExpectType Promise + +tagsBrowsePromise.then((tags) => { + const tagPromise = api.tags.read(tags[0]); // $ExpectType Promise + + tagPromise.then((tag) => { + if (tag.name) { + tag.name; // $ExpectType string + } + }); +}); + +api.webhooks.add({ event: "post.added", target_url: "https://example.com/webhook" }); // $ExpectType Promise +api.webhooks.edit({ ...{ event: "post.published" }, id: "webhook-id" }); // $ExpectType Promise +api.webhooks.delete({ id: "webhook-id" }); // $ExpectType Promise + +api.users.browse(); // $ExpectType Promise +api.users.read({ id: "user-id" }); // $ExpectType Promise +api.users.edit({ id: "user-id", name: "Test User" }); // $ExpectType Promise +api.users.delete({ id: "user-id" }); // $ExpectType Promise + +api.images.upload({ file: "test.jpg" }); // $ExpectType Promise +api.media.upload({ file: "test-2.png", purpose: "test" }); // $ExpectType Promise + +api.site.read(); // $ExpectType Promise diff --git a/types/tryghost__admin-api/tsconfig.json b/types/tryghost__admin-api/tsconfig.json new file mode 100644 index 00000000000000..6d24b0943444f2 --- /dev/null +++ b/types/tryghost__admin-api/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "node16", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "tryghost__admin-api-tests.ts" + ] +}