@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
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # Serial Subscriptions Interface - Platform Integration
@@ -0,0 +1,343 @@
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
30
+ * const project = await client.get('uuid-here', ['owner', 'tags']);
31
+ *
32
+ * // Create a project
33
+ * const newProject = await client.create(
34
+ * { title: 'New Project', status: 'active' },
35
+ * { owner: { type: 'user--user', id: 'user-uuid' } }
36
+ * );
37
+ *
38
+ * // Update a project
39
+ * await client.update('uuid-here', { status: 'completed' });
40
+ *
41
+ * // Delete a project
42
+ * await client.delete('uuid-here');
43
+ * ```
44
+ */
45
+ /**
46
+ * JSON:API Resource Identifier
47
+ */
48
+ export interface ResourceIdentifier {
49
+ type: string;
50
+ id: string;
51
+ }
52
+ /**
53
+ * JSON:API Relationship Data
54
+ */
55
+ export type RelationshipData = ResourceIdentifier | ResourceIdentifier[];
56
+ /**
57
+ * JSON:API Relationship
58
+ */
59
+ export interface Relationship {
60
+ data: RelationshipData;
61
+ }
62
+ /**
63
+ * JSON:API Resource Object
64
+ */
65
+ export interface JsonApiResource {
66
+ type: string;
67
+ id?: string;
68
+ attributes?: Record<string, unknown>;
69
+ relationships?: Record<string, Relationship>;
70
+ }
71
+ /**
72
+ * JSON:API Document
73
+ */
74
+ export interface JsonApiDocument {
75
+ data: JsonApiResource | JsonApiResource[];
76
+ included?: JsonApiResource[];
77
+ links?: {
78
+ self?: string;
79
+ first?: string;
80
+ last?: string;
81
+ next?: string;
82
+ prev?: string;
83
+ };
84
+ meta?: {
85
+ count?: number;
86
+ [key: string]: unknown;
87
+ };
88
+ }
89
+ /**
90
+ * JSON:API Error
91
+ */
92
+ export interface JsonApiError {
93
+ status?: string;
94
+ code?: string;
95
+ title?: string;
96
+ detail?: string;
97
+ source?: {
98
+ pointer?: string;
99
+ parameter?: string;
100
+ };
101
+ }
102
+ /**
103
+ * JSON:API Error Document
104
+ */
105
+ export interface JsonApiErrorDocument {
106
+ errors: JsonApiError[];
107
+ }
108
+ /**
109
+ * Filter condition with operator
110
+ */
111
+ export interface FilterCondition {
112
+ operator: string;
113
+ value: string | number | string[] | number[];
114
+ }
115
+ /**
116
+ * Filter parameters
117
+ */
118
+ export type FilterParams = Record<string, string | number | FilterCondition>;
119
+ /**
120
+ * Sort field (with optional '-' prefix for descending)
121
+ */
122
+ export type SortField = string;
123
+ /**
124
+ * Pagination options
125
+ */
126
+ export interface PaginationOptions {
127
+ offset?: number;
128
+ limit?: number;
129
+ }
130
+ /**
131
+ * Sparse fieldset options
132
+ */
133
+ export type SparseFieldsetOptions = Record<string, string[]>;
134
+ /**
135
+ * Relationship format for create/update
136
+ */
137
+ export interface RelationshipInput {
138
+ type: string;
139
+ id: string;
140
+ }
141
+ /**
142
+ * Relationships for create/update
143
+ */
144
+ export type RelationshipsInput = Record<string, RelationshipInput | RelationshipInput[]>;
145
+ /**
146
+ * Options for list() method
147
+ */
148
+ export interface ListOptions {
149
+ filters?: FilterParams;
150
+ sort?: SortField[];
151
+ pagination?: PaginationOptions;
152
+ include?: string[];
153
+ fields?: SparseFieldsetOptions;
154
+ }
155
+ /**
156
+ * Options for get() method
157
+ */
158
+ export interface GetOptions {
159
+ include?: string[];
160
+ fields?: SparseFieldsetOptions;
161
+ }
162
+ /**
163
+ * Options for create() method
164
+ */
165
+ export interface CreateOptions {
166
+ relationships?: RelationshipsInput;
167
+ resourceType?: string;
168
+ }
169
+ /**
170
+ * Options for update() method
171
+ */
172
+ export interface UpdateOptions {
173
+ relationships?: RelationshipsInput;
174
+ resourceType?: string;
175
+ }
176
+ /**
177
+ * SSIProjectApi - JSON:API Client for Project Entities
178
+ */
179
+ export declare class SSIProjectApi {
180
+ private baseUrl;
181
+ private apiBasePath;
182
+ private bearerToken;
183
+ private defaultHeaders;
184
+ /**
185
+ * Constructs an SSIProjectApi client.
186
+ *
187
+ * @param domain - The full URL prefix of the Drupal site (e.g., 'https://example.com').
188
+ * @param options - Optional configuration:
189
+ * - apiBasePath: Override the default API path (default: '/jsonapi/project/project')
190
+ * - timeout: Request timeout in milliseconds (default: 30000)
191
+ */
192
+ constructor(domain: string, options?: {
193
+ apiBasePath?: string;
194
+ timeout?: number;
195
+ });
196
+ /**
197
+ * Sets the Bearer token for authentication.
198
+ *
199
+ * @param token - The Bearer token (OAuth/JWT).
200
+ */
201
+ setBearerToken(token: string): void;
202
+ /**
203
+ * Gets the current Bearer token.
204
+ *
205
+ * @returns The Bearer token, or null if not set.
206
+ */
207
+ getBearerToken(): string | null;
208
+ /**
209
+ * Lists project entities with optional filtering, sorting, and pagination.
210
+ *
211
+ * @param options - List options:
212
+ * - filters: Filter conditions (e.g., { status: 'active' } or { created: { operator: '>', value: '2024-01-01' } })
213
+ * - sort: Sort fields (e.g., ['-created', 'title'] for descending created, ascending title)
214
+ * - pagination: Pagination options (offset, limit; max limit: 50)
215
+ * - include: Related resources to include (e.g., ['owner', 'tags'])
216
+ * - fields: Sparse fieldsets to limit returned fields
217
+ *
218
+ * @returns Promise resolving to the JSON:API document with projects.
219
+ *
220
+ * @throws Error if the request fails.
221
+ */
222
+ list(options?: ListOptions): Promise<JsonApiDocument>;
223
+ /**
224
+ * Retrieves a single project entity by UUID.
225
+ *
226
+ * @param uuid - The UUID of the project entity.
227
+ * @param options - Get options:
228
+ * - include: Related resources to include
229
+ * - fields: Sparse fieldsets to limit returned fields
230
+ *
231
+ * @returns Promise resolving to the JSON:API document with the project.
232
+ *
233
+ * @throws Error if the request fails or entity is not found.
234
+ */
235
+ get(uuid: string, options?: GetOptions): Promise<JsonApiDocument>;
236
+ /**
237
+ * Creates a new project entity.
238
+ *
239
+ * @param attributes - Entity attributes (e.g., { title: 'My Project', status: 'active' }).
240
+ * @param options - Create options:
241
+ * - relationships: Entity relationships
242
+ * - resourceType: The resource type (default: 'project--project')
243
+ *
244
+ * @returns Promise resolving to the JSON:API document with the created entity.
245
+ *
246
+ * @throws Error if the request fails or validation errors occur.
247
+ */
248
+ create(attributes: Record<string, unknown>, options?: CreateOptions): Promise<JsonApiDocument>;
249
+ /**
250
+ * Updates an existing project entity.
251
+ *
252
+ * @param uuid - The UUID of the project entity to update.
253
+ * @param attributes - Attributes to update (partial updates supported).
254
+ * @param options - Update options:
255
+ * - relationships: Relationships to update (optional)
256
+ * - resourceType: The resource type (default: 'project--project')
257
+ *
258
+ * @returns Promise resolving to the JSON:API document with the updated entity.
259
+ *
260
+ * @throws Error if the request fails or validation errors occur.
261
+ */
262
+ update(uuid: string, attributes: Record<string, unknown>, options?: UpdateOptions): Promise<JsonApiDocument>;
263
+ /**
264
+ * Deletes a project entity.
265
+ *
266
+ * @param uuid - The UUID of the project entity to delete.
267
+ *
268
+ * @returns Promise resolving to true if deletion was successful.
269
+ *
270
+ * @throws Error if the request fails.
271
+ */
272
+ delete(uuid: string): Promise<boolean>;
273
+ /**
274
+ * Makes an HTTP request to the API and returns the parsed JSON:API document.
275
+ *
276
+ * @param method - HTTP method (GET, POST, PATCH).
277
+ * @param url - The full URL.
278
+ * @param body - Request body (for POST/PATCH).
279
+ *
280
+ * @returns Promise resolving to the parsed JSON:API document.
281
+ *
282
+ * @throws Error if the request fails.
283
+ *
284
+ * @private
285
+ */
286
+ private request;
287
+ /**
288
+ * Makes a raw HTTP request to the API and returns the Response object.
289
+ *
290
+ * @param method - HTTP method (GET, POST, PATCH, DELETE).
291
+ * @param url - The full URL.
292
+ * @param body - Request body (for POST/PATCH).
293
+ *
294
+ * @returns Promise resolving to the Response object.
295
+ *
296
+ * @throws Error if the request fails (network errors, etc.).
297
+ *
298
+ * @private
299
+ */
300
+ private requestRaw;
301
+ /**
302
+ * Parses error response from JSON:API.
303
+ *
304
+ * @param response - The HTTP response.
305
+ *
306
+ * @returns Promise resolving to the error data.
307
+ *
308
+ * @private
309
+ */
310
+ private parseErrorResponse;
311
+ /**
312
+ * Creates an error from JSON:API error response.
313
+ *
314
+ * @param errorData - The error data.
315
+ * @param status - HTTP status code.
316
+ * @param statusText - HTTP status text.
317
+ *
318
+ * @returns Error instance.
319
+ *
320
+ * @private
321
+ */
322
+ private createError;
323
+ /**
324
+ * Builds filter query parameters from a filter object.
325
+ *
326
+ * @param filters - Filter conditions.
327
+ *
328
+ * @returns Query parameters for filters.
329
+ *
330
+ * @private
331
+ */
332
+ private buildFilterParams;
333
+ /**
334
+ * Formats relationships for JSON:API format.
335
+ *
336
+ * @param relationships - Relationships input.
337
+ *
338
+ * @returns Formatted relationships.
339
+ *
340
+ * @private
341
+ */
342
+ private formatRelationships;
343
+ }