@serialsubscriptions/platform-integration 0.0.79

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 (60) hide show
  1. package/README.md +1 -0
  2. package/lib/SSIProject.d.ts +343 -0
  3. package/lib/SSIProject.js +429 -0
  4. package/lib/SSIProjectApi.d.ts +384 -0
  5. package/lib/SSIProjectApi.js +534 -0
  6. package/lib/SSISubscribedFeatureApi.d.ts +387 -0
  7. package/lib/SSISubscribedFeatureApi.js +511 -0
  8. package/lib/SSISubscribedLimitApi.d.ts +384 -0
  9. package/lib/SSISubscribedLimitApi.js +534 -0
  10. package/lib/SSISubscribedPlanApi.d.ts +384 -0
  11. package/lib/SSISubscribedPlanApi.js +537 -0
  12. package/lib/SubscribedPlanManager.d.ts +380 -0
  13. package/lib/SubscribedPlanManager.js +288 -0
  14. package/lib/UsageApi.d.ts +128 -0
  15. package/lib/UsageApi.js +224 -0
  16. package/lib/auth.server.d.ts +192 -0
  17. package/lib/auth.server.js +579 -0
  18. package/lib/cache/SSICache.d.ts +40 -0
  19. package/lib/cache/SSICache.js +134 -0
  20. package/lib/cache/backends/MemoryCacheBackend.d.ts +15 -0
  21. package/lib/cache/backends/MemoryCacheBackend.js +46 -0
  22. package/lib/cache/backends/RedisCacheBackend.d.ts +27 -0
  23. package/lib/cache/backends/RedisCacheBackend.js +95 -0
  24. package/lib/cache/constants.d.ts +7 -0
  25. package/lib/cache/constants.js +10 -0
  26. package/lib/cache/types.d.ts +27 -0
  27. package/lib/cache/types.js +2 -0
  28. package/lib/frontend/index.d.ts +1 -0
  29. package/lib/frontend/index.js +6 -0
  30. package/lib/frontend/session/SessionClient.d.ts +24 -0
  31. package/lib/frontend/session/SessionClient.js +145 -0
  32. package/lib/index.d.ts +15 -0
  33. package/lib/index.js +38 -0
  34. package/lib/lib/session/SessionClient.d.ts +11 -0
  35. package/lib/lib/session/SessionClient.js +47 -0
  36. package/lib/lib/session/index.d.ts +3 -0
  37. package/lib/lib/session/index.js +3 -0
  38. package/lib/lib/session/stores/MemoryStore.d.ts +7 -0
  39. package/lib/lib/session/stores/MemoryStore.js +23 -0
  40. package/lib/lib/session/stores/index.d.ts +1 -0
  41. package/lib/lib/session/stores/index.js +1 -0
  42. package/lib/lib/session/types.d.ts +37 -0
  43. package/lib/lib/session/types.js +1 -0
  44. package/lib/session/SessionClient.d.ts +19 -0
  45. package/lib/session/SessionClient.js +132 -0
  46. package/lib/session/SessionManager.d.ts +139 -0
  47. package/lib/session/SessionManager.js +443 -0
  48. package/lib/stateStore.d.ts +5 -0
  49. package/lib/stateStore.js +9 -0
  50. package/lib/storage/SSIStorage.d.ts +24 -0
  51. package/lib/storage/SSIStorage.js +117 -0
  52. package/lib/storage/backends/MemoryBackend.d.ts +10 -0
  53. package/lib/storage/backends/MemoryBackend.js +44 -0
  54. package/lib/storage/backends/PostgresBackend.d.ts +24 -0
  55. package/lib/storage/backends/PostgresBackend.js +106 -0
  56. package/lib/storage/backends/RedisBackend.d.ts +19 -0
  57. package/lib/storage/backends/RedisBackend.js +78 -0
  58. package/lib/storage/types.d.ts +27 -0
  59. package/lib/storage/types.js +2 -0
  60. package/package.json +71 -0
@@ -0,0 +1,384 @@
1
+ /**
2
+ * @file
3
+ * SSIProjectApi - JSON:API Client for Project Entities
4
+ *
5
+ * A TypeScript client for interacting with Drupal JSON:API endpoints
6
+ * for project entities. This class is independent of Drupal and can be used
7
+ * on any platform that supports fetch.
8
+ *
9
+ * Requirements:
10
+ * - Node.js 18+ (for native fetch) or a fetch polyfill
11
+ * - TypeScript 5.0+
12
+ *
13
+ * Usage:
14
+ * @example
15
+ * ```typescript
16
+ * // Initialize the client with a domain
17
+ * const client = new SSIProjectApi('https://example.com');
18
+ *
19
+ * // Set Bearer token authentication
20
+ * client.setBearerToken('your-oauth-or-jwt-token-here');
21
+ *
22
+ * // List projects with filters and pagination
23
+ * const projects = await client.list(
24
+ * { status: 'active' },
25
+ * ['-created'],
26
+ * { offset: 0, limit: 10 }
27
+ * );
28
+ *
29
+ * // Get a single project by UUID
30
+ * const project = await client.get('550e8400-e29b-41d4-a716-446655440000', {
31
+ * include: ['owner', 'tags']
32
+ * });
33
+ *
34
+ * // Create a project
35
+ * const newProject = await client.create(
36
+ * { title: 'New Project', status: 'active' },
37
+ * { owner: { type: 'user--user', id: 'user-uuid' } }
38
+ * );
39
+ *
40
+ * // Update a project by UUID
41
+ * await client.update('550e8400-e29b-41d4-a716-446655440000', { status: 'completed' });
42
+ *
43
+ * // Delete a project by UUID
44
+ * await client.delete('550e8400-e29b-41d4-a716-446655440000');
45
+ * ```
46
+ */
47
+ /**
48
+ * JSON:API Resource Identifier
49
+ */
50
+ export interface ResourceIdentifier {
51
+ type: string;
52
+ id: string;
53
+ }
54
+ /**
55
+ * JSON:API Relationship Data
56
+ */
57
+ export type RelationshipData = ResourceIdentifier | ResourceIdentifier[];
58
+ /**
59
+ * JSON:API Relationship
60
+ */
61
+ export interface Relationship {
62
+ data: RelationshipData;
63
+ }
64
+ /**
65
+ * JSON:API Resource Object
66
+ */
67
+ export interface JsonApiResource {
68
+ type: string;
69
+ id?: string;
70
+ attributes?: Record<string, unknown>;
71
+ relationships?: Record<string, Relationship>;
72
+ }
73
+ /**
74
+ * JSON:API Document
75
+ */
76
+ export interface JsonApiDocument {
77
+ data: JsonApiResource | JsonApiResource[];
78
+ included?: JsonApiResource[];
79
+ links?: {
80
+ self?: string;
81
+ first?: string;
82
+ last?: string;
83
+ next?: string;
84
+ prev?: string;
85
+ };
86
+ meta?: {
87
+ count?: number;
88
+ [key: string]: unknown;
89
+ };
90
+ }
91
+ /**
92
+ * JSON:API Error
93
+ */
94
+ export interface JsonApiError {
95
+ status?: string;
96
+ code?: string;
97
+ title?: string;
98
+ detail?: string;
99
+ source?: {
100
+ pointer?: string;
101
+ parameter?: string;
102
+ };
103
+ }
104
+ /**
105
+ * JSON:API Error Document
106
+ */
107
+ export interface JsonApiErrorDocument {
108
+ errors: JsonApiError[];
109
+ }
110
+ /**
111
+ * Filter condition with operator
112
+ */
113
+ export interface FilterCondition {
114
+ operator: string;
115
+ value: string | number | string[] | number[];
116
+ }
117
+ /**
118
+ * Filter parameters
119
+ */
120
+ export type FilterParams = Record<string, string | number | FilterCondition>;
121
+ /**
122
+ * Sort field (with optional '-' prefix for descending)
123
+ */
124
+ export type SortField = string;
125
+ /**
126
+ * Pagination options
127
+ */
128
+ export interface PaginationOptions {
129
+ offset?: number;
130
+ limit?: number;
131
+ }
132
+ /**
133
+ * Sparse fieldset options
134
+ */
135
+ export type SparseFieldsetOptions = Record<string, string[]>;
136
+ /**
137
+ * Relationship format for create/update
138
+ */
139
+ export interface RelationshipInput {
140
+ type: string;
141
+ id: string;
142
+ }
143
+ /**
144
+ * Relationships for create/update
145
+ */
146
+ export type RelationshipsInput = Record<string, RelationshipInput | RelationshipInput[]>;
147
+ /**
148
+ * Options for list() method
149
+ */
150
+ export interface ListOptions {
151
+ filters?: FilterParams;
152
+ sort?: SortField[];
153
+ pagination?: PaginationOptions;
154
+ include?: string[];
155
+ fields?: SparseFieldsetOptions;
156
+ }
157
+ /**
158
+ * Options for get() method
159
+ */
160
+ export interface GetOptions {
161
+ include?: string[];
162
+ fields?: SparseFieldsetOptions;
163
+ }
164
+ /**
165
+ * Options for create() method
166
+ */
167
+ export interface CreateOptions {
168
+ relationships?: RelationshipsInput;
169
+ resourceType?: string;
170
+ }
171
+ /**
172
+ * Options for update() method
173
+ */
174
+ export interface UpdateOptions {
175
+ relationships?: RelationshipsInput;
176
+ resourceType?: string;
177
+ }
178
+ /**
179
+ * SSIProjectApi - JSON:API Client for Project Entities
180
+ */
181
+ export declare class SSIProjectApi {
182
+ private baseUrl;
183
+ private apiBasePath;
184
+ private bearerToken;
185
+ private csrfToken;
186
+ private defaultHeaders;
187
+ /**
188
+ * Constructs an SSIProjectApi client.
189
+ *
190
+ * @param domain - The full URL prefix of the Drupal site (e.g., 'https://example.com').
191
+ * @param options - Optional configuration:
192
+ * - apiBasePath: Override the default API path (default: '/jsonapi/project/project')
193
+ * - timeout: Request timeout in milliseconds (default: 30000)
194
+ */
195
+ constructor(domain: string, options?: {
196
+ apiBasePath?: string;
197
+ timeout?: number;
198
+ });
199
+ /**
200
+ * Sets the Bearer token for authentication.
201
+ *
202
+ * @param token - The Bearer token (OAuth/JWT).
203
+ */
204
+ setBearerToken(token: string): void;
205
+ /**
206
+ * Gets the current Bearer token.
207
+ *
208
+ * @returns The Bearer token, or null if not set.
209
+ */
210
+ getBearerToken(): string | null;
211
+ /**
212
+ * Fetches a CSRF token from the Drupal session/token endpoint.
213
+ * The token is cached after the first fetch to avoid unnecessary requests.
214
+ *
215
+ * @returns Promise resolving to the CSRF token string.
216
+ *
217
+ * @throws Error if the request fails.
218
+ *
219
+ * @private
220
+ */
221
+ private getCsrfToken;
222
+ /**
223
+ * Clears the cached CSRF token, forcing a fresh fetch on the next write operation.
224
+ * This may be useful if the token expires or becomes invalid.
225
+ */
226
+ clearCsrfToken(): void;
227
+ /**
228
+ * Lists project entities with optional filtering, sorting, and pagination.
229
+ *
230
+ * @param options - List options:
231
+ * - filters: Filter conditions (e.g., { status: 'active' } or { created: { operator: '>', value: '2024-01-01' } })
232
+ * - sort: Sort fields (e.g., ['-created', 'title'] for descending created, ascending title)
233
+ * - pagination: Pagination options (offset, limit; max limit: 50)
234
+ * - include: Related resources to include (e.g., ['owner', 'tags'])
235
+ * - fields: Sparse fieldsets to limit returned fields
236
+ *
237
+ * @returns Promise resolving to the JSON:API document with projects.
238
+ *
239
+ * @throws Error if the request fails.
240
+ */
241
+ list(options?: ListOptions): Promise<JsonApiDocument>;
242
+ /**
243
+ * Retrieves a single project entity by UUID.
244
+ *
245
+ * The API endpoint is constructed as: baseUrl + apiBasePath + "/" + uuid
246
+ * Example: https://example.com/jsonapi/project/project/550e8400-e29b-41d4-a716-446655440000
247
+ *
248
+ * @param uuid - The UUID of the project entity (NOT the project ID).
249
+ * Must be a valid UUID string (e.g., '550e8400-e29b-41d4-a716-446655440000').
250
+ * @param options - Get options:
251
+ * - include: Related resources to include (e.g., ['owner', 'tags'])
252
+ * - fields: Sparse fieldsets to limit returned fields
253
+ *
254
+ * @returns Promise resolving to the JSON:API document with the project.
255
+ *
256
+ * @throws Error if the request fails or entity is not found.
257
+ */
258
+ get(uuid: string, options?: GetOptions): Promise<JsonApiDocument>;
259
+ /**
260
+ * Creates a new project entity.
261
+ *
262
+ * @param attributes - Entity attributes (e.g., { title: 'My Project', status: 'active' }).
263
+ * @param options - Create options:
264
+ * - relationships: Entity relationships
265
+ * - resourceType: The resource type (default: 'project--project')
266
+ *
267
+ * @returns Promise resolving to the JSON:API document with the created entity.
268
+ *
269
+ * @throws Error if the request fails or validation errors occur.
270
+ */
271
+ create(attributes: Record<string, unknown>, options?: CreateOptions): Promise<JsonApiDocument>;
272
+ /**
273
+ * Updates an existing project entity.
274
+ *
275
+ * The API endpoint is constructed as: baseUrl + apiBasePath + "/" + uuid
276
+ * Example: https://example.com/jsonapi/project/project/550e8400-e29b-41d4-a716-446655440000
277
+ *
278
+ * @param uuid - The UUID of the project entity to update (NOT the project ID).
279
+ * Must be a valid UUID string (e.g., '550e8400-e29b-41d4-a716-446655440000').
280
+ * @param attributes - Attributes to update (partial updates supported).
281
+ * @param options - Update options:
282
+ * - relationships: Relationships to update (optional)
283
+ * - resourceType: The resource type (default: 'project--project')
284
+ *
285
+ * @returns Promise resolving to the JSON:API document with the updated entity.
286
+ *
287
+ * @throws Error if the request fails or validation errors occur.
288
+ */
289
+ update(uuid: string, attributes: Record<string, unknown>, options?: UpdateOptions): Promise<JsonApiDocument>;
290
+ /**
291
+ * Deletes a project entity.
292
+ *
293
+ * The API endpoint is constructed as: baseUrl + apiBasePath + "/" + uuid
294
+ * Example: https://example.com/jsonapi/project/project/550e8400-e29b-41d4-a716-446655440000
295
+ *
296
+ * @param uuid - The UUID of the project entity to delete (NOT the project ID).
297
+ * Must be a valid UUID string (e.g., '550e8400-e29b-41d4-a716-446655440000').
298
+ *
299
+ * @returns Promise resolving to true if deletion was successful.
300
+ *
301
+ * @throws Error if the request fails.
302
+ */
303
+ delete(uuid: string): Promise<boolean>;
304
+ /**
305
+ * Makes an HTTP request to the API and returns the parsed JSON:API document.
306
+ *
307
+ * @param method - HTTP method (GET, POST, PATCH).
308
+ * @param url - The full URL.
309
+ * @param body - Request body (for POST/PATCH).
310
+ *
311
+ * @returns Promise resolving to the parsed JSON:API document.
312
+ *
313
+ * @throws Error if the request fails.
314
+ *
315
+ * @private
316
+ */
317
+ private request;
318
+ /**
319
+ * Makes a raw HTTP request to the API and returns the Response object.
320
+ *
321
+ * @param method - HTTP method (GET, POST, PATCH, DELETE).
322
+ * @param url - The full URL.
323
+ * @param body - Request body (for POST/PATCH).
324
+ *
325
+ * @returns Promise resolving to the Response object.
326
+ *
327
+ * @throws Error if the request fails (network errors, etc.).
328
+ *
329
+ * @private
330
+ */
331
+ private requestRaw;
332
+ /**
333
+ * Parses error response from JSON:API.
334
+ *
335
+ * @param response - The HTTP response.
336
+ *
337
+ * @returns Promise resolving to the error data.
338
+ *
339
+ * @private
340
+ */
341
+ private parseErrorResponse;
342
+ /**
343
+ * Parses error response from text string.
344
+ *
345
+ * @param text - The response text.
346
+ *
347
+ * @returns The error data, or null if parsing fails.
348
+ *
349
+ * @private
350
+ */
351
+ private parseErrorResponseFromText;
352
+ /**
353
+ * Creates an error from JSON:API error response.
354
+ *
355
+ * @param errorData - The error data.
356
+ * @param status - HTTP status code.
357
+ * @param statusText - HTTP status text.
358
+ *
359
+ * @returns Error instance.
360
+ *
361
+ * @private
362
+ */
363
+ private createError;
364
+ /**
365
+ * Builds filter query parameters from a filter object.
366
+ *
367
+ * @param filters - Filter conditions.
368
+ *
369
+ * @returns Query parameters for filters.
370
+ *
371
+ * @private
372
+ */
373
+ private buildFilterParams;
374
+ /**
375
+ * Formats relationships for JSON:API format.
376
+ *
377
+ * @param relationships - Relationships input.
378
+ *
379
+ * @returns Formatted relationships.
380
+ *
381
+ * @private
382
+ */
383
+ private formatRelationships;
384
+ }