@solytude/listmonk 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 +21 -0
- package/README.md +542 -0
- package/dist/chunk-saezhne8.js +14 -0
- package/dist/chunk-saezhne8.js.map +9 -0
- package/dist/client.d.ts +430 -0
- package/dist/errors/api.d.ts +178 -0
- package/dist/errors/base.d.ts +47 -0
- package/dist/errors/configuration.d.ts +49 -0
- package/dist/errors/index.d.ts +13 -0
- package/dist/errors/network.d.ts +69 -0
- package/dist/errors/validation.d.ts +57 -0
- package/dist/http/auth.d.ts +39 -0
- package/dist/http/client.d.ts +149 -0
- package/dist/http/hooks.d.ts +90 -0
- package/dist/http/index.d.ts +10 -0
- package/dist/http/resource.d.ts +100 -0
- package/dist/http/sse.d.ts +36 -0
- package/dist/http/url.d.ts +51 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +16039 -0
- package/dist/index.js.map +120 -0
- package/dist/resources/admin/admin.d.ts +92 -0
- package/dist/resources/admin/index.d.ts +10 -0
- package/dist/resources/admin/schemas.d.ts +23 -0
- package/dist/resources/admin/types.d.ts +29 -0
- package/dist/resources/bounces/bounces.d.ts +262 -0
- package/dist/resources/bounces/index.d.ts +10 -0
- package/dist/resources/bounces/schemas.d.ts +86 -0
- package/dist/resources/bounces/types.d.ts +37 -0
- package/dist/resources/campaigns/campaigns.d.ts +339 -0
- package/dist/resources/campaigns/index.d.ts +10 -0
- package/dist/resources/campaigns/schemas.d.ts +374 -0
- package/dist/resources/campaigns/types.d.ts +111 -0
- package/dist/resources/dashboard/dashboard.d.ts +73 -0
- package/dist/resources/dashboard/index.d.ts +10 -0
- package/dist/resources/dashboard/schemas.d.ts +55 -0
- package/dist/resources/dashboard/types.d.ts +22 -0
- package/dist/resources/import/import.d.ts +215 -0
- package/dist/resources/import/index.d.ts +10 -0
- package/dist/resources/import/schemas.d.ts +109 -0
- package/dist/resources/import/types.d.ts +72 -0
- package/dist/resources/lists/index.d.ts +10 -0
- package/dist/resources/lists/lists.d.ts +180 -0
- package/dist/resources/lists/schemas.d.ts +176 -0
- package/dist/resources/lists/types.d.ts +56 -0
- package/dist/resources/maintenance/index.d.ts +10 -0
- package/dist/resources/maintenance/maintenance.d.ts +92 -0
- package/dist/resources/maintenance/schemas.d.ts +36 -0
- package/dist/resources/maintenance/types.d.ts +31 -0
- package/dist/resources/media/index.d.ts +10 -0
- package/dist/resources/media/media.d.ts +198 -0
- package/dist/resources/media/schemas.d.ts +48 -0
- package/dist/resources/media/types.d.ts +48 -0
- package/dist/resources/public/index.d.ts +10 -0
- package/dist/resources/public/public.d.ts +111 -0
- package/dist/resources/public/schemas.d.ts +52 -0
- package/dist/resources/public/types.d.ts +30 -0
- package/dist/resources/settings/index.d.ts +10 -0
- package/dist/resources/settings/schemas.d.ts +374 -0
- package/dist/resources/settings/settings.d.ts +106 -0
- package/dist/resources/settings/types.d.ts +78 -0
- package/dist/resources/subscribers/index.d.ts +10 -0
- package/dist/resources/subscribers/schemas.d.ts +360 -0
- package/dist/resources/subscribers/subscribers.d.ts +308 -0
- package/dist/resources/subscribers/types.d.ts +113 -0
- package/dist/resources/templates/index.d.ts +10 -0
- package/dist/resources/templates/schemas.d.ts +110 -0
- package/dist/resources/templates/templates.d.ts +225 -0
- package/dist/resources/templates/types.d.ts +45 -0
- package/dist/resources/tx/index.d.ts +10 -0
- package/dist/resources/tx/schemas.d.ts +67 -0
- package/dist/resources/tx/tx.d.ts +167 -0
- package/dist/resources/tx/types.d.ts +88 -0
- package/dist/schemas/common.d.ts +48 -0
- package/dist/schemas/index.d.ts +6 -0
- package/dist/testing/errors.d.ts +25 -0
- package/dist/testing/factories/bounce.d.ts +43 -0
- package/dist/testing/factories/campaign.d.ts +43 -0
- package/dist/testing/factories/common.d.ts +54 -0
- package/dist/testing/factories/index.d.ts +12 -0
- package/dist/testing/factories/list.d.ts +43 -0
- package/dist/testing/factories/media.d.ts +40 -0
- package/dist/testing/factories/subscriber.d.ts +43 -0
- package/dist/testing/factories/template.d.ts +40 -0
- package/dist/testing/index.d.ts +39 -0
- package/dist/testing/index.js +573 -0
- package/dist/testing/index.js.map +32 -0
- package/dist/testing/mock-client.d.ts +119 -0
- package/dist/testing/mock-function.d.ts +28 -0
- package/dist/testing/resources/admin.d.ts +20 -0
- package/dist/testing/resources/bounces.d.ts +22 -0
- package/dist/testing/resources/campaigns.d.ts +31 -0
- package/dist/testing/resources/dashboard.d.ts +17 -0
- package/dist/testing/resources/import.d.ts +19 -0
- package/dist/testing/resources/index.d.ts +18 -0
- package/dist/testing/resources/lists.d.ts +24 -0
- package/dist/testing/resources/maintenance.d.ts +18 -0
- package/dist/testing/resources/media.d.ts +21 -0
- package/dist/testing/resources/public.d.ts +18 -0
- package/dist/testing/resources/settings.d.ts +19 -0
- package/dist/testing/resources/subscribers.d.ts +33 -0
- package/dist/testing/resources/templates.d.ts +24 -0
- package/dist/testing/resources/tx.d.ts +16 -0
- package/dist/testing/types.d.ts +138 -0
- package/dist/types/config.d.ts +59 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/pagination.d.ts +37 -0
- package/package.json +97 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing utility types for mock functions and mock client.
|
|
3
|
+
*
|
|
4
|
+
* @module testing/types
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Result of a mock function call.
|
|
8
|
+
*/
|
|
9
|
+
export interface MockResult<T> {
|
|
10
|
+
/** Whether the call returned or threw */
|
|
11
|
+
type: "return" | "throw";
|
|
12
|
+
/** The returned value or thrown error */
|
|
13
|
+
value: T | Error;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Internal state tracking for mock function calls.
|
|
17
|
+
*/
|
|
18
|
+
export interface MockState<TArgs extends unknown[], TReturn> {
|
|
19
|
+
/** Array of argument arrays from each invocation */
|
|
20
|
+
calls: TArgs[];
|
|
21
|
+
/** Array of results (return values or thrown errors) */
|
|
22
|
+
results: MockResult<TReturn>[];
|
|
23
|
+
/** Arguments from the most recent call, or undefined if never called */
|
|
24
|
+
lastCall: TArgs | undefined;
|
|
25
|
+
/** Total number of times the mock was called */
|
|
26
|
+
callCount: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Generic mock function interface.
|
|
30
|
+
*
|
|
31
|
+
* Replaces a real function with a configurable mock that tracks calls
|
|
32
|
+
* and can return predetermined values or throw errors.
|
|
33
|
+
*
|
|
34
|
+
* @typeParam TArgs - The function argument types
|
|
35
|
+
* @typeParam TReturn - The function return type
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const mockCreate = createMockFunction<[CreateSubscriberInput], Promise<Subscriber>>(
|
|
40
|
+
* 'subscribers',
|
|
41
|
+
* 'create'
|
|
42
|
+
* );
|
|
43
|
+
*
|
|
44
|
+
* // Configure return value
|
|
45
|
+
* mockCreate.mockResolvedValue({ id: 1, email: 'test@example.com', ... });
|
|
46
|
+
*
|
|
47
|
+
* // Use the mock
|
|
48
|
+
* const result = await mockCreate({ email: 'test@example.com' });
|
|
49
|
+
*
|
|
50
|
+
* // Verify calls
|
|
51
|
+
* expect(mockCreate.mock.callCount).toBe(1);
|
|
52
|
+
* expect(mockCreate.mock.calls[0]).toEqual([{ email: 'test@example.com' }]);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export interface MockFunction<TArgs extends unknown[], TReturn> {
|
|
56
|
+
/**
|
|
57
|
+
* Invoke the mock function.
|
|
58
|
+
* Returns the configured value or throws the configured error.
|
|
59
|
+
*
|
|
60
|
+
* @throws {MockNotConfiguredError} If no mock value/implementation configured
|
|
61
|
+
*/
|
|
62
|
+
(...args: TArgs): TReturn;
|
|
63
|
+
/**
|
|
64
|
+
* Internal mock state tracking.
|
|
65
|
+
*/
|
|
66
|
+
mock: MockState<TArgs, Awaited<TReturn>>;
|
|
67
|
+
/**
|
|
68
|
+
* Configure the mock to resolve with the given value.
|
|
69
|
+
* For async functions, wraps the value in Promise.resolve().
|
|
70
|
+
*
|
|
71
|
+
* @param value - The value to resolve with
|
|
72
|
+
* @returns The mock function for chaining
|
|
73
|
+
*/
|
|
74
|
+
mockResolvedValue(value: Awaited<TReturn>): this;
|
|
75
|
+
/**
|
|
76
|
+
* Configure the mock to reject with the given error.
|
|
77
|
+
* For async functions, wraps the error in Promise.reject().
|
|
78
|
+
*
|
|
79
|
+
* @param error - The error to reject with
|
|
80
|
+
* @returns The mock function for chaining
|
|
81
|
+
*/
|
|
82
|
+
mockRejectedValue(error: Error): this;
|
|
83
|
+
/**
|
|
84
|
+
* Configure the mock with a custom implementation.
|
|
85
|
+
* The implementation receives the same arguments as the real function.
|
|
86
|
+
*
|
|
87
|
+
* @param fn - The implementation function
|
|
88
|
+
* @returns The mock function for chaining
|
|
89
|
+
*/
|
|
90
|
+
mockImplementation(fn: (...args: TArgs) => TReturn): this;
|
|
91
|
+
/**
|
|
92
|
+
* Configure the mock to return the given value synchronously.
|
|
93
|
+
* For sync functions only.
|
|
94
|
+
*
|
|
95
|
+
* @param value - The value to return
|
|
96
|
+
* @returns The mock function for chaining
|
|
97
|
+
*/
|
|
98
|
+
mockReturnValue(value: TReturn): this;
|
|
99
|
+
/**
|
|
100
|
+
* Configure the mock to return an async iterator yielding the given values.
|
|
101
|
+
* Used for methods like listAll() that return AsyncIterableIterator.
|
|
102
|
+
*
|
|
103
|
+
* @param values - The values to yield
|
|
104
|
+
* @returns The mock function for chaining
|
|
105
|
+
*/
|
|
106
|
+
mockAsyncIterator<T>(values: T[]): this;
|
|
107
|
+
/**
|
|
108
|
+
* Clear call history and results, but keep the configured implementation.
|
|
109
|
+
*
|
|
110
|
+
* @returns The mock function for chaining
|
|
111
|
+
*/
|
|
112
|
+
mockClear(): this;
|
|
113
|
+
/**
|
|
114
|
+
* Reset the mock to unconfigured state.
|
|
115
|
+
* Clears call history, results, and implementation.
|
|
116
|
+
*
|
|
117
|
+
* @returns The mock function for chaining
|
|
118
|
+
*/
|
|
119
|
+
mockReset(): this;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Type helper for extracting argument types from a function.
|
|
123
|
+
*/
|
|
124
|
+
export type MockArgs<T> = T extends (...args: infer A) => unknown ? A : never;
|
|
125
|
+
/**
|
|
126
|
+
* Type helper for extracting return type from a function.
|
|
127
|
+
*/
|
|
128
|
+
export type MockReturn<T> = T extends (...args: unknown[]) => infer R ? R : never;
|
|
129
|
+
/**
|
|
130
|
+
* Type helper for converting a method to its mocked version.
|
|
131
|
+
*/
|
|
132
|
+
export type Mocked<T> = T extends (...args: infer A) => infer R ? MockFunction<A, R> : never;
|
|
133
|
+
/**
|
|
134
|
+
* Type helper for converting all methods of an object to mocks.
|
|
135
|
+
*/
|
|
136
|
+
export type MockedObject<T> = {
|
|
137
|
+
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? MockFunction<A, R> : T[K];
|
|
138
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client configuration types and Zod schema.
|
|
3
|
+
*
|
|
4
|
+
* Defines the shape of options passed to the Listmonk client constructor.
|
|
5
|
+
*
|
|
6
|
+
* @module types/config
|
|
7
|
+
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import type { RequestHook, ResponseHook } from "../http/hooks";
|
|
10
|
+
/**
|
|
11
|
+
* Type for custom fetch implementations.
|
|
12
|
+
* Compatible with both browser fetch and custom implementations.
|
|
13
|
+
*/
|
|
14
|
+
export type FetchLike = (input: string | Request | URL, init?: RequestInit) => Promise<Response>;
|
|
15
|
+
/**
|
|
16
|
+
* Authentication credentials schema.
|
|
17
|
+
*/
|
|
18
|
+
export declare const AuthCredentialsSchema: z.ZodObject<{
|
|
19
|
+
username: z.ZodString;
|
|
20
|
+
password: z.ZodString;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
/**
|
|
23
|
+
* Authentication credentials type.
|
|
24
|
+
*/
|
|
25
|
+
export type AuthCredentials = z.infer<typeof AuthCredentialsSchema>;
|
|
26
|
+
/**
|
|
27
|
+
* Client options Zod schema with runtime validation.
|
|
28
|
+
*
|
|
29
|
+
* Validates:
|
|
30
|
+
* - URL must be valid HTTPS
|
|
31
|
+
* - Auth credentials must be non-empty
|
|
32
|
+
* - Timeout must be non-negative integer
|
|
33
|
+
* - MaxRetries must be non-negative integer
|
|
34
|
+
*/
|
|
35
|
+
export declare const ClientOptionsSchema: z.ZodObject<{
|
|
36
|
+
url: z.ZodString;
|
|
37
|
+
auth: z.ZodObject<{
|
|
38
|
+
username: z.ZodString;
|
|
39
|
+
password: z.ZodString;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
42
|
+
maxRetries: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
43
|
+
debug: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
44
|
+
fetch: z.ZodOptional<z.ZodCustom<FetchLike, FetchLike>>;
|
|
45
|
+
onRequest: z.ZodOptional<z.ZodCustom<RequestHook, RequestHook>>;
|
|
46
|
+
onResponse: z.ZodOptional<z.ZodCustom<ResponseHook, ResponseHook>>;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
/**
|
|
49
|
+
* Client options type inferred from schema.
|
|
50
|
+
*
|
|
51
|
+
* Use this type when accepting configuration from users.
|
|
52
|
+
*/
|
|
53
|
+
export type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
54
|
+
/**
|
|
55
|
+
* Input type for ClientOptions (before defaults are applied).
|
|
56
|
+
*
|
|
57
|
+
* Use this type for the constructor parameter.
|
|
58
|
+
*/
|
|
59
|
+
export type ClientOptionsInput = z.input<typeof ClientOptionsSchema>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type exports for the listmonk SDK.
|
|
3
|
+
*
|
|
4
|
+
* @module types
|
|
5
|
+
*/
|
|
6
|
+
export { ClientOptionsSchema, AuthCredentialsSchema, type ClientOptions, type ClientOptionsInput, type AuthCredentials, type FetchLike, } from "./config";
|
|
7
|
+
export type { PagedAsyncIterableIterator } from "./pagination";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pagination types for async iteration over API results.
|
|
3
|
+
*
|
|
4
|
+
* @module types/pagination
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Async iterator that yields items with page-level iteration support.
|
|
8
|
+
*
|
|
9
|
+
* This interface extends `AsyncIterableIterator` to provide both
|
|
10
|
+
* item-by-item iteration and page-by-page iteration for paginated
|
|
11
|
+
* API responses.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam T - The type of items yielded (e.g., Subscriber, List)
|
|
14
|
+
* @typeParam TPage - The type of page objects (e.g., ListSubscribersResponse)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Iterate over individual items
|
|
19
|
+
* for await (const item of client.resource.listAll()) {
|
|
20
|
+
* console.log(item);
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* // Iterate over pages
|
|
24
|
+
* for await (const page of client.resource.listAll().byPage()) {
|
|
25
|
+
* console.log(`Page ${page.page} has ${page.results.length} items`);
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export interface PagedAsyncIterableIterator<T, TPage = T[]> extends AsyncIterableIterator<T> {
|
|
30
|
+
/**
|
|
31
|
+
* Returns an async iterator that yields pages instead of individual items.
|
|
32
|
+
*
|
|
33
|
+
* Use this when you need access to page-level metadata (total count,
|
|
34
|
+
* current page number, etc.) or want to process items in batches.
|
|
35
|
+
*/
|
|
36
|
+
byPage(): AsyncIterableIterator<TPage>;
|
|
37
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solytude/listmonk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Production-grade TypeScript SDK for the listmonk email marketing platform API",
|
|
5
|
+
"author": "solytude",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./testing": {
|
|
14
|
+
"types": "./dist/testing/index.d.ts",
|
|
15
|
+
"import": "./dist/testing/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"typesVersions": {
|
|
22
|
+
"*": {
|
|
23
|
+
"testing": [
|
|
24
|
+
"./dist/testing/index.d.ts"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
],
|
|
33
|
+
"sideEffects": false,
|
|
34
|
+
"packageManager": "bun@1.3.5",
|
|
35
|
+
"engines": {
|
|
36
|
+
"bun": ">=1.3.0",
|
|
37
|
+
"node": ">=22.0.0"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"listmonk",
|
|
41
|
+
"email",
|
|
42
|
+
"newsletter",
|
|
43
|
+
"mailing list",
|
|
44
|
+
"typescript",
|
|
45
|
+
"sdk",
|
|
46
|
+
"api",
|
|
47
|
+
"email marketing"
|
|
48
|
+
],
|
|
49
|
+
"homepage": "https://solytude.com/projects/listmonk-sdk",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://codeberg.org/solytude/listmonk-sdk/issues"
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "https://codeberg.org/solytude/listmonk-sdk.git"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "bun run build:js && bun run build:types",
|
|
59
|
+
"build:js": "bun run scripts/build.ts",
|
|
60
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
61
|
+
"test": "bun test tests/",
|
|
62
|
+
"test:unit": "bun test tests/unit/",
|
|
63
|
+
"test:integration": "bun test tests/integration/",
|
|
64
|
+
"test:e2e": "bun test tests/e2e/",
|
|
65
|
+
"check": "biome check",
|
|
66
|
+
"lint": "biome lint --write",
|
|
67
|
+
"format": "biome format --write",
|
|
68
|
+
"typecheck": "tsc -p tsconfig.check.json",
|
|
69
|
+
"docs": "typedoc",
|
|
70
|
+
"prepublishOnly": "bun run build && bun test tests/unit/ tests/integration/"
|
|
71
|
+
},
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"zod": "^4.3.5"
|
|
74
|
+
},
|
|
75
|
+
"publishConfig": {
|
|
76
|
+
"access": "public",
|
|
77
|
+
"registry": "https://registry.npmjs.org"
|
|
78
|
+
},
|
|
79
|
+
"overrides": {
|
|
80
|
+
"got": "11.8.5"
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@biomejs/biome": "2.3.11",
|
|
84
|
+
"@bun-security-scanner/osv": "^1.0.0",
|
|
85
|
+
"@commitlint/cli": "^20.3.0",
|
|
86
|
+
"@commitlint/config-conventional": "^20.3.0",
|
|
87
|
+
"@saithodev/semantic-release-gitea": "^2.0.0",
|
|
88
|
+
"@semantic-release/changelog": "^6.0.0",
|
|
89
|
+
"@semantic-release/git": "^10.0.0",
|
|
90
|
+
"@tsconfig/bun": "^1.0.10",
|
|
91
|
+
"@types/bun": "^1.3.5",
|
|
92
|
+
"semantic-release": "^25.0.0",
|
|
93
|
+
"typedoc": "^0.28.15",
|
|
94
|
+
"typedoc-plugin-markdown": "^4.0.0",
|
|
95
|
+
"typescript": "^5.9.3"
|
|
96
|
+
}
|
|
97
|
+
}
|