@ffflorian/icanhazdadjoke 2.4.7 → 2.5.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 +1 -1
- package/dist/ICanHazDadJokeAPI.d.ts +11 -1
- package/dist/ICanHazDadJokeAPI.js +25 -0
- package/dist/Interfaces.d.ts +21 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ICanHazDadJoke [](https://www.npmjs.com/package/@ffflorian/icanhazdadjoke)
|
|
2
2
|
|
|
3
|
-
An [ICanHazDadJoke](https://icanhazdadjoke.com) API client with a CLI.
|
|
3
|
+
An [ICanHazDadJoke](https://icanhazdadjoke.com) API client with a CLI. For a documentation on the API see [the icanhazdadjoke API reference](https://icanhazdadjoke.com/api).
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { APIClient } from '@ffflorian/api-client';
|
|
2
|
-
import type { ClientOptions, JokeResult, JokeResultWithImage, JokeSearchResult, RequestOptions, SearchOptions } from './Interfaces';
|
|
2
|
+
import type { ClientOptions, GraphQLResponse, JokeResult, JokeResultWithImage, JokeSearchResult, RequestOptions, SearchOptions, SlackJokeResult } from './Interfaces';
|
|
3
3
|
export declare class ICanHazDadJokeAPI {
|
|
4
4
|
protected readonly apiClient: APIClient;
|
|
5
5
|
protected readonly options: ClientOptions;
|
|
@@ -28,6 +28,16 @@ export declare class ICanHazDadJokeAPI {
|
|
|
28
28
|
withImage: true;
|
|
29
29
|
}): Promise<JokeResultWithImage>;
|
|
30
30
|
getRandom(options?: RequestOptions): Promise<JokeResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Fetch a random dad joke as a Slack message.
|
|
33
|
+
* @see https://icanhazdadjoke.com/api#fetch-a-random-dad-joke-as-a-slack-message
|
|
34
|
+
*/
|
|
35
|
+
getSlack(): Promise<SlackJokeResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Execute a GraphQL query.
|
|
38
|
+
* @see https://icanhazdadjoke.com/api#graphql
|
|
39
|
+
*/
|
|
40
|
+
graphql(query: string): Promise<GraphQLResponse>;
|
|
31
41
|
/**
|
|
32
42
|
* Search for dad jokes.
|
|
33
43
|
* @param options Search options (default: list all jokes)
|
|
@@ -10,6 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ICanHazDadJokeAPI = void 0;
|
|
13
|
+
const MIN_SEARCH_LIMIT = 1;
|
|
14
|
+
const MAX_SEARCH_LIMIT = 30;
|
|
13
15
|
class ICanHazDadJokeAPI {
|
|
14
16
|
constructor(apiClient, options) {
|
|
15
17
|
this.apiClient = apiClient;
|
|
@@ -38,11 +40,34 @@ class ICanHazDadJokeAPI {
|
|
|
38
40
|
return metaData;
|
|
39
41
|
});
|
|
40
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Fetch a random dad joke as a Slack message.
|
|
45
|
+
* @see https://icanhazdadjoke.com/api#fetch-a-random-dad-joke-as-a-slack-message
|
|
46
|
+
*/
|
|
47
|
+
getSlack() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const { data } = yield this.apiClient.get('/slack');
|
|
50
|
+
return data;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Execute a GraphQL query.
|
|
55
|
+
* @see https://icanhazdadjoke.com/api#graphql
|
|
56
|
+
*/
|
|
57
|
+
graphql(query) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const { data } = yield this.apiClient.post('/graphql', { query });
|
|
60
|
+
return data;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
41
63
|
search(query_1) {
|
|
42
64
|
return __awaiter(this, arguments, void 0, function* (query, options = {}) {
|
|
43
65
|
if (typeof query === 'string') {
|
|
44
66
|
options.term = query;
|
|
45
67
|
}
|
|
68
|
+
if (options.limit !== undefined && (options.limit < MIN_SEARCH_LIMIT || options.limit > MAX_SEARCH_LIMIT)) {
|
|
69
|
+
throw new Error(`The search limit must be between ${MIN_SEARCH_LIMIT} and ${MAX_SEARCH_LIMIT}, got ${options.limit}.`);
|
|
70
|
+
}
|
|
46
71
|
const { data } = yield this.apiClient.get('/search', {
|
|
47
72
|
params: options,
|
|
48
73
|
});
|
package/dist/Interfaces.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
export interface ClientOptions {
|
|
2
2
|
apiUrl?: string;
|
|
3
3
|
}
|
|
4
|
+
export interface GraphQLData {
|
|
5
|
+
joke: GraphQLJokeResult;
|
|
6
|
+
}
|
|
7
|
+
export interface GraphQLJokeResult {
|
|
8
|
+
id: string;
|
|
9
|
+
joke: string;
|
|
10
|
+
permalink: string;
|
|
11
|
+
}
|
|
12
|
+
export interface GraphQLResponse {
|
|
13
|
+
data: GraphQLData;
|
|
14
|
+
}
|
|
4
15
|
export interface JokeResult {
|
|
5
16
|
id: string;
|
|
6
17
|
joke: string;
|
|
@@ -31,3 +42,13 @@ export interface SearchOptions {
|
|
|
31
42
|
/** search term to use (default: list all jokes) */
|
|
32
43
|
term?: string;
|
|
33
44
|
}
|
|
45
|
+
export interface SlackAttachment {
|
|
46
|
+
fallback: string;
|
|
47
|
+
footer: string;
|
|
48
|
+
text: string;
|
|
49
|
+
}
|
|
50
|
+
export interface SlackJokeResult {
|
|
51
|
+
attachments: SlackAttachment[];
|
|
52
|
+
response_type: string;
|
|
53
|
+
username: string;
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -8,10 +8,12 @@
|
|
|
8
8
|
"description": "An icanhazdadjoke.com API client with a CLI.",
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@types/node": "~24",
|
|
11
|
+
"nock": "14.0.12",
|
|
11
12
|
"rimraf": "6.1.3",
|
|
12
13
|
"tsx": "4.21.0",
|
|
13
|
-
"typedoc": "0.28.
|
|
14
|
-
"typescript": "6.0.2"
|
|
14
|
+
"typedoc": "0.28.19",
|
|
15
|
+
"typescript": "6.0.2",
|
|
16
|
+
"vitest": "4.1.4"
|
|
15
17
|
},
|
|
16
18
|
"engines": {
|
|
17
19
|
"node": ">= 21"
|
|
@@ -37,7 +39,7 @@
|
|
|
37
39
|
"clean": "rimraf dist",
|
|
38
40
|
"dist": "yarn clean && yarn build",
|
|
39
41
|
"start": "tsx src/cli.ts",
|
|
40
|
-
"test": "
|
|
42
|
+
"test": "vitest"
|
|
41
43
|
},
|
|
42
|
-
"version": "2.
|
|
44
|
+
"version": "2.5.0"
|
|
43
45
|
}
|