@zapyapi/sdk 1.0.0-beta.1

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.
Files changed (44) hide show
  1. package/README.md +308 -0
  2. package/index.cjs +1176 -0
  3. package/index.js +1149 -0
  4. package/package.json +55 -0
  5. package/src/client.d.ts +98 -0
  6. package/src/client.d.ts.map +1 -0
  7. package/src/errors.d.ts +70 -0
  8. package/src/errors.d.ts.map +1 -0
  9. package/src/generated/Api.d.ts +1542 -0
  10. package/src/generated/Api.d.ts.map +1 -0
  11. package/src/index.d.ts +38 -0
  12. package/src/index.d.ts.map +1 -0
  13. package/src/resources/base.resource.d.ts +17 -0
  14. package/src/resources/base.resource.d.ts.map +1 -0
  15. package/src/resources/index.d.ts +8 -0
  16. package/src/resources/index.d.ts.map +1 -0
  17. package/src/resources/instances.resource.d.ts +75 -0
  18. package/src/resources/instances.resource.d.ts.map +1 -0
  19. package/src/resources/messages.resource.d.ts +159 -0
  20. package/src/resources/messages.resource.d.ts.map +1 -0
  21. package/src/resources/webhooks.resource.d.ts +115 -0
  22. package/src/resources/webhooks.resource.d.ts.map +1 -0
  23. package/src/types/common.types.d.ts +89 -0
  24. package/src/types/common.types.d.ts.map +1 -0
  25. package/src/types/enums.d.ts +142 -0
  26. package/src/types/enums.d.ts.map +1 -0
  27. package/src/types/index.d.ts +11 -0
  28. package/src/types/index.d.ts.map +1 -0
  29. package/src/types/instances.types.d.ts +114 -0
  30. package/src/types/instances.types.d.ts.map +1 -0
  31. package/src/types/messages.types.d.ts +166 -0
  32. package/src/types/messages.types.d.ts.map +1 -0
  33. package/src/types/webhook-config.types.d.ts +60 -0
  34. package/src/types/webhook-config.types.d.ts.map +1 -0
  35. package/src/types/webhook-events.types.d.ts +232 -0
  36. package/src/types/webhook-events.types.d.ts.map +1 -0
  37. package/src/utils/index.d.ts +6 -0
  38. package/src/utils/index.d.ts.map +1 -0
  39. package/src/utils/phone.d.ts +38 -0
  40. package/src/utils/phone.d.ts.map +1 -0
  41. package/src/utils/webhook-signature.d.ts +69 -0
  42. package/src/utils/webhook-signature.d.ts.map +1 -0
  43. package/src/version.d.ts +3 -0
  44. package/src/version.d.ts.map +1 -0
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@zapyapi/sdk",
3
+ "version": "1.0.0-beta.1",
4
+ "description": "Official TypeScript SDK for ZapyAPI - WhatsApp API",
5
+ "type": "module",
6
+ "main": "./index.cjs",
7
+ "module": "./index.js",
8
+ "types": "./src/index.d.ts",
9
+ "exports": {
10
+ "./package.json": "./package.json",
11
+ ".": {
12
+ "types": "./src/index.d.ts",
13
+ "import": "./index.js",
14
+ "require": "./index.cjs",
15
+ "default": "./index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "index.js",
20
+ "index.cjs",
21
+ "src",
22
+ "README.md"
23
+ ],
24
+ "sideEffects": false,
25
+ "engines": {
26
+ "node": ">=18"
27
+ },
28
+ "keywords": [
29
+ "whatsapp",
30
+ "whatsapp-api",
31
+ "zapyapi",
32
+ "messaging",
33
+ "sdk",
34
+ "typescript"
35
+ ],
36
+ "author": "ZapyAPI <contato@zapyapi.com>",
37
+ "license": "MIT",
38
+ "homepage": "https://zapyapi.com",
39
+ "scripts": {
40
+ "generate": "node scripts/generate-api.mjs",
41
+ "generate:prod": "OPENAPI_URL=https://api.zapyapi.com/swagger-json node scripts/generate-api.mjs",
42
+ "generate:local": "OPENAPI_URL=http://localhost:3001/swagger-json node scripts/generate-api.mjs"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "registry": "https://registry.npmjs.org/"
47
+ },
48
+ "dependencies": {
49
+ "axios": "^1.11.0",
50
+ "tslib": "^2.3.0"
51
+ },
52
+ "devDependencies": {
53
+ "swagger-typescript-api": "^13.0.0"
54
+ }
55
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * ZapyClient - Main entry point for the ZapyAPI SDK
3
+ */
4
+ import { type AxiosInstance } from 'axios';
5
+ import type { ZapyClientOptions } from './types';
6
+ import { MessagesResource } from './resources/messages.resource';
7
+ import { WebhooksResource } from './resources/webhooks.resource';
8
+ import { InstancesResource } from './resources/instances.resource';
9
+ /**
10
+ * ZapyClient - Official TypeScript SDK for ZapyAPI
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { ZapyClient, WebhookEventType, isMessageEvent } from '@zapyapi/sdk';
15
+ *
16
+ * const client = new ZapyClient({
17
+ * apiKey: 'your-api-key',
18
+ * });
19
+ *
20
+ * // Send a text message
21
+ * await client.messages.sendText('my-instance', {
22
+ * to: '5511999999999',
23
+ * text: 'Hello from ZapyAPI SDK!'
24
+ * });
25
+ *
26
+ * // List instances
27
+ * const instances = await client.instances.list();
28
+ *
29
+ * // Get QR code for an instance
30
+ * const qr = await client.instances.getQRCode('my-instance');
31
+ *
32
+ * // Configure webhooks programmatically
33
+ * await client.webhooks.configure({
34
+ * url: 'https://your-server.com/webhook',
35
+ * secret: 'your-secret-key-min-16-chars',
36
+ * isActive: true,
37
+ * });
38
+ * ```
39
+ */
40
+ export declare class ZapyClient {
41
+ /**
42
+ * Internal Axios HTTP client
43
+ */
44
+ private readonly http;
45
+ /**
46
+ * Instance management operations
47
+ */
48
+ readonly instances: InstancesResource;
49
+ /**
50
+ * Message sending and management operations
51
+ */
52
+ readonly messages: MessagesResource;
53
+ /**
54
+ * Webhook configuration and management operations
55
+ *
56
+ * Webhooks are configured at the user level - one webhook URL receives
57
+ * events from ALL your instances. Each payload includes `instanceId`.
58
+ */
59
+ readonly webhooks: WebhooksResource;
60
+ /**
61
+ * Create a new ZapyClient instance
62
+ *
63
+ * @param options - Client configuration options
64
+ *
65
+ * @example
66
+ * const client = new ZapyClient({
67
+ * apiKey: 'your-api-key',
68
+ * baseUrl: 'https://api.zapyapi.com/api', // optional
69
+ * timeout: 30000, // optional, in milliseconds
70
+ * });
71
+ */
72
+ constructor(options: ZapyClientOptions);
73
+ /**
74
+ * Get the underlying Axios instance for advanced usage
75
+ *
76
+ * @returns The configured Axios instance
77
+ *
78
+ * @example
79
+ * const httpClient = client.getHttpClient();
80
+ * httpClient.interceptors.response.use(/* ... *\/);
81
+ */
82
+ getHttpClient(): AxiosInstance;
83
+ }
84
+ /**
85
+ * Create a new ZapyClient instance
86
+ *
87
+ * @param options - Client configuration options
88
+ * @returns A configured ZapyClient instance
89
+ *
90
+ * @example
91
+ * import { createClient } from '@zapyapi/sdk';
92
+ *
93
+ * const client = createClient({
94
+ * apiKey: 'your-api-key',
95
+ * });
96
+ */
97
+ export declare function createClient(options: ZapyClientOptions): ZapyClient;
98
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../libs/sdk/src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAc,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAElD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,UAAU;IACrB;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgB;IAErC;;OAEG;IACH,SAAgB,SAAS,EAAE,iBAAiB,CAAC;IAE7C;;OAEG;IACH,SAAgB,QAAQ,EAAE,gBAAgB,CAAC;IAE3C;;;;;OAKG;IACH,SAAgB,QAAQ,EAAE,gBAAgB,CAAC;IAE3C;;;;;;;;;;;OAWG;gBACS,OAAO,EAAE,iBAAiB;IAsBtC;;;;;;;;OAQG;IACH,aAAa,IAAI,aAAa;CAG/B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CAEnE"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Custom error classes for @zapyapi/sdk
3
+ */
4
+ import type { AxiosError } from 'axios';
5
+ import type { ApiErrorResponse } from './types/common.types';
6
+ /**
7
+ * Base error class for all ZapyAPI errors
8
+ */
9
+ export declare class ZapyError extends Error {
10
+ constructor(message: string);
11
+ }
12
+ /**
13
+ * Error thrown when the API returns an error response
14
+ */
15
+ export declare class ZapyApiError extends ZapyError {
16
+ /**
17
+ * HTTP status code
18
+ */
19
+ readonly statusCode: number;
20
+ /**
21
+ * Error code from the API
22
+ */
23
+ readonly code: string;
24
+ /**
25
+ * Request ID for debugging (if available)
26
+ */
27
+ readonly requestId?: string;
28
+ /**
29
+ * Additional error details
30
+ */
31
+ readonly details?: Record<string, unknown>;
32
+ constructor(message: string, statusCode: number, code: string, requestId?: string, details?: Record<string, unknown>);
33
+ /**
34
+ * Create a ZapyApiError from an Axios error
35
+ */
36
+ static fromAxiosError(error: AxiosError<ApiErrorResponse>): ZapyApiError;
37
+ }
38
+ /**
39
+ * Error thrown when input validation fails
40
+ */
41
+ export declare class ValidationError extends ZapyError {
42
+ /**
43
+ * Validation error details by field
44
+ */
45
+ readonly details: Record<string, string[]>;
46
+ constructor(message: string, details: Record<string, string[]>);
47
+ }
48
+ /**
49
+ * Error thrown when an instance is not found
50
+ */
51
+ export declare class InstanceNotFoundError extends ZapyApiError {
52
+ constructor(instanceId: string, requestId?: string);
53
+ }
54
+ /**
55
+ * Error thrown when authentication fails
56
+ */
57
+ export declare class AuthenticationError extends ZapyApiError {
58
+ constructor(message?: string, requestId?: string);
59
+ }
60
+ /**
61
+ * Error thrown when rate limit is exceeded
62
+ */
63
+ export declare class RateLimitError extends ZapyApiError {
64
+ /**
65
+ * Timestamp when the rate limit resets (Unix ms)
66
+ */
67
+ readonly retryAfter?: number;
68
+ constructor(message?: string, retryAfter?: number, requestId?: string);
69
+ }
70
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +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