@superlikers/microsites-api 0.1.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,723 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, makeEnvironmentProviders, inject, EnvironmentInjector, runInInjectionContext, Service } from '@angular/core';
3
+ import { HttpParams, HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
4
+ import { map, catchError, throwError } from 'rxjs';
5
+
6
+ /** @internal Holds the normalized config. Not part of the public API. */
7
+ const MICROSITES_API_CONFIG = new InjectionToken('MICROSITES_API_CONFIG');
8
+ /**
9
+ * Configures `@superlikers/microsites-api` for the application.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // app.config.ts
14
+ * export const appConfig: ApplicationConfig = {
15
+ * providers: [provideMicrositesApi({ baseUrl: environment.baseUrl })]
16
+ * }
17
+ * ```
18
+ */
19
+ function provideMicrositesApi(config) {
20
+ return makeEnvironmentProviders([{ provide: MICROSITES_API_CONFIG, useValue: normalizeConfig(config) }]);
21
+ }
22
+ /** @internal Reads the config inside the library, with a helpful error when it is missing. */
23
+ function injectMicrositesApiConfig() {
24
+ const config = inject(MICROSITES_API_CONFIG, { optional: true });
25
+ if (!config) {
26
+ throw new Error('[@superlikers/microsites-api] Missing configuration. Add provideMicrositesApi({ baseUrl }) to your app.config.ts providers.');
27
+ }
28
+ return config;
29
+ }
30
+ function normalizeConfig(config) {
31
+ const baseUrl = config.baseUrl?.trim().replace(/\/+$/, '') ?? '';
32
+ if (!URL.canParse(baseUrl) || !/^https?:$/.test(new URL(baseUrl).protocol)) {
33
+ throw new Error(`[@superlikers/microsites-api] Invalid baseUrl "${config.baseUrl}". Expected an absolute http(s) URL, e.g. https://4x.superlikerslabs.com`);
34
+ }
35
+ return { ...config, baseUrl };
36
+ }
37
+
38
+ /**
39
+ * Error thrown by every `@superlikers/microsites-api` request.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * try {
44
+ * await firstValueFrom(sessionService.login(data))
45
+ * } catch (error) {
46
+ * if (isApiError(error)) this.message.set(error.message)
47
+ * }
48
+ * ```
49
+ */
50
+ class ApiError extends Error {
51
+ name = 'ApiError';
52
+ /** HTTP status. `0` means the request never reached the server (network, CORS, offline). */
53
+ status;
54
+ /** Backend error code (`code_error`), e.g. `140`. `null` when the backend did not send one. */
55
+ code;
56
+ /** Validation errors by field name, e.g. `{ email: 'is invalid' }`. Empty when there are none. */
57
+ fieldErrors;
58
+ /** URL of the failed request. */
59
+ url;
60
+ /**
61
+ * `true` when the server answered with something that is not JSON (e.g. an HTML page).
62
+ * Happens when a module is disabled for the campaign: the backend redirects to the site instead of answering.
63
+ */
64
+ isInvalidResponse;
65
+ constructor(response) {
66
+ const invalidResponse = isParseFailure(response);
67
+ const body = invalidResponse ? {} : readBody(response.error);
68
+ super(body.message || defaultMessage(response.status, invalidResponse), { cause: response });
69
+ this.status = response.status;
70
+ this.code = typeof body.code_error === 'number' ? body.code_error : null;
71
+ this.fieldErrors = body.errors ?? {};
72
+ this.url = response.url;
73
+ this.isInvalidResponse = invalidResponse;
74
+ }
75
+ get isNetworkError() {
76
+ return this.status === 0;
77
+ }
78
+ get isUnauthorized() {
79
+ return this.status === 401;
80
+ }
81
+ }
82
+ function isApiError(error) {
83
+ return error instanceof ApiError;
84
+ }
85
+ function readBody(error) {
86
+ return typeof error === 'object' && error !== null ? error : {};
87
+ }
88
+ /**
89
+ * A 2xx body HttpClient could not parse: the fetch backend (Angular's default) reports the `SyntaxError`
90
+ * itself, the XHR backend wraps it as `{ error: SyntaxError, text }`.
91
+ */
92
+ function isParseFailure(response) {
93
+ if (response.status < 200 || response.status >= 300)
94
+ return false;
95
+ const error = response.error;
96
+ return error instanceof SyntaxError || (typeof error === 'object' && error !== null && error.error instanceof SyntaxError);
97
+ }
98
+ function defaultMessage(status, invalidResponse) {
99
+ if (invalidResponse)
100
+ return 'The server did not answer with JSON. The module may be disabled for this campaign.';
101
+ return status === 0 ? 'Could not reach the server. Check your connection.' : `Request failed with status ${status}.`;
102
+ }
103
+
104
+ /**
105
+ * Encodes every reserved character. Angular's default codec leaves `+` unencoded,
106
+ * which the backend decodes as a space (`ana+test@mail.com` → `ana test@mail.com`).
107
+ */
108
+ class StrictUrlCodec {
109
+ encodeKey(key) {
110
+ return encodeURIComponent(key);
111
+ }
112
+ encodeValue(value) {
113
+ return encodeURIComponent(value);
114
+ }
115
+ decodeKey(key) {
116
+ return decodeURIComponent(key);
117
+ }
118
+ decodeValue(value) {
119
+ return decodeURIComponent(value);
120
+ }
121
+ }
122
+ const codec = new StrictUrlCodec();
123
+ /**
124
+ * @internal Builds query params: arrays use `key[]`, plain objects use `key[subkey]`,
125
+ * empty values are skipped. `{ page: 2, tags: ['a', 'b'], q: undefined }` → `page=2&tags[]=a&tags[]=b`.
126
+ */
127
+ function toHttpParams(params) {
128
+ let httpParams = new HttpParams({ encoder: codec });
129
+ for (const [key, value] of Object.entries(params)) {
130
+ if (Array.isArray(value)) {
131
+ for (const item of value) {
132
+ if (item != null)
133
+ httpParams = httpParams.append(`${key}[]`, String(item));
134
+ }
135
+ }
136
+ else if (isPlainObject(value)) {
137
+ for (const [subkey, subvalue] of Object.entries(value)) {
138
+ if (subvalue != null)
139
+ httpParams = httpParams.append(`${key}[${subkey}]`, String(subvalue));
140
+ }
141
+ }
142
+ else if (value != null) {
143
+ httpParams = httpParams.append(key, String(value));
144
+ }
145
+ }
146
+ return httpParams;
147
+ }
148
+ function isPlainObject(value) {
149
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
150
+ }
151
+ /**
152
+ * @internal Casts a params object with a named nested type (e.g. a `date_filter: DateFilter` field) to
153
+ * {@link ApiParams}. Named types without an index signature aren't structurally assignable to `ApiParams`
154
+ * even when every property matches; `toHttpParams` handles arbitrary shapes safely at runtime regardless.
155
+ */
156
+ function asApiParams(params) {
157
+ return params;
158
+ }
159
+
160
+ /**
161
+ * @internal The library's only gateway to the microsite backend.
162
+ * Every domain service makes its requests through here; nothing else uses `HttpClient`.
163
+ */
164
+ class ApiClient {
165
+ #http = inject(HttpClient);
166
+ #injector = inject(EnvironmentInjector);
167
+ #config = injectMicrositesApiConfig();
168
+ get(path, options) {
169
+ const url = this.#url(path);
170
+ return this.#handleErrors(this.#http.get(url, this.#options(options)), url);
171
+ }
172
+ post(path, body, options) {
173
+ const url = this.#url(path);
174
+ return this.#handleErrors(this.#http.post(url, body, this.#options(options)), url);
175
+ }
176
+ put(path, body, options) {
177
+ const url = this.#url(path);
178
+ return this.#handleErrors(this.#http.put(url, body, this.#options(options)), url);
179
+ }
180
+ patch(path, body, options) {
181
+ const url = this.#url(path);
182
+ return this.#handleErrors(this.#http.patch(url, body, this.#options(options)), url);
183
+ }
184
+ delete(path, options) {
185
+ const url = this.#url(path);
186
+ return this.#handleErrors(this.#http.delete(url, this.#options(options)), url);
187
+ }
188
+ /** `/sessions/login` → `https://4x.superlikerslabs.com/sessions/login` */
189
+ #url(path) {
190
+ return `${this.#config.baseUrl}/${path.replace(/^\/+/, '')}`;
191
+ }
192
+ /** What every request shares. `Content-Type` is left to HttpClient (JSON for objects, none for FormData). */
193
+ #options(options) {
194
+ return {
195
+ params: options?.params instanceof HttpParams ? options.params : toHttpParams(options?.params ?? {}),
196
+ headers: new HttpHeaders({ Accept: 'application/json', ...options?.headers }),
197
+ withCredentials: true
198
+ };
199
+ }
200
+ /**
201
+ * Turns every failure into an {@link ApiError} and notifies `onUnauthorized` on 401.
202
+ * Some endpoints report errors with HTTP 200 and `state: 'error'` (e.g. referral code validation);
203
+ * those are thrown as an `ApiError` with status 200 too, so callers only handle errors in one place.
204
+ */
205
+ #handleErrors(request, url) {
206
+ return request.pipe(map(body => {
207
+ if (isErrorBody(body))
208
+ throw new ApiError(new HttpErrorResponse({ status: 200, statusText: 'OK', error: body, url }));
209
+ return body;
210
+ }), catchError((error) => {
211
+ if (!(error instanceof HttpErrorResponse))
212
+ return throwError(() => error);
213
+ const apiError = new ApiError(error);
214
+ const onUnauthorized = this.#config.onUnauthorized;
215
+ if (apiError.isUnauthorized && onUnauthorized)
216
+ runInInjectionContext(this.#injector, () => onUnauthorized(apiError));
217
+ return throwError(() => apiError);
218
+ }));
219
+ }
220
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ApiClient, deps: [], target: i0.ɵɵFactoryTarget.Service });
221
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: ApiClient });
222
+ }
223
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ApiClient, decorators: [{
224
+ type: Service
225
+ }] });
226
+ function isErrorBody(body) {
227
+ return typeof body === 'object' && body !== null && !Array.isArray(body) && body.state === 'error';
228
+ }
229
+
230
+ /** Achievements earned by participants (goal and badge achievements). */
231
+ class AchievementsService {
232
+ #api = inject(ApiClient);
233
+ list(params = {}) {
234
+ return this.#api.get('/achievements/index', { params: asApiParams({ ...params, view: params.view ?? 'list' }) });
235
+ }
236
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: AchievementsService, deps: [], target: i0.ɵɵFactoryTarget.Service });
237
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: AchievementsService });
238
+ }
239
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: AchievementsService, decorators: [{
240
+ type: Service
241
+ }] });
242
+
243
+ /** Photo and document uploads. */
244
+ class ActivitiesService {
245
+ #api = inject(ApiClient);
246
+ uploadPhoto({ file, filename, category }) {
247
+ const body = new FormData();
248
+ if (filename)
249
+ body.append('upload_photo[image]', file, filename);
250
+ else
251
+ body.append('upload_photo[image]', file);
252
+ if (category != null)
253
+ body.append('upload_photo[category]', category);
254
+ return this.#api.post('/mod/photos', body);
255
+ }
256
+ uploadDocument({ file, category }) {
257
+ const body = new FormData();
258
+ body.append('upload_document[document]', file);
259
+ if (category)
260
+ body.append('upload_document[category]', category);
261
+ return this.#api.post('/mod/documents', body);
262
+ }
263
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ActivitiesService, deps: [], target: i0.ɵɵFactoryTarget.Service });
264
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: ActivitiesService });
265
+ }
266
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ActivitiesService, decorators: [{
267
+ type: Service
268
+ }] });
269
+
270
+ /** Badges and the badges earned by a participant. */
271
+ class BadgesService {
272
+ #api = inject(ApiClient);
273
+ list(params = {}) {
274
+ return this.#api.get('/badges/index', { params: { ...params } });
275
+ }
276
+ get(id) {
277
+ return this.#api.get(`/badges/${id}/show`);
278
+ }
279
+ /** Badges earned by the logged participant, or by `uid` when given. */
280
+ getStats(uid) {
281
+ return this.#api.get('/badges/stats', { params: { participant_uid: uid } });
282
+ }
283
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: BadgesService, deps: [], target: i0.ɵɵFactoryTarget.Service });
284
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: BadgesService });
285
+ }
286
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: BadgesService, decorators: [{
287
+ type: Service
288
+ }] });
289
+
290
+ /** Blog posts (mod/blog activity). */
291
+ class BlogsService {
292
+ #api = inject(ApiClient);
293
+ list(params = {}) {
294
+ return this.#api.get('/mod/blog', { params: { ...params, page: params.page ?? 1 } });
295
+ }
296
+ get(id) {
297
+ return this.#api.get(`/mod/blog/${id}/show`);
298
+ }
299
+ create({ title, body, format, attached_file, category, tags, push_redirect_url }) {
300
+ const data = new FormData();
301
+ data.append('blog_post[title]', title);
302
+ data.append('blog_post[body]', body);
303
+ data.append('blog_post[format]', format ?? 'text');
304
+ if (attached_file)
305
+ data.append('blog_post[attached_file]', attached_file);
306
+ if (category)
307
+ data.append('blog_post[category]', category);
308
+ if (push_redirect_url)
309
+ data.append('blog_post[push_redirect_url]', push_redirect_url);
310
+ for (const tag of tags ?? [])
311
+ data.append('blog_post[tags][]', tag);
312
+ return this.#api.post('/mod/blogs', data);
313
+ }
314
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: BlogsService, deps: [], target: i0.ɵɵFactoryTarget.Service });
315
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: BlogsService });
316
+ }
317
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: BlogsService, decorators: [{
318
+ type: Service
319
+ }] });
320
+
321
+ /** Dashboards (boards) and their reports. */
322
+ class BoardsService {
323
+ #api = inject(ApiClient);
324
+ list(params = {}) {
325
+ return this.#api.get('/boards/index', { params: { ...params } });
326
+ }
327
+ listReports(board, page) {
328
+ return this.#api.get(`/boards/${board}/reports`, { params: { page } });
329
+ }
330
+ /** Either `timeframe` or `start_date`/`end_date` is used, never both. */
331
+ executeReport(board, report, params = {}) {
332
+ const query = params.timeframe ? { timeframe: params.timeframe } : { start_date: params.start_date, end_date: params.end_date };
333
+ return this.#api.get(`/boards/${board}/reports/${report}/exec`, { params: query });
334
+ }
335
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: BoardsService, deps: [], target: i0.ɵɵFactoryTarget.Service });
336
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: BoardsService });
337
+ }
338
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: BoardsService, decorators: [{
339
+ type: Service
340
+ }] });
341
+
342
+ /** Comments on an activity (target). */
343
+ class CommentsService {
344
+ #api = inject(ApiClient);
345
+ list(targetId, params = {}) {
346
+ return this.#api.get(`/mod/comments/${targetId}`, { params: { ...params } });
347
+ }
348
+ create(targetId, { body, category }) {
349
+ return this.#api.post(`/mod/comments/${targetId}`, { comment: { body, category } });
350
+ }
351
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: CommentsService, deps: [], target: i0.ɵɵFactoryTarget.Service });
352
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: CommentsService });
353
+ }
354
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: CommentsService, decorators: [{
355
+ type: Service
356
+ }] });
357
+
358
+ /**
359
+ * Entries (activities) of the logged participant, or of another one with `participant_uid` (admins).
360
+ * Every method uses the detailed `show` view. Types without a method of their own are listed with `list({ _type })`.
361
+ */
362
+ class EntriesService {
363
+ #api = inject(ApiClient);
364
+ /** `T`: shape of `data` (the campaign's external action fields). */
365
+ listExternals(params = {}) {
366
+ return this.#list({ ...params, _type: 'External' });
367
+ }
368
+ listRedemptions(params = {}) {
369
+ return this.#list({ ...params, _type: 'Redeem' });
370
+ }
371
+ listPhotos(params = {}) {
372
+ return this.#list({ ...params, _type: 'UploadPhoto' });
373
+ }
374
+ listDocuments(params = {}) {
375
+ return this.#list({ ...params, _type: 'UploadDocument' });
376
+ }
377
+ listPurchases(params = {}) {
378
+ return this.#list({ ...params, _type: 'Retail::Buy' });
379
+ }
380
+ /** Every entry, or one `_type` (including the ones without a method of their own). Narrow each item with `isEntryType`. */
381
+ list(params = {}) {
382
+ return this.#list(params);
383
+ }
384
+ /** Entries of several participants at once (admins only, 100 per page). `uids` is required by the backend. */
385
+ search(uids, params = {}) {
386
+ return this.#api.get('/entries/search', { params: asApiParams({ ...params, participant_uids: uids, hide_undo: params.hide_undo ?? true, view: 'show' }) });
387
+ }
388
+ /**
389
+ * Records an external action event.
390
+ * @param event An external action configured in the campaign (otherwise `code_error: 30`).
391
+ * @param properties Event data. Must not be empty (otherwise `code_error: 11`).
392
+ */
393
+ createExternal(event, properties, { category, points_type } = {}) {
394
+ return this.#api.post('/mod/external', { event, properties, category, points_type });
395
+ }
396
+ #list(params) {
397
+ return this.#api.get('/participant_entries', { params: asApiParams({ ...params, hide_undo: params.hide_undo ?? true, view: 'show' }) });
398
+ }
399
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: EntriesService, deps: [], target: i0.ɵɵFactoryTarget.Service });
400
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: EntriesService });
401
+ }
402
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: EntriesService, decorators: [{
403
+ type: Service
404
+ }] });
405
+
406
+ /**
407
+ * Narrows an entry to its type.
408
+ *
409
+ * @example
410
+ * ```ts
411
+ * for (const entry of response.data) {
412
+ * if (isEntryType(entry, 'Redeem')) console.log(entry.prize.name)
413
+ * }
414
+ * ```
415
+ */
416
+ function isEntryType(entry, type) {
417
+ return entry._type === type;
418
+ }
419
+
420
+ /** External forms (custom actions configured per campaign) and their submissions. */
421
+ class ExternalFormsService {
422
+ #api = inject(ApiClient);
423
+ listForms(params = {}) {
424
+ return this.#api.get('/external_forms/actions/list', { params: { ...params, participant_match_rules: params.participant_match_rules ?? true } });
425
+ }
426
+ getFormFields(id) {
427
+ return this.#api.get(`/external_forms/actions/${id}/fields_info`);
428
+ }
429
+ submit(id, values, category) {
430
+ return this.#api.post(`/external_forms/actions/${id}/fillup`, { external_form: values, category });
431
+ }
432
+ /** Submitted forms (`External` entries), paginated. It is a read, but the backend only accepts POST. `T`: shape of `data`. */
433
+ listSubmissions(params = {}) {
434
+ return this.#api.post('/external_forms/list', { ...params, hide_undo: params.hide_undo ?? true });
435
+ }
436
+ /** @param id The submission (entry) `_id`. */
437
+ getSubmission(id) {
438
+ return this.#api.get(`/external_forms/${id}`);
439
+ }
440
+ updateSubmission(id, values) {
441
+ return this.#api.patch(`/external_forms/${id}`, { external_form: values });
442
+ }
443
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ExternalFormsService, deps: [], target: i0.ɵɵFactoryTarget.Service });
444
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: ExternalFormsService });
445
+ }
446
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ExternalFormsService, decorators: [{
447
+ type: Service
448
+ }] });
449
+
450
+ /** Campaign goals: the participant's goals with progress, the campaign catalog, and accepting goals. */
451
+ class GoalsService {
452
+ #api = inject(ApiClient);
453
+ /** Goals that apply to the logged participant (or `participant_uid`), with their progress. `T`: shape of `goal_data`. */
454
+ listParticipantGoals(params = {}) {
455
+ return this.#api.get('/participants/goals', { params: { ...params } });
456
+ }
457
+ /** Every goal of the campaign (no progress), paginated. It is a read, but the backend only accepts POST. */
458
+ list(params = {}) {
459
+ return this.#api.post('/goals/index', { ...params, include_ended: params.include_ended ?? true });
460
+ }
461
+ /** @param goalId The goal id (`ParticipantGoal.goal_id`, not its `_id`). */
462
+ accept(goalId) {
463
+ return this.#api.post('/participants/goals/accept', { goal_id: goalId });
464
+ }
465
+ /** @param goalId The goal id (`ParticipantGoal.goal_id`, not its `_id`). */
466
+ decline(goalId) {
467
+ return this.#api.post('/participants/goals/unaccept', { goal_id: goalId });
468
+ }
469
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: GoalsService, deps: [], target: i0.ɵɵFactoryTarget.Service });
470
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: GoalsService });
471
+ }
472
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: GoalsService, decorators: [{
473
+ type: Service
474
+ }] });
475
+
476
+ /** Campaign metrics (custom aggregations configured per campaign). */
477
+ class MetricsService {
478
+ #api = inject(ApiClient);
479
+ list(params = {}) {
480
+ return this.#api.get('/metrics/index', { params: { ...params } });
481
+ }
482
+ calculate(params) {
483
+ return this.#api.get('/metrics/exec', { params: { ...params } });
484
+ }
485
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MetricsService, deps: [], target: i0.ɵɵFactoryTarget.Service });
486
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: MetricsService });
487
+ }
488
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MetricsService, decorators: [{
489
+ type: Service
490
+ }] });
491
+
492
+ /** Logged participant, participant lists and push notification subscriptions. */
493
+ class ParticipantService {
494
+ #api = inject(ApiClient);
495
+ /** Logged participant and site config. `T`: your participant interface (`extends BaseCurrentParticipant`). */
496
+ getCurrent() {
497
+ return this.#api.get('/sconfig');
498
+ }
499
+ /** Points, level and position of the logged participant. `T`: shape of `data.data` (`extends BaseParticipantRankData`). */
500
+ getRank() {
501
+ return this.#api.get('/participant_rank');
502
+ }
503
+ /** `T`: your participant interface (`extends BaseParticipant`). */
504
+ list(params = {}) {
505
+ return this.#api.get('/participants/list', { params: { ...params } });
506
+ }
507
+ /** `T`: your participant interface (`extends BaseParticipant`). */
508
+ getByUid(uid) {
509
+ return this.#api.get('/participants/show', { params: { uid } });
510
+ }
511
+ /** Sends the browser subscription as the request body, unwrapped. */
512
+ savePushSubscription(subscription) {
513
+ return this.#api.post('/participants/save_push_subscription', subscription);
514
+ }
515
+ removePushSubscriptions() {
516
+ return this.#api.post('/participants/remove_push_subscriptions', {});
517
+ }
518
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ParticipantService, deps: [], target: i0.ɵɵFactoryTarget.Service });
519
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: ParticipantService });
520
+ }
521
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ParticipantService, decorators: [{
522
+ type: Service
523
+ }] });
524
+
525
+ /** Change password (logged participant) and the password recovery flow. */
526
+ class PasswordService {
527
+ #api = inject(ApiClient);
528
+ changePassword(params) {
529
+ return this.#api.put('/password/change', { participation: params });
530
+ }
531
+ /** Checks that a participant exists for the given channel value (e.g. an email or a phone number). */
532
+ validateChannel(channel, value) {
533
+ return this.#api.post('/password/validate_channel', { [channel]: value });
534
+ }
535
+ sendResetToken({ channel, data, edit_password_url, uid }) {
536
+ const body = { participation: data, notification_channel: channel, edit_password_url };
537
+ if (uid)
538
+ body['uid'] = uid;
539
+ return this.#api.post('/password', body);
540
+ }
541
+ resetPassword({ password, password_confirmation, token, channel }) {
542
+ return this.#api.post('/password/update', { participation: { password, password_confirmation }, token, channel });
543
+ }
544
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: PasswordService, deps: [], target: i0.ɵɵFactoryTarget.Service });
545
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: PasswordService });
546
+ }
547
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: PasswordService, decorators: [{
548
+ type: Service
549
+ }] });
550
+
551
+ /** Prizes and redemptions. */
552
+ class PrizesService {
553
+ #api = inject(ApiClient);
554
+ list(params = {}) {
555
+ return this.#api.get('/prizes/index', { params: asApiParams({ ...params, page: params.page ?? 1, view: params.view ?? 'show' }) });
556
+ }
557
+ checkRedeem(id) {
558
+ return this.#api.get(`/prizes/${id}/redeem/check`);
559
+ }
560
+ redeem(id, opts = {}) {
561
+ return this.#api.post(`/prizes/${id}/redeem`, opts);
562
+ }
563
+ getWishlist(page) {
564
+ return this.#api.get('/prizes/whislist', { params: { page } });
565
+ }
566
+ toggleWishlist(id) {
567
+ return this.#api.get(`/prizes/${id}/whislist_toggle`, { params: { id } });
568
+ }
569
+ getExternalCouponData(id, key, city) {
570
+ return this.#api.get(`/prizes/${id}/redeem/external/${key}`, { params: { city } });
571
+ }
572
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: PrizesService, deps: [], target: i0.ɵɵFactoryTarget.Service });
573
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: PrizesService });
574
+ }
575
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: PrizesService, decorators: [{
576
+ type: Service
577
+ }] });
578
+
579
+ /** Segment and advanced participant rankings. */
580
+ class RankingService {
581
+ #api = inject(ApiClient);
582
+ getSegment(params = {}) {
583
+ return this.#api.get('/participants/ranks/segment', { params: { ...params } });
584
+ }
585
+ getAdvanced(params = {}) {
586
+ return this.#api.get('/participants/ranks/advanced', { params: { ...params } });
587
+ }
588
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: RankingService, deps: [], target: i0.ɵɵFactoryTarget.Service });
589
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: RankingService });
590
+ }
591
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: RankingService, decorators: [{
592
+ type: Service
593
+ }] });
594
+
595
+ /** The participant's referral code. */
596
+ class ReferralsService {
597
+ #api = inject(ApiClient);
598
+ changeCode(code) {
599
+ return this.#api.post('/mod/referrals', {}, { params: { code } });
600
+ }
601
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ReferralsService, deps: [], target: i0.ɵɵFactoryTarget.Service });
602
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: ReferralsService });
603
+ }
604
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ReferralsService, decorators: [{
605
+ type: Service
606
+ }] });
607
+
608
+ /** Signup and email verification. */
609
+ class RegistrationsService {
610
+ #api = inject(ApiClient);
611
+ getSignupForm() {
612
+ return this.#api.get('/registrations/signupform');
613
+ }
614
+ signup(data) {
615
+ return this.#api.post('/registrations/fillup', { participation: data });
616
+ }
617
+ updateParticipant(data) {
618
+ return this.#api.post('/registrations/update', { participation: data });
619
+ }
620
+ /** Sends (or resends) the email verification token to the given address. */
621
+ sendEmailVerificationToken(email) {
622
+ return this.#api.post('/registrations/reset_email_verify_token', { email });
623
+ }
624
+ validateEmailToken(token) {
625
+ return this.#api.post('/registrations/validate_email_token', { token });
626
+ }
627
+ confirmEmail(token) {
628
+ return this.#api.post('/registrations/confirm_email', { token });
629
+ }
630
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: RegistrationsService, deps: [], target: i0.ɵɵFactoryTarget.Service });
631
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: RegistrationsService });
632
+ }
633
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: RegistrationsService, decorators: [{
634
+ type: Service
635
+ }] });
636
+
637
+ /** Participant session: login form, login/logout, SSO and login requirements. */
638
+ class SessionService {
639
+ #api = inject(ApiClient);
640
+ /** Fields the microsite asks for on login (the login identifier varies: email, code, document…). */
641
+ getLoginForm() {
642
+ return this.#api.get('/sessions/loginform');
643
+ }
644
+ login(credentials) {
645
+ return this.#api.post('/sessions/login', { participation: credentials });
646
+ }
647
+ logout() {
648
+ return this.#api.get('/sessions/logout');
649
+ }
650
+ /** URL to redirect the participant to the SSO provider. */
651
+ getSsoLoginUrl(provider) {
652
+ return this.#api.get('/auth/sso_login', { params: { provider } });
653
+ }
654
+ /** Whether the logged participant can use the site or must complete something first (`redirect_page`). */
655
+ checkLoginRequirements() {
656
+ return this.#api.get('/participant_login_requirements');
657
+ }
658
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: SessionService, deps: [], target: i0.ɵɵFactoryTarget.Service });
659
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: SessionService });
660
+ }
661
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: SessionService, decorators: [{
662
+ type: Service
663
+ }] });
664
+
665
+ /** Teams. */
666
+ class TeamsService {
667
+ #api = inject(ApiClient);
668
+ list(params = {}) {
669
+ return this.#api.get('/mod/teams', { params: { ...params } });
670
+ }
671
+ get(id) {
672
+ return this.#api.get(`/mod/teams/${id}/show`);
673
+ }
674
+ create(params) {
675
+ return this.#api.post('/mod/teams', { team: params });
676
+ }
677
+ /** Removes the logged participant, or `uid` when given, from the team. */
678
+ removeMember(id, uid) {
679
+ return this.#api.post(`/mod/teams/${id}/remove_member`, {}, { params: { participant_uid: uid } });
680
+ }
681
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: TeamsService, deps: [], target: i0.ɵɵFactoryTarget.Service });
682
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: TeamsService });
683
+ }
684
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: TeamsService, decorators: [{
685
+ type: Service
686
+ }] });
687
+
688
+ /** Votes on an activity (target): like, support, interest, curiosity. */
689
+ class VotesService {
690
+ #api = inject(ApiClient);
691
+ get(targetId) {
692
+ return this.#api.get(`/mod/votes/${targetId}`);
693
+ }
694
+ create(targetId, params = {}) {
695
+ return this.#api.post(`/mod/votes/${targetId}`, params);
696
+ }
697
+ update(targetId, params = {}) {
698
+ return this.#api.patch(`/mod/votes/${targetId}`, params);
699
+ }
700
+ delete(targetId) {
701
+ return this.#api.delete(`/mod/votes/${targetId}`);
702
+ }
703
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: VotesService, deps: [], target: i0.ɵɵFactoryTarget.Service });
704
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.1.7", ngImport: i0, type: VotesService });
705
+ }
706
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: VotesService, decorators: [{
707
+ type: Service
708
+ }] });
709
+
710
+ /*
711
+ * Public API Surface of @superlikers/microsites-api
712
+ *
713
+ * Everything exported here is public API (the contract with consumers).
714
+ * Domain folders only hold public models and their service, so they are exported through their
715
+ * `index.ts`; `config`, `errors` and `http` also hold internal pieces and are exported one by one.
716
+ */
717
+
718
+ /**
719
+ * Generated bundle index. Do not edit.
720
+ */
721
+
722
+ export { AchievementsService, ActivitiesService, ApiError, BadgesService, BlogsService, BoardsService, CommentsService, EntriesService, ExternalFormsService, GoalsService, MetricsService, ParticipantService, PasswordService, PrizesService, RankingService, ReferralsService, RegistrationsService, SessionService, TeamsService, VotesService, isApiError, isEntryType, provideMicrositesApi };
723
+ //# sourceMappingURL=superlikers-microsites-api.mjs.map