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