@scell/sdk 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.
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Webhooks Resource
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+
7
+ import type { HttpClient, RequestOptions } from '../client.js';
8
+ import type {
9
+ MessageResponse,
10
+ MessageWithDataResponse,
11
+ PaginatedResponse,
12
+ } from '../types/common.js';
13
+ import type {
14
+ CreateWebhookInput,
15
+ UpdateWebhookInput,
16
+ Webhook,
17
+ WebhookListOptions,
18
+ WebhookLog,
19
+ WebhookTestResponse,
20
+ WebhookWithSecret,
21
+ } from '../types/webhooks.js';
22
+
23
+ /**
24
+ * Webhooks API resource
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // Create a webhook
29
+ * const webhook = await client.webhooks.create({
30
+ * url: 'https://myapp.com/webhooks/scell',
31
+ * events: ['invoice.validated', 'signature.completed'],
32
+ * environment: 'production'
33
+ * });
34
+ *
35
+ * // Store the secret securely!
36
+ * console.log('Webhook secret:', webhook.secret);
37
+ *
38
+ * // Test the webhook
39
+ * const test = await client.webhooks.test(webhook.id);
40
+ * console.log('Test success:', test.success);
41
+ * ```
42
+ */
43
+ export class WebhooksResource {
44
+ constructor(private readonly http: HttpClient) {}
45
+
46
+ /**
47
+ * List all webhooks
48
+ *
49
+ * @param options - Filter options
50
+ * @param requestOptions - Request options
51
+ * @returns List of webhooks
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const { data: webhooks } = await client.webhooks.list();
56
+ * webhooks.forEach(wh => {
57
+ * console.log(`${wh.url}: ${wh.is_active ? 'active' : 'inactive'}`);
58
+ * });
59
+ * ```
60
+ */
61
+ async list(
62
+ options: WebhookListOptions = {},
63
+ requestOptions?: RequestOptions
64
+ ): Promise<{ data: Webhook[] }> {
65
+ return this.http.get<{ data: Webhook[] }>(
66
+ '/webhooks',
67
+ options as Record<string, string | number | boolean | undefined>,
68
+ requestOptions
69
+ );
70
+ }
71
+
72
+ /**
73
+ * Create a new webhook
74
+ *
75
+ * Important: The secret is only returned once during creation.
76
+ * Store it securely - you'll need it to verify webhook signatures.
77
+ *
78
+ * @param input - Webhook configuration
79
+ * @param requestOptions - Request options
80
+ * @returns Created webhook with secret
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const { data: webhook } = await client.webhooks.create({
85
+ * url: 'https://myapp.com/webhooks/scell',
86
+ * events: [
87
+ * 'invoice.created',
88
+ * 'invoice.validated',
89
+ * 'signature.completed',
90
+ * 'balance.low'
91
+ * ],
92
+ * environment: 'production',
93
+ * headers: {
94
+ * 'X-Custom-Auth': 'my-secret-token'
95
+ * },
96
+ * retry_count: 5,
97
+ * timeout_seconds: 30
98
+ * });
99
+ *
100
+ * // IMPORTANT: Store this secret securely!
101
+ * await saveWebhookSecret(webhook.id, webhook.secret);
102
+ * ```
103
+ */
104
+ async create(
105
+ input: CreateWebhookInput,
106
+ requestOptions?: RequestOptions
107
+ ): Promise<MessageWithDataResponse<WebhookWithSecret>> {
108
+ return this.http.post<MessageWithDataResponse<WebhookWithSecret>>(
109
+ '/webhooks',
110
+ input,
111
+ requestOptions
112
+ );
113
+ }
114
+
115
+ /**
116
+ * Update a webhook
117
+ *
118
+ * @param id - Webhook UUID
119
+ * @param input - Fields to update
120
+ * @param requestOptions - Request options
121
+ * @returns Updated webhook
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * // Disable a webhook temporarily
126
+ * await client.webhooks.update('webhook-uuid', {
127
+ * is_active: false
128
+ * });
129
+ *
130
+ * // Update events
131
+ * await client.webhooks.update('webhook-uuid', {
132
+ * events: ['invoice.validated', 'signature.completed']
133
+ * });
134
+ * ```
135
+ */
136
+ async update(
137
+ id: string,
138
+ input: UpdateWebhookInput,
139
+ requestOptions?: RequestOptions
140
+ ): Promise<MessageWithDataResponse<Webhook>> {
141
+ return this.http.put<MessageWithDataResponse<Webhook>>(
142
+ `/webhooks/${id}`,
143
+ input,
144
+ requestOptions
145
+ );
146
+ }
147
+
148
+ /**
149
+ * Delete a webhook
150
+ *
151
+ * @param id - Webhook UUID
152
+ * @param requestOptions - Request options
153
+ * @returns Deletion confirmation
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * await client.webhooks.delete('webhook-uuid');
158
+ * ```
159
+ */
160
+ async delete(
161
+ id: string,
162
+ requestOptions?: RequestOptions
163
+ ): Promise<MessageResponse> {
164
+ return this.http.delete<MessageResponse>(`/webhooks/${id}`, requestOptions);
165
+ }
166
+
167
+ /**
168
+ * Regenerate webhook secret
169
+ *
170
+ * Use this if your secret has been compromised.
171
+ * The old secret will immediately stop working.
172
+ *
173
+ * @param id - Webhook UUID
174
+ * @param requestOptions - Request options
175
+ * @returns Webhook with new secret
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * const { data: webhook } = await client.webhooks.regenerateSecret(
180
+ * 'webhook-uuid'
181
+ * );
182
+ *
183
+ * // Update your stored secret
184
+ * await updateWebhookSecret(webhook.id, webhook.secret);
185
+ * ```
186
+ */
187
+ async regenerateSecret(
188
+ id: string,
189
+ requestOptions?: RequestOptions
190
+ ): Promise<MessageWithDataResponse<WebhookWithSecret>> {
191
+ return this.http.post<MessageWithDataResponse<WebhookWithSecret>>(
192
+ `/webhooks/${id}/regenerate-secret`,
193
+ undefined,
194
+ requestOptions
195
+ );
196
+ }
197
+
198
+ /**
199
+ * Test webhook by sending a test event
200
+ *
201
+ * @param id - Webhook UUID
202
+ * @param requestOptions - Request options
203
+ * @returns Test result
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const result = await client.webhooks.test('webhook-uuid');
208
+ *
209
+ * if (result.success) {
210
+ * console.log(`Success! Response time: ${result.response_time_ms}ms`);
211
+ * } else {
212
+ * console.log(`Failed: ${result.error}`);
213
+ * }
214
+ * ```
215
+ */
216
+ async test(
217
+ id: string,
218
+ requestOptions?: RequestOptions
219
+ ): Promise<WebhookTestResponse> {
220
+ return this.http.post<WebhookTestResponse>(
221
+ `/webhooks/${id}/test`,
222
+ undefined,
223
+ requestOptions
224
+ );
225
+ }
226
+
227
+ /**
228
+ * Get webhook delivery logs
229
+ *
230
+ * @param id - Webhook UUID
231
+ * @param options - Pagination options
232
+ * @param requestOptions - Request options
233
+ * @returns Paginated list of logs
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * const { data: logs } = await client.webhooks.logs('webhook-uuid', {
238
+ * per_page: 50
239
+ * });
240
+ *
241
+ * logs.forEach(log => {
242
+ * const status = log.success ? 'OK' : 'FAILED';
243
+ * console.log(`${log.event} - ${status} (${log.response_time_ms}ms)`);
244
+ * });
245
+ * ```
246
+ */
247
+ async logs(
248
+ id: string,
249
+ options: { per_page?: number } = {},
250
+ requestOptions?: RequestOptions
251
+ ): Promise<PaginatedResponse<WebhookLog>> {
252
+ return this.http.get<PaginatedResponse<WebhookLog>>(
253
+ `/webhooks/${id}/logs`,
254
+ options,
255
+ requestOptions
256
+ );
257
+ }
258
+ }
@@ -0,0 +1,35 @@
1
+ import type { DateTimeString, Environment, UUID } from './common.js';
2
+
3
+ /**
4
+ * API Key entity
5
+ */
6
+ export interface ApiKey {
7
+ id: UUID;
8
+ name: string;
9
+ company_id: UUID;
10
+ key_prefix: string;
11
+ environment: Environment;
12
+ permissions: string[];
13
+ rate_limit: number;
14
+ last_used_at: DateTimeString | null;
15
+ expires_at: DateTimeString | null;
16
+ created_at: DateTimeString;
17
+ }
18
+
19
+ /**
20
+ * API Key with full key (returned on creation only)
21
+ */
22
+ export interface ApiKeyWithSecret extends ApiKey {
23
+ key: string;
24
+ }
25
+
26
+ /**
27
+ * API Key creation input
28
+ */
29
+ export interface CreateApiKeyInput {
30
+ name: string;
31
+ company_id: UUID;
32
+ environment: Environment;
33
+ permissions?: string[] | undefined;
34
+ expires_at?: DateTimeString | undefined;
35
+ }
@@ -0,0 +1,58 @@
1
+ import type { DateTimeString, UUID } from './common.js';
2
+
3
+ /**
4
+ * User entity
5
+ */
6
+ export interface User {
7
+ id: UUID;
8
+ name: string;
9
+ email: string;
10
+ email_verified_at: DateTimeString | null;
11
+ is_admin: boolean;
12
+ created_at: DateTimeString;
13
+ updated_at: DateTimeString;
14
+ }
15
+
16
+ /**
17
+ * Login credentials
18
+ */
19
+ export interface LoginCredentials {
20
+ email: string;
21
+ password: string;
22
+ }
23
+
24
+ /**
25
+ * Registration input
26
+ */
27
+ export interface RegisterInput {
28
+ name: string;
29
+ email: string;
30
+ password: string;
31
+ password_confirmation: string;
32
+ }
33
+
34
+ /**
35
+ * Auth response with token
36
+ */
37
+ export interface AuthResponse {
38
+ message: string;
39
+ user: User;
40
+ token: string;
41
+ }
42
+
43
+ /**
44
+ * Password reset request input
45
+ */
46
+ export interface ForgotPasswordInput {
47
+ email: string;
48
+ }
49
+
50
+ /**
51
+ * Password reset input
52
+ */
53
+ export interface ResetPasswordInput {
54
+ email: string;
55
+ token: string;
56
+ password: string;
57
+ password_confirmation: string;
58
+ }
@@ -0,0 +1,87 @@
1
+ import type {
2
+ CurrencyCode,
3
+ DateRangeOptions,
4
+ DateTimeString,
5
+ PaginationOptions,
6
+ UUID,
7
+ } from './common.js';
8
+
9
+ /**
10
+ * Transaction type
11
+ */
12
+ export type TransactionType = 'credit' | 'debit';
13
+
14
+ /**
15
+ * Transaction service
16
+ */
17
+ export type TransactionService = 'invoice' | 'signature' | 'manual' | 'admin';
18
+
19
+ /**
20
+ * Balance entity
21
+ */
22
+ export interface Balance {
23
+ amount: number;
24
+ currency: CurrencyCode;
25
+ auto_reload_enabled: boolean;
26
+ auto_reload_threshold: number | null;
27
+ auto_reload_amount: number | null;
28
+ low_balance_alert_threshold: number;
29
+ critical_balance_alert_threshold: number;
30
+ }
31
+
32
+ /**
33
+ * Transaction entity
34
+ */
35
+ export interface Transaction {
36
+ id: UUID;
37
+ type: TransactionType;
38
+ service: TransactionService;
39
+ amount: number;
40
+ balance_before: number;
41
+ balance_after: number;
42
+ description: string;
43
+ reference_type: string | null;
44
+ reference_id: UUID | null;
45
+ created_at: DateTimeString;
46
+ }
47
+
48
+ /**
49
+ * Balance reload input
50
+ */
51
+ export interface ReloadBalanceInput {
52
+ /** Amount to reload (10-10000 EUR) */
53
+ amount: number;
54
+ }
55
+
56
+ /**
57
+ * Balance reload response
58
+ */
59
+ export interface ReloadBalanceResponse {
60
+ message: string;
61
+ transaction: {
62
+ id: UUID;
63
+ amount: number;
64
+ balance_after: number;
65
+ };
66
+ }
67
+
68
+ /**
69
+ * Balance settings update input
70
+ */
71
+ export interface UpdateBalanceSettingsInput {
72
+ auto_reload_enabled?: boolean | undefined;
73
+ auto_reload_threshold?: number | undefined;
74
+ auto_reload_amount?: number | undefined;
75
+ low_balance_alert_threshold?: number | undefined;
76
+ critical_balance_alert_threshold?: number | undefined;
77
+ }
78
+
79
+ /**
80
+ * Transaction list filter options
81
+ */
82
+ export interface TransactionListOptions
83
+ extends PaginationOptions,
84
+ DateRangeOptions {
85
+ type?: TransactionType | undefined;
86
+ service?: TransactionService | undefined;
87
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Common types used across the SDK
3
+ */
4
+
5
+ /**
6
+ * Environment mode for API operations
7
+ */
8
+ export type Environment = 'sandbox' | 'production';
9
+
10
+ /**
11
+ * ISO 8601 date string (YYYY-MM-DD)
12
+ */
13
+ export type DateString = string;
14
+
15
+ /**
16
+ * ISO 8601 datetime string
17
+ */
18
+ export type DateTimeString = string;
19
+
20
+ /**
21
+ * UUID string
22
+ */
23
+ export type UUID = string;
24
+
25
+ /**
26
+ * French SIRET number (14 digits)
27
+ */
28
+ export type Siret = string;
29
+
30
+ /**
31
+ * French SIREN number (9 digits)
32
+ */
33
+ export type Siren = string;
34
+
35
+ /**
36
+ * Currency code (ISO 4217)
37
+ */
38
+ export type CurrencyCode = string;
39
+
40
+ /**
41
+ * Address structure
42
+ */
43
+ export interface Address {
44
+ line1: string;
45
+ line2?: string | undefined;
46
+ postal_code: string;
47
+ city: string;
48
+ country?: string | undefined;
49
+ }
50
+
51
+ /**
52
+ * Pagination metadata
53
+ */
54
+ export interface PaginationMeta {
55
+ current_page: number;
56
+ last_page: number;
57
+ per_page: number;
58
+ total: number;
59
+ }
60
+
61
+ /**
62
+ * Paginated response wrapper
63
+ */
64
+ export interface PaginatedResponse<T> {
65
+ data: T[];
66
+ meta: PaginationMeta;
67
+ }
68
+
69
+ /**
70
+ * Single item response wrapper
71
+ */
72
+ export interface SingleResponse<T> {
73
+ data: T;
74
+ }
75
+
76
+ /**
77
+ * Message response
78
+ */
79
+ export interface MessageResponse {
80
+ message: string;
81
+ }
82
+
83
+ /**
84
+ * Message with data response
85
+ */
86
+ export interface MessageWithDataResponse<T> {
87
+ message: string;
88
+ data: T;
89
+ }
90
+
91
+ /**
92
+ * Pagination options for list requests
93
+ */
94
+ export interface PaginationOptions {
95
+ page?: number | undefined;
96
+ per_page?: number | undefined;
97
+ }
98
+
99
+ /**
100
+ * Date range filter options
101
+ */
102
+ export interface DateRangeOptions {
103
+ from?: DateString | undefined;
104
+ to?: DateString | undefined;
105
+ }
106
+
107
+ /**
108
+ * API error response structure
109
+ */
110
+ export interface ApiErrorResponse {
111
+ message: string;
112
+ errors?: Record<string, string[]> | undefined;
113
+ code?: string | undefined;
114
+ }
@@ -0,0 +1,86 @@
1
+ import type { DateTimeString, Siren, Siret, UUID } from './common.js';
2
+
3
+ /**
4
+ * Company KYC status
5
+ */
6
+ export type CompanyStatus = 'pending_kyc' | 'active' | 'suspended';
7
+
8
+ /**
9
+ * Company entity
10
+ */
11
+ export interface Company {
12
+ id: UUID;
13
+ name: string;
14
+ siret: Siret;
15
+ siren: Siren | null;
16
+ vat_number: string | null;
17
+ legal_form: string | null;
18
+ address_line1: string;
19
+ address_line2: string | null;
20
+ postal_code: string;
21
+ city: string;
22
+ country: string;
23
+ phone: string | null;
24
+ email: string | null;
25
+ website: string | null;
26
+ logo_url: string | null;
27
+ status: CompanyStatus;
28
+ kyc_completed_at: DateTimeString | null;
29
+ created_at: DateTimeString;
30
+ updated_at: DateTimeString;
31
+ }
32
+
33
+ /**
34
+ * Company creation input
35
+ */
36
+ export interface CreateCompanyInput {
37
+ name: string;
38
+ siret: Siret;
39
+ vat_number?: string | undefined;
40
+ legal_form?: string | undefined;
41
+ address_line1: string;
42
+ address_line2?: string | undefined;
43
+ postal_code: string;
44
+ city: string;
45
+ country?: string | undefined;
46
+ phone?: string | undefined;
47
+ email?: string | undefined;
48
+ website?: string | undefined;
49
+ }
50
+
51
+ /**
52
+ * Company update input
53
+ */
54
+ export interface UpdateCompanyInput {
55
+ name?: string | undefined;
56
+ siret?: Siret | undefined;
57
+ vat_number?: string | undefined;
58
+ legal_form?: string | undefined;
59
+ address_line1?: string | undefined;
60
+ address_line2?: string | undefined;
61
+ postal_code?: string | undefined;
62
+ city?: string | undefined;
63
+ country?: string | undefined;
64
+ phone?: string | undefined;
65
+ email?: string | undefined;
66
+ website?: string | undefined;
67
+ }
68
+
69
+ /**
70
+ * KYC initiation response
71
+ */
72
+ export interface KycInitiateResponse {
73
+ message: string;
74
+ kyc_reference: string;
75
+ redirect_url: string;
76
+ }
77
+
78
+ /**
79
+ * KYC status response
80
+ */
81
+ export interface KycStatusResponse {
82
+ status: CompanyStatus;
83
+ kyc_reference: string | null;
84
+ kyc_completed_at: DateTimeString | null;
85
+ message: string;
86
+ }