@apolitical/sdk 8.0.2 → 8.1.0-ld.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.
Files changed (2) hide show
  1. package/lib/index.d.ts +349 -0
  2. package/package.json +4 -2
package/lib/index.d.ts ADDED
@@ -0,0 +1,349 @@
1
+ interface LoadSdkOptions {
2
+ contentContext: { apiKey: string; previewKey: string; location: string };
3
+ errorsContext: { apiKey: string; serviceName: string };
4
+ gtmContext: { configs: { [key: string]: any } };
5
+ origin: string;
6
+ }
7
+
8
+ interface PeopleAPIUser {
9
+ [key: string]: any;
10
+ }
11
+
12
+ interface PeopleAPIUserCourse {
13
+ [key: string]: any;
14
+ }
15
+
16
+ interface PeopleAPIUserEvents {
17
+ [key: string]: any;
18
+ }
19
+
20
+ interface PeopleAPIUserLikes {
21
+ [key: string]: any;
22
+ }
23
+
24
+ interface PeopleAPIUserLesson {
25
+ [key: string]: any;
26
+ }
27
+
28
+ interface PeopleAPIUserProduct {
29
+ [key: string]: any;
30
+ }
31
+
32
+ interface PeopleAPIUserRating {
33
+ [key: string]: any;
34
+ }
35
+
36
+ interface PeopleAPIUserReferral {
37
+ [key: string]: any;
38
+ }
39
+
40
+ interface SocialsAPIActivity {
41
+ [key: string]: any;
42
+ }
43
+
44
+ interface SocialsAPICommunity {
45
+ [key: string]: any;
46
+ }
47
+
48
+ interface SocialsAPIReaction {
49
+ [key: string]: any;
50
+ }
51
+
52
+ interface SocialsAPILike {
53
+ slug: string;
54
+ activityId: string;
55
+ reactionId: string;
56
+ }
57
+
58
+ interface PostResponse {
59
+ created: true;
60
+ }
61
+
62
+ interface DeleteResponse {
63
+ removed?: true;
64
+ deleted?: true;
65
+ }
66
+
67
+ interface QueryParams {
68
+ [key: string]: string | number | boolean;
69
+ }
70
+
71
+ declare module '@apolitical/sdk' {
72
+ /**
73
+ * Loads the SDK using the provided options
74
+ *
75
+ * @param contentContext for setting up Contentful
76
+ * @param errorsContext for setting up GCP error logging
77
+ * @param gtmContext for setting up Google Tag Manager
78
+ * @param origin the origin of the page
79
+ */
80
+ export default function loadSdk(options: LoadSdkOptions): string;
81
+
82
+ /**
83
+ * Decodes a base64 string to plain string
84
+ * @param {String} value - The base64 string
85
+ * @return {String} value - The plain string
86
+ */
87
+ export function decodeBase64(value: string): string;
88
+
89
+ /**
90
+ * Logs the error message and reports the error to GCP
91
+ * @param {Error} error - The error object
92
+ */
93
+ export function reportError(error: Error): void;
94
+
95
+ //
96
+ // People API resources
97
+ // ----------------------------------------------------------------------
98
+ export const people: {
99
+ bulkEnrolments: {
100
+ /**
101
+ * Lists bulk enrolments from the People API
102
+ * @param {Object} params - Params to be passed to the request
103
+ * @return {Array} data - JSON array returned by the API
104
+ */
105
+ list: (params: QueryParams) => Promise<any[]>;
106
+ };
107
+ // TODO: add types for the rest of the handlers
108
+ handlers: {};
109
+ registrations: {
110
+ /**
111
+ * Lists registrations from the People API
112
+ * @param {Object} params - Params to be passed to the request
113
+ * @return {Object} data - JSON object returned by the API
114
+ */
115
+ list: (params: QueryParams) => Promise<any>;
116
+ };
117
+ users: {
118
+ /**
119
+ * Fetches a user by id
120
+ * @param {String} id - The id of the user
121
+ * @return {Promise} user - The user object
122
+ */
123
+ read: (id: string) => Promise<PeopleAPIUser>;
124
+ /**
125
+ * Lists users from the People API based on an array of ids
126
+ * @param {String} ids - The ids of the users (needs at least two)
127
+ * @return {Array} data - array with JSON objects returned by the API
128
+ */
129
+ list: (ids: string[]) => Promise<PeopleAPIUser[]>;
130
+ /**
131
+ * Updates a user in the People API
132
+ * @param {String} id - The id of the user
133
+ * @param {Object} payload - The data to update the user with
134
+ * @return {Promise} updated - Whether the user was updated or not
135
+ */
136
+ update: (id: string, payload: Partial<PeopleAPIUser>) => Promise<boolean>;
137
+ };
138
+ userCourses: {
139
+ /**
140
+ * Creates a user course in People API
141
+ * @param {Object} payload - The data to create the user course with
142
+ */
143
+ create: (payload: PeopleAPIUserCourse) => Promise<void>;
144
+ /**
145
+ * Lists user's courses from the People API based on the supplied params
146
+ * @param {String} params - The params to use to filter the courses
147
+ * @return {Array} data - array with JSON objects returned by the API
148
+ */
149
+ list: (params: QueryParams) => Promise<PeopleAPIUserCourse[]>;
150
+ /**
151
+ * Updates a user course in the People API
152
+ * @param {String} courseId - The id of the user course
153
+ * @param {Object} payload - The data to update the user course with
154
+ */
155
+ update: (courseId: string, payload: Partial<PeopleAPIUserCourse>) => Promise<void>;
156
+ };
157
+ userEvents: {
158
+ /**
159
+ * Lists user's events from the People API based on the supplied params
160
+ * * @param {String} params - The params to use to filter the events
161
+ * @return {Array} data - array with JSON objects returned by the API
162
+ */
163
+ list: (params: QueryParams) => Promise<PeopleAPIUserEvents[]>;
164
+ };
165
+ userLikes: {
166
+ /**
167
+ * Lists user's likes from the People API based on the supplied params
168
+ * @param {String} params - The params to use to filter the likes
169
+ * @return {Array} data - array with JSON objects returned by the API
170
+ */
171
+ list: (params: QueryParams) => Promise<PeopleAPIUserLikes[]>;
172
+ };
173
+ userLessons: {
174
+ /**
175
+ * Creates a user lesson in People API
176
+ * @param {Object} payload - The data to create the user lesson with
177
+ */
178
+ create: (payload: PeopleAPIUserLesson) => Promise<PeopleAPIUserLesson>;
179
+ /**
180
+ * Lists user's lessons from the People API based on the supplied params
181
+ * @param {String} params - The params to use to filter the lessons
182
+ * @return {Array} data - array with JSON objects returned by the API
183
+ */
184
+ list: (params: QueryParams) => Promise<PeopleAPIUserLesson[]>;
185
+ };
186
+ userProducts: {
187
+ /**
188
+ * Creates a user product in People API
189
+ * @param {Object} payload - The data to create the user product with
190
+ */
191
+ create: (payload: PeopleAPIUserProduct) => Promise<PeopleAPIUserProduct>;
192
+ /**
193
+ * Lists user's products from the People API based on the supplied params
194
+ * @param {String} params - The params to use to filter the products
195
+ * @return {Array} data - array with JSON objects returned by the API
196
+ */
197
+ list: (params: QueryParams) => Promise<PeopleAPIUserProduct[]>;
198
+ /**
199
+ * Updates a user product in the People API
200
+ * @param {String} productId - The id of the user product
201
+ * @param {Object} payload - The data to update the user product with
202
+ */
203
+ update: (productId: string, payload: Partial<PeopleAPIUserProduct>) => Promise<void>;
204
+ };
205
+ userRatings: {
206
+ /**
207
+ * Creates a user rating in People API
208
+ * @param {Object} payload - The data to create the user rating with
209
+ */
210
+ create: (payload: PeopleAPIUserRating) => Promise<PeopleAPIUserRating>;
211
+ /**
212
+ * Updates a user rating in the People API
213
+ * @param {String} ratingId - The id of the user rating
214
+ * @param {Object} payload - The data to update the user rating with
215
+ */
216
+ update: (ratingId: string, payload: Partial<PeopleAPIUserRating>) => Promise<void>;
217
+ };
218
+ userReferrals: {
219
+ /**
220
+ * Lists user's referrals from the People API based on the supplied params
221
+ * @param {String} params - The params to use to filter the referrals
222
+ * @return {Array} data - array with JSON objects returned by the API
223
+ */
224
+ list: (params: QueryParams) => Promise<PeopleAPIUserReferral[]>;
225
+ };
226
+ };
227
+
228
+ //
229
+ // Social API resources
230
+ // ----------------------------------------------------------------------
231
+ export const socials: {
232
+ activities: {
233
+ /**
234
+ * Creates an activity in Socials API
235
+ * @param {String} slug - The slug of the community
236
+ * @param {Object} payload - The data to create the activity with
237
+ * @return {Promise} activity - The activity object
238
+ */
239
+ create: (slug: string, payload: SocialsAPIActivity) => Promise<SocialsAPIActivity>;
240
+ /**
241
+ * Fetches an activity by slug in Socials API
242
+ * @param {String} slug - The slug of the community
243
+ * @param {String} activityId - The ID of the activity
244
+ * @return {Promise} activity - The activity object
245
+ */
246
+ read: (slug: string, activityId: string) => Promise<SocialsAPIActivity>;
247
+ /**
248
+ * Lists activities from the Socials API based on params
249
+ * @param {String} slug - The slug of the community
250
+ * @param {Object} params - Params to be passed to the request
251
+ * @return {Array} data - array with JSON objects returned by the API
252
+ */
253
+ list: (slug: string, params: QueryParams) => Promise<SocialsAPIActivity[]>;
254
+ /**
255
+ * Updates an activity in the Socials API
256
+ * @param {String} slug - The slug of the community
257
+ * @param {String} activityId - The ID of the activity
258
+ * @param {Object} payload - The data to update the activity with
259
+ * @return {Promise} activity - The activity object
260
+ */
261
+ update: (slug: string, activityId: string, payload: Partial<SocialsAPIActivity>) => Promise<SocialsAPIActivity>;
262
+ /**
263
+ * Removes an activity in the Socials API
264
+ * @param {String} slug - The slug of the community
265
+ * @param {String} activityId - The ID of the activity
266
+ * @return {Promise} activity - The activity object
267
+ */
268
+ remove: (slug: string, activityId: string) => Promise<DeleteResponse>;
269
+ };
270
+ communities: {
271
+ /**
272
+ * Fetches a community by slug in Socials API
273
+ * @param {String} slug - The slug of the community
274
+ * @return {Promise} community - The community object
275
+ */
276
+ read: (slug: string) => Promise<SocialsAPICommunity>;
277
+ /**
278
+ * Allows a user to join a community in Socials API
279
+ * @param {String} slug - The slug of the community
280
+ * @param {Object} payload - The data to join the community with
281
+ * @return {Promise} data - The join object
282
+ */
283
+ join: (slug: string, payload: SocialsAPICommunity) => Promise<PostResponse>;
284
+ /**
285
+ * Allows a user to leave a community in the Socials API
286
+ * @param {String} slug - The slug of the community
287
+ * @return {Promise} data - The deletion object
288
+ */
289
+ remove: (slug: string) => Promise<DeleteResponse>;
290
+ };
291
+ likes: {
292
+ /**
293
+ * Creates a like on a reaction in Socials API
294
+ * @param {String} slug - The slug of the community
295
+ * @param {String} activityId - The ID of the activity
296
+ * @param {String} reactionId - The ID of the reaction
297
+ * @return {Promise} reaction - The reaction object
298
+ */
299
+ create: (payload: SocialsAPILike) => Promise<SocialsAPIReaction>;
300
+ /**
301
+ * Allows a user to remove like on a reaction in the Socials API
302
+ * @param {String} slug - The slug of the community
303
+ * @param {String} reactionId - The ID of the reaction
304
+ * @return {Promise} data - The deletion object
305
+ */
306
+ remove: (payload: Exclude<SocialsAPILike, 'activityId'>) => Promise<DeleteResponse>;
307
+ };
308
+ reactions: {
309
+ /**
310
+ * Creates a reaction on a reaction in Socials API
311
+ * @param {String} slug - The slug of the community
312
+ * @param {String} activityId - The ID of the activity
313
+ * @param {String} reactionId - The ID of the reaction
314
+ * @return {Promise} reaction - The reaction object
315
+ */
316
+ create: (slug: string, activityId: string, reactionId: string) => Promise<SocialsAPIReaction>;
317
+ /**
318
+ * Removes a reaction on a reaction in the Socials API
319
+ * @param {String} slug - The slug of the community
320
+ * @param {String} reactionId - The ID of the reaction
321
+ * @return {Promise} data - The deletion object
322
+ */
323
+ remove: (slug: string, reactionId: string) => Promise<DeleteResponse>;
324
+
325
+ /**
326
+ * Updates a reaction on a reaction in the Socials API
327
+ * @param {String} slug - The slug of the community
328
+ * @param {String} activityId - The ID of the activity
329
+ * @param {String} reactionId - The ID of the reaction
330
+ * @param {Object} payload - The data to update the reaction with
331
+ */
332
+ update: (
333
+ slug: string,
334
+ activityId: string,
335
+ reactionId: string,
336
+ payload: Partial<SocialsAPIReaction>,
337
+ ) => Promise<SocialsAPIReaction>;
338
+
339
+ /**
340
+ * Lists reactions from the Socials API based on params
341
+ * @param {String} slug - The slug of the community
342
+ * @param {Object} payload - The data to create the reaction with
343
+ * @param {Object} params - Params to be passed to the request
344
+ * @return {Array}
345
+ */
346
+ list: (slug: string, payload: Exclude<SocialsAPILike, 'slug'>, params: any) => Promise<SocialsAPIReaction[]>;
347
+ };
348
+ };
349
+ }
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@apolitical/sdk",
3
- "version": "8.0.2",
3
+ "version": "8.1.0-ld.0",
4
4
  "description": "Browser library to interact with Apolitical's APIs",
5
5
  "author": "Apolitical Group Limited <engineering@apolitical.co>",
6
6
  "license": "MIT",
7
7
  "main": "build/index.js",
8
8
  "files": [
9
- "build/**"
9
+ "build/**",
10
+ "lib/index.d.ts"
10
11
  ],
12
+ "types": "lib/index.d.ts",
11
13
  "scripts": {
12
14
  "test": "jest --runInBand",
13
15
  "unit-test": "jest test/unit/* --bail --runInBand --passWithNoTests",