@quapt/event-feedback 1.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.
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# @quapt/event-feedback
|
|
2
|
+
|
|
3
|
+
Trigger event-based questionnaires from Angular (after API success/failure or via a button).
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @quapt/event-feedback
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Sometimes npm still caches the old registry error.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm cache clean --force
|
|
13
|
+
```
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Setup
|
|
17
|
+
|
|
18
|
+
**Standalone:** In `main.ts` add `provideHttpClient()` and `provideEventBased()`.
|
|
19
|
+
|
|
20
|
+
**NgModule:** Import `HttpClientModule` and `EventBasedModule.forRoot({ apiBaseUrl: '...' })`.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Component: `EventBased`
|
|
25
|
+
|
|
26
|
+
Selector: `lib-event-feedback`. Standalone; import `EventBased` from `@quapt/event-feedback`.
|
|
27
|
+
|
|
28
|
+
| Input | Type | Default |
|
|
29
|
+
|-------|------|---------|
|
|
30
|
+
| `organizationId` | `string` | `''` |
|
|
31
|
+
| `appId` | `string` | `''` |
|
|
32
|
+
| `groupId` | `string` | `''` |
|
|
33
|
+
| `eventId` | `string` | `''` |
|
|
34
|
+
| `questionnaireType` | `string` | `''` |
|
|
35
|
+
| `eventData` | `EventDataItem[]` | `[]` |
|
|
36
|
+
| `buttonLabel` | `string` | `'Trigger event'` |
|
|
37
|
+
| `buttonBgColor` | `string` | `'#f59e0b'` |
|
|
38
|
+
| `buttonColor` | `string` | `'#000'` |
|
|
39
|
+
| `buttonHeight` | `string` | `'40px'` |
|
|
40
|
+
|
|
41
|
+
**Template:**
|
|
42
|
+
|
|
43
|
+
```html
|
|
44
|
+
<quapt-event-feedback
|
|
45
|
+
[organizationId]="organizationId"
|
|
46
|
+
[appId]="appId"
|
|
47
|
+
[groupId]="groupId"
|
|
48
|
+
[eventId]="eventId"
|
|
49
|
+
[questionnaireType]="questionnaireType"
|
|
50
|
+
[eventData]="eventData"
|
|
51
|
+
buttonLabel="Trigger questionnaire"
|
|
52
|
+
buttonBgColor="#f59e0b"
|
|
53
|
+
buttonColor="#000"
|
|
54
|
+
buttonHeight="40px"
|
|
55
|
+
/>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Service: `EventBasedTriggerService`
|
|
61
|
+
|
|
62
|
+
Inject and call `triggerEvent(options)` (e.g. in your API `subscribe`).
|
|
63
|
+
|
|
64
|
+
**`TriggerEventOptions`:** `organizationId`, `appId`, `groupId`, `eventId`, `questionnaireType`, `eventData?`
|
|
65
|
+
|
|
66
|
+
**`EventDataItem`:** `{ fieldName: string; fieldValue: string }`
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { EventBasedTriggerService } from '@quapt/event-feedback';
|
|
70
|
+
|
|
71
|
+
constructor(private readonly eventTriggerService: EventBasedTriggerService) {
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.eventBased.triggerEvent({
|
|
75
|
+
organizationId: 'ORG-123',
|
|
76
|
+
appId: 'APP-1',
|
|
77
|
+
groupId: 'GRP001',
|
|
78
|
+
eventId: 'EVT-1',
|
|
79
|
+
questionnaireType: 'NPS',
|
|
80
|
+
eventData: [
|
|
81
|
+
{ fieldName: 'EMAIL', fieldValue: 'user@example.com' },
|
|
82
|
+
{ fieldName: 'NAME', fieldValue: 'User' },
|
|
83
|
+
],
|
|
84
|
+
}).subscribe();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Exports
|
|
90
|
+
|
|
91
|
+
`EventBased`, `EventBasedTriggerService`, `EventBasedModule`, `provideEventBased`, `TriggerEventOptions`, `EventDataItem`, `EventBasedConfig`
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, Optional, Inject, Injectable, Input, Component, NgModule } from '@angular/core';
|
|
3
|
+
import { catchError, of } from 'rxjs';
|
|
4
|
+
import * as i1 from '@angular/common/http';
|
|
5
|
+
|
|
6
|
+
/** Default base URL for the event-based API (core-service). */
|
|
7
|
+
// export const EVENT_BASED_DEFAULT_API_BASE_URL =
|
|
8
|
+
// 'https://ibtz2bm4h3.execute-api.ap-south-1.amazonaws.com/core-service/api/v1';
|
|
9
|
+
const EVENT_BASED_DEFAULT_API_BASE_URL = 'https://iszg9dimg9.execute-api.ap-south-1.amazonaws.com/core-service/api/v1';
|
|
10
|
+
/**
|
|
11
|
+
* Base URL for the event-based API (e.g. `https://api.example.com`).
|
|
12
|
+
* The service will call `PATCH {baseUrl}/{organizationId}/questionnaires/trigger`.
|
|
13
|
+
*/
|
|
14
|
+
const EVENT_BASED_API_BASE_URL = new InjectionToken('EVENT_BASED_API_BASE_URL');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Service to trigger event-based questionnaires from any part of your Angular app.
|
|
18
|
+
* Use it after your own API calls succeed or fail to fire the trigger.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // In your component after your API call:
|
|
22
|
+
* this.myApi.submit(data).subscribe({
|
|
23
|
+
* next: () => this.eventBasedTrigger.triggerEvent({ organizationId, appId, ... }).subscribe(),
|
|
24
|
+
* error: () => this.eventBasedTrigger.triggerEvent({ organizationId, appId, ... }).subscribe()
|
|
25
|
+
* });
|
|
26
|
+
*/
|
|
27
|
+
class EventBasedTriggerService {
|
|
28
|
+
http;
|
|
29
|
+
apiBaseUrl;
|
|
30
|
+
constructor(http, apiBaseUrl) {
|
|
31
|
+
this.http = http;
|
|
32
|
+
this.apiBaseUrl = apiBaseUrl;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Trigger the event-based questionnaire API.
|
|
36
|
+
* Call this in your subscribe (next or error) when you want to fire the trigger.
|
|
37
|
+
*
|
|
38
|
+
* @param options Trigger options (organizationId, appId, groupId, eventId, questionnaireType, eventData).
|
|
39
|
+
* @param apiBaseUrl Optional override for the API base URL (if not provided via token).
|
|
40
|
+
* @returns Observable that completes on success or error; never throws (errors are logged).
|
|
41
|
+
*/
|
|
42
|
+
triggerEvent(options, apiBaseUrl) {
|
|
43
|
+
const base = apiBaseUrl ?? this.apiBaseUrl ?? EVENT_BASED_DEFAULT_API_BASE_URL;
|
|
44
|
+
const url = this.buildUrl(base, options.organizationId);
|
|
45
|
+
const body = {
|
|
46
|
+
appId: options.appId,
|
|
47
|
+
groupId: options.groupId,
|
|
48
|
+
eventId: options.eventId,
|
|
49
|
+
questionnaireType: options.questionnaireType,
|
|
50
|
+
eventData: options.eventData ?? [],
|
|
51
|
+
};
|
|
52
|
+
return this.http.patch(url, body).pipe(catchError((err) => {
|
|
53
|
+
const details = err?.error?.error?.details ?? err?.message ?? err;
|
|
54
|
+
console.warn('[event-based] trigger failed:', details);
|
|
55
|
+
return of(null);
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
buildUrl(base, organizationId) {
|
|
59
|
+
const baseTrimmed = base.replace(/\/+$/, '');
|
|
60
|
+
return `${baseTrimmed}/${organizationId}/questionnaires/trigger`;
|
|
61
|
+
}
|
|
62
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: EventBasedTriggerService, deps: [{ token: i1.HttpClient }, { token: EVENT_BASED_API_BASE_URL, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
63
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: EventBasedTriggerService, providedIn: 'root' });
|
|
64
|
+
}
|
|
65
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: EventBasedTriggerService, decorators: [{
|
|
66
|
+
type: Injectable,
|
|
67
|
+
args: [{ providedIn: 'root' }]
|
|
68
|
+
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: undefined, decorators: [{
|
|
69
|
+
type: Optional
|
|
70
|
+
}, {
|
|
71
|
+
type: Inject,
|
|
72
|
+
args: [EVENT_BASED_API_BASE_URL]
|
|
73
|
+
}] }] });
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Reusable UI component that triggers the icxbee when the user
|
|
77
|
+
* clicks the button. Use when you want a visible trigger in the template.
|
|
78
|
+
*
|
|
79
|
+
* For triggering from code (e.g. after your own API success/fail), inject
|
|
80
|
+
* EventBasedTriggerService and call triggerEvent() in your subscribe.
|
|
81
|
+
*/
|
|
82
|
+
class QuaptEventFeedback {
|
|
83
|
+
trigger;
|
|
84
|
+
organizationId = '';
|
|
85
|
+
appId = '';
|
|
86
|
+
groupId = '';
|
|
87
|
+
eventId = '';
|
|
88
|
+
questionnaireType = '';
|
|
89
|
+
eventData = [];
|
|
90
|
+
buttonLabel = 'Trigger event';
|
|
91
|
+
buttonBgColor = '#f59e0b';
|
|
92
|
+
buttonColor = '#000';
|
|
93
|
+
buttonHeight = '40px';
|
|
94
|
+
constructor(trigger) {
|
|
95
|
+
this.trigger = trigger;
|
|
96
|
+
}
|
|
97
|
+
triggerEvent() {
|
|
98
|
+
const options = {
|
|
99
|
+
organizationId: this.organizationId,
|
|
100
|
+
appId: this.appId,
|
|
101
|
+
groupId: this.groupId,
|
|
102
|
+
eventId: this.eventId,
|
|
103
|
+
questionnaireType: this.questionnaireType,
|
|
104
|
+
eventData: this.eventData,
|
|
105
|
+
};
|
|
106
|
+
this.trigger.triggerEvent(options).subscribe();
|
|
107
|
+
}
|
|
108
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: QuaptEventFeedback, deps: [{ token: EventBasedTriggerService }], target: i0.ɵɵFactoryTarget.Component });
|
|
109
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.0", type: QuaptEventFeedback, isStandalone: true, selector: "quapt-event-feedback", inputs: { organizationId: "organizationId", appId: "appId", groupId: "groupId", eventId: "eventId", questionnaireType: "questionnaireType", eventData: "eventData", buttonLabel: "buttonLabel", buttonBgColor: "buttonBgColor", buttonColor: "buttonColor", buttonHeight: "buttonHeight" }, ngImport: i0, template: `
|
|
110
|
+
<button type="button" (click)="triggerEvent()"
|
|
111
|
+
[style.background-color]="buttonBgColor"
|
|
112
|
+
[style.color]="buttonColor"
|
|
113
|
+
[style.height]="buttonHeight"
|
|
114
|
+
class="trigger-button"
|
|
115
|
+
>
|
|
116
|
+
{{ buttonLabel }}
|
|
117
|
+
</button>
|
|
118
|
+
`, isInline: true, styles: [".trigger-button{border:none;padding:0 20px;display:flex;align-items:center;justify-content:center;border-radius:4px;cursor:pointer}\n"] });
|
|
119
|
+
}
|
|
120
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: QuaptEventFeedback, decorators: [{
|
|
121
|
+
type: Component,
|
|
122
|
+
args: [{ selector: 'quapt-event-feedback', standalone: true, imports: [], template: `
|
|
123
|
+
<button type="button" (click)="triggerEvent()"
|
|
124
|
+
[style.background-color]="buttonBgColor"
|
|
125
|
+
[style.color]="buttonColor"
|
|
126
|
+
[style.height]="buttonHeight"
|
|
127
|
+
class="trigger-button"
|
|
128
|
+
>
|
|
129
|
+
{{ buttonLabel }}
|
|
130
|
+
</button>
|
|
131
|
+
`, styles: [".trigger-button{border:none;padding:0 20px;display:flex;align-items:center;justify-content:center;border-radius:4px;cursor:pointer}\n"] }]
|
|
132
|
+
}], ctorParameters: () => [{ type: EventBasedTriggerService }], propDecorators: { organizationId: [{
|
|
133
|
+
type: Input
|
|
134
|
+
}], appId: [{
|
|
135
|
+
type: Input
|
|
136
|
+
}], groupId: [{
|
|
137
|
+
type: Input
|
|
138
|
+
}], eventId: [{
|
|
139
|
+
type: Input
|
|
140
|
+
}], questionnaireType: [{
|
|
141
|
+
type: Input
|
|
142
|
+
}], eventData: [{
|
|
143
|
+
type: Input
|
|
144
|
+
}], buttonLabel: [{
|
|
145
|
+
type: Input
|
|
146
|
+
}], buttonBgColor: [{
|
|
147
|
+
type: Input
|
|
148
|
+
}], buttonColor: [{
|
|
149
|
+
type: Input
|
|
150
|
+
}], buttonHeight: [{
|
|
151
|
+
type: Input
|
|
152
|
+
}] } });
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Provide the event-based trigger service with optional config.
|
|
156
|
+
* Uses the default core-service API base URL when no config is passed.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* // main.ts (standalone) – uses default URL
|
|
160
|
+
* bootstrapApplication(AppComponent, {
|
|
161
|
+
* providers: [provideHttpClient(), provideEventBased()]
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* // With custom URL
|
|
166
|
+
* provideEventBased({ apiBaseUrl: 'https://api.example.com' })
|
|
167
|
+
*/
|
|
168
|
+
function provideEventBased(config) {
|
|
169
|
+
const providers = [EventBasedTriggerService];
|
|
170
|
+
const apiBaseUrl = config?.apiBaseUrl ?? EVENT_BASED_DEFAULT_API_BASE_URL;
|
|
171
|
+
providers.push({
|
|
172
|
+
provide: EVENT_BASED_API_BASE_URL,
|
|
173
|
+
useValue: apiBaseUrl,
|
|
174
|
+
});
|
|
175
|
+
return providers;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* NgModule for the event-based library.
|
|
180
|
+
* Use forRoot() to configure the API base URL when using modules.
|
|
181
|
+
*/
|
|
182
|
+
class EventBasedModule {
|
|
183
|
+
static forRoot(config) {
|
|
184
|
+
return {
|
|
185
|
+
ngModule: EventBasedModule,
|
|
186
|
+
providers: [
|
|
187
|
+
EventBasedTriggerService,
|
|
188
|
+
{ provide: EVENT_BASED_API_BASE_URL, useValue: config.apiBaseUrl },
|
|
189
|
+
],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: EventBasedModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
193
|
+
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.0", ngImport: i0, type: EventBasedModule, imports: [QuaptEventFeedback], exports: [QuaptEventFeedback] });
|
|
194
|
+
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: EventBasedModule });
|
|
195
|
+
}
|
|
196
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: EventBasedModule, decorators: [{
|
|
197
|
+
type: NgModule,
|
|
198
|
+
args: [{
|
|
199
|
+
imports: [QuaptEventFeedback],
|
|
200
|
+
exports: [QuaptEventFeedback],
|
|
201
|
+
}]
|
|
202
|
+
}] });
|
|
203
|
+
|
|
204
|
+
/*
|
|
205
|
+
* Public API Surface of event-based
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Generated bundle index. Do not edit.
|
|
210
|
+
*/
|
|
211
|
+
|
|
212
|
+
export { EVENT_BASED_API_BASE_URL, EVENT_BASED_DEFAULT_API_BASE_URL, EventBasedModule, EventBasedTriggerService, QuaptEventFeedback, provideEventBased };
|
|
213
|
+
//# sourceMappingURL=quapt-event-feedback.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quapt-event-feedback.mjs","sources":["../../../projects/event-based/src/lib/event-based.config.ts","../../../projects/event-based/src/lib/event-based-trigger.service.ts","../../../projects/event-based/src/lib/event-based.ts","../../../projects/event-based/src/lib/event-based.providers.ts","../../../projects/event-based/src/lib/event-based.module.ts","../../../projects/event-based/src/public-api.ts","../../../projects/event-based/src/quapt-event-feedback.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\n/** Default base URL for the event-based API (core-service). */\n// export const EVENT_BASED_DEFAULT_API_BASE_URL =\n// 'https://ibtz2bm4h3.execute-api.ap-south-1.amazonaws.com/core-service/api/v1';\n\nexport const EVENT_BASED_DEFAULT_API_BASE_URL =\n 'https://iszg9dimg9.execute-api.ap-south-1.amazonaws.com/core-service/api/v1';\n\n/**\n * Base URL for the event-based API (e.g. `https://api.example.com`).\n * The service will call `PATCH {baseUrl}/{organizationId}/questionnaires/trigger`.\n */\nexport const EVENT_BASED_API_BASE_URL = new InjectionToken<string>(\n 'EVENT_BASED_API_BASE_URL'\n);\n\n/**\n * Optional global config for the event-based library.\n */\nexport interface EventBasedConfig {\n /** Base URL for the API. Required for the trigger service to work. */\n apiBaseUrl: string;\n}\n","import { Injectable, Optional, Inject } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { Observable, catchError, of } from 'rxjs';\nimport {\n EVENT_BASED_API_BASE_URL,\n EVENT_BASED_DEFAULT_API_BASE_URL,\n} from './event-based.config';\nimport type { TriggerEventOptions, TriggerEventSuccess } from './event-based.types';\n\n/**\n * Service to trigger event-based questionnaires from any part of your Angular app.\n * Use it after your own API calls succeed or fail to fire the trigger.\n *\n * @example\n * // In your component after your API call:\n * this.myApi.submit(data).subscribe({\n * next: () => this.eventBasedTrigger.triggerEvent({ organizationId, appId, ... }).subscribe(),\n * error: () => this.eventBasedTrigger.triggerEvent({ organizationId, appId, ... }).subscribe()\n * });\n */\n@Injectable({ providedIn: 'root' })\nexport class EventBasedTriggerService {\n constructor(\n private readonly http: HttpClient,\n @Optional() @Inject(EVENT_BASED_API_BASE_URL) private readonly apiBaseUrl: string | null\n ) {}\n\n /**\n * Trigger the event-based questionnaire API.\n * Call this in your subscribe (next or error) when you want to fire the trigger.\n *\n * @param options Trigger options (organizationId, appId, groupId, eventId, questionnaireType, eventData).\n * @param apiBaseUrl Optional override for the API base URL (if not provided via token).\n * @returns Observable that completes on success or error; never throws (errors are logged).\n */\n triggerEvent(\n options: TriggerEventOptions,\n apiBaseUrl?: string\n ): Observable<TriggerEventSuccess | null> {\n const base =\n apiBaseUrl ?? this.apiBaseUrl ?? EVENT_BASED_DEFAULT_API_BASE_URL;\n\n const url = this.buildUrl(base, options.organizationId);\n const body = {\n appId: options.appId,\n groupId: options.groupId,\n eventId: options.eventId,\n questionnaireType: options.questionnaireType,\n eventData: options.eventData ?? [],\n };\n\n return this.http.patch<TriggerEventSuccess>(url, body).pipe(\n catchError((err) => {\n const details = err?.error?.error?.details ?? err?.message ?? err;\n console.warn('[event-based] trigger failed:', details);\n return of(null);\n })\n );\n }\n\n private buildUrl(base: string, organizationId: string): string {\n const baseTrimmed = base.replace(/\\/+$/, '');\n return `${baseTrimmed}/${organizationId}/questionnaires/trigger`;\n }\n}\n","import { Component, Input } from '@angular/core';\nimport { EventBasedTriggerService } from './event-based-trigger.service';\nimport type { EventDataItem, TriggerEventOptions } from './event-based.types';\n\n/**\n * Reusable UI component that triggers the icxbee when the user\n * clicks the button. Use when you want a visible trigger in the template.\n *\n * For triggering from code (e.g. after your own API success/fail), inject\n * EventBasedTriggerService and call triggerEvent() in your subscribe.\n */\n@Component({\n selector: 'quapt-event-feedback',\n standalone: true,\n imports: [],\n template: `\n <button type=\"button\" (click)=\"triggerEvent()\"\n [style.background-color]=\"buttonBgColor\"\n [style.color]=\"buttonColor\"\n [style.height]=\"buttonHeight\"\n class=\"trigger-button\"\n >\n {{ buttonLabel }}\n </button>\n `,\n styles: [\n `\n .trigger-button {\n border: none;\n padding: 0px 20px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n cursor: pointer;\n }\n `,\n ],\n})\nexport class QuaptEventFeedback {\n @Input() organizationId = '';\n @Input() appId = '';\n @Input() groupId = '';\n @Input() eventId = '';\n @Input() questionnaireType = '';\n @Input() eventData: EventDataItem[] = [];\n @Input() buttonLabel = 'Trigger event';\n @Input() buttonBgColor = '#f59e0b';\n @Input() buttonColor = '#000';\n @Input() buttonHeight = '40px';\n constructor(private readonly trigger: EventBasedTriggerService) { }\n\n triggerEvent(): void {\n const options: TriggerEventOptions = {\n organizationId: this.organizationId,\n appId: this.appId,\n groupId: this.groupId,\n eventId: this.eventId,\n questionnaireType: this.questionnaireType,\n eventData: this.eventData,\n };\n this.trigger.triggerEvent(options).subscribe();\n }\n}\n","import { Provider } from '@angular/core';\nimport { EventBasedTriggerService } from './event-based-trigger.service';\nimport {\n EVENT_BASED_API_BASE_URL,\n EVENT_BASED_DEFAULT_API_BASE_URL,\n type EventBasedConfig,\n} from './event-based.config';\n\n/**\n * Provide the event-based trigger service with optional config.\n * Uses the default core-service API base URL when no config is passed.\n *\n * @example\n * // main.ts (standalone) – uses default URL\n * bootstrapApplication(AppComponent, {\n * providers: [provideHttpClient(), provideEventBased()]\n * });\n *\n * @example\n * // With custom URL\n * provideEventBased({ apiBaseUrl: 'https://api.example.com' })\n */\nexport function provideEventBased(config?: EventBasedConfig): Provider[] {\n const providers: Provider[] = [EventBasedTriggerService];\n const apiBaseUrl = config?.apiBaseUrl ?? EVENT_BASED_DEFAULT_API_BASE_URL;\n providers.push({\n provide: EVENT_BASED_API_BASE_URL,\n useValue: apiBaseUrl,\n });\n return providers;\n}\n","import { ModuleWithProviders, NgModule } from '@angular/core';\nimport { QuaptEventFeedback } from './event-based';\nimport { EventBasedTriggerService } from './event-based-trigger.service';\nimport {\n EVENT_BASED_API_BASE_URL,\n type EventBasedConfig,\n} from './event-based.config';\n\n/**\n * NgModule for the event-based library.\n * Use forRoot() to configure the API base URL when using modules.\n */\n@NgModule({\n imports: [QuaptEventFeedback],\n exports: [QuaptEventFeedback],\n})\nexport class EventBasedModule {\n static forRoot(config: EventBasedConfig): ModuleWithProviders<EventBasedModule> {\n return {\n ngModule: EventBasedModule,\n providers: [\n EventBasedTriggerService,\n { provide: EVENT_BASED_API_BASE_URL, useValue: config.apiBaseUrl },\n ],\n };\n }\n}\n","/*\n * Public API Surface of event-based\n */\n\nexport * from './lib/event-based';\nexport * from './lib/event-based.config';\nexport * from './lib/event-based.types';\nexport * from './lib/event-based-trigger.service';\nexport * from './lib/event-based.providers';\nexport * from './lib/event-based.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.EventBasedTriggerService"],"mappings":";;;;;AAEA;AACA;AACA;AAEO,MAAM,gCAAgC,GAC3C;AAEF;;;AAGG;MACU,wBAAwB,GAAG,IAAI,cAAc,CACxD,0BAA0B;;ACL5B;;;;;;;;;;AAUG;MAEU,wBAAwB,CAAA;AAEhB,IAAA,IAAA;AAC8C,IAAA,UAAA;IAFjE,WAAA,CACmB,IAAgB,EAC8B,UAAyB,EAAA;QADvE,IAAA,CAAA,IAAI,GAAJ,IAAI;QAC0C,IAAA,CAAA,UAAU,GAAV,UAAU;IACxE;AAEH;;;;;;;AAOG;IACH,YAAY,CACV,OAA4B,EAC5B,UAAmB,EAAA;QAEnB,MAAM,IAAI,GACR,UAAU,IAAI,IAAI,CAAC,UAAU,IAAI,gCAAgC;AAEnE,QAAA,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,cAAc,CAAC;AACvD,QAAA,MAAM,IAAI,GAAG;YACX,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;AAC5C,YAAA,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,EAAE;SACnC;AAED,QAAA,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAsB,GAAG,EAAE,IAAI,CAAC,CAAC,IAAI,CACzD,UAAU,CAAC,CAAC,GAAG,KAAI;AACjB,YAAA,MAAM,OAAO,GAAG,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,IAAI,GAAG,EAAE,OAAO,IAAI,GAAG;AAC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;;;ACfD;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quapt/event-feedback",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/common": ">=15.0.0 <23",
|
|
6
|
+
"@angular/core": ">=15.0.0 <23"
|
|
7
|
+
},
|
|
8
|
+
"peerDependenciesMeta": {
|
|
9
|
+
"@angular/common": {
|
|
10
|
+
"optional": false
|
|
11
|
+
},
|
|
12
|
+
"@angular/core": {
|
|
13
|
+
"optional": false
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"tslib": "^2.3.0"
|
|
18
|
+
},
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"module": "fesm2022/quapt-event-feedback.mjs",
|
|
21
|
+
"typings": "types/quapt-event-feedback.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
"./package.json": {
|
|
24
|
+
"default": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./types/quapt-event-feedback.d.ts",
|
|
28
|
+
"default": "./fesm2022/quapt-event-feedback.mjs"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { InjectionToken, Provider, ModuleWithProviders } from '@angular/core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Single key-value pair for event context (e.g. EMAIL, NAME).
|
|
8
|
+
*/
|
|
9
|
+
interface EventDataItem {
|
|
10
|
+
fieldName: string;
|
|
11
|
+
fieldValue: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Options for triggering an event-based questionnaire.
|
|
15
|
+
*/
|
|
16
|
+
interface TriggerEventOptions {
|
|
17
|
+
organizationId: string;
|
|
18
|
+
appId: string;
|
|
19
|
+
groupId: string;
|
|
20
|
+
eventId: string;
|
|
21
|
+
questionnaireType: string;
|
|
22
|
+
eventData?: EventDataItem[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Result of a trigger request (success).
|
|
26
|
+
*/
|
|
27
|
+
interface TriggerEventSuccess {
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Service to trigger event-based questionnaires from any part of your Angular app.
|
|
33
|
+
* Use it after your own API calls succeed or fail to fire the trigger.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // In your component after your API call:
|
|
37
|
+
* this.myApi.submit(data).subscribe({
|
|
38
|
+
* next: () => this.eventBasedTrigger.triggerEvent({ organizationId, appId, ... }).subscribe(),
|
|
39
|
+
* error: () => this.eventBasedTrigger.triggerEvent({ organizationId, appId, ... }).subscribe()
|
|
40
|
+
* });
|
|
41
|
+
*/
|
|
42
|
+
declare class EventBasedTriggerService {
|
|
43
|
+
private readonly http;
|
|
44
|
+
private readonly apiBaseUrl;
|
|
45
|
+
constructor(http: HttpClient, apiBaseUrl: string | null);
|
|
46
|
+
/**
|
|
47
|
+
* Trigger the event-based questionnaire API.
|
|
48
|
+
* Call this in your subscribe (next or error) when you want to fire the trigger.
|
|
49
|
+
*
|
|
50
|
+
* @param options Trigger options (organizationId, appId, groupId, eventId, questionnaireType, eventData).
|
|
51
|
+
* @param apiBaseUrl Optional override for the API base URL (if not provided via token).
|
|
52
|
+
* @returns Observable that completes on success or error; never throws (errors are logged).
|
|
53
|
+
*/
|
|
54
|
+
triggerEvent(options: TriggerEventOptions, apiBaseUrl?: string): Observable<TriggerEventSuccess | null>;
|
|
55
|
+
private buildUrl;
|
|
56
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<EventBasedTriggerService, [null, { optional: true; }]>;
|
|
57
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<EventBasedTriggerService>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Reusable UI component that triggers the icxbee when the user
|
|
62
|
+
* clicks the button. Use when you want a visible trigger in the template.
|
|
63
|
+
*
|
|
64
|
+
* For triggering from code (e.g. after your own API success/fail), inject
|
|
65
|
+
* EventBasedTriggerService and call triggerEvent() in your subscribe.
|
|
66
|
+
*/
|
|
67
|
+
declare class QuaptEventFeedback {
|
|
68
|
+
private readonly trigger;
|
|
69
|
+
organizationId: string;
|
|
70
|
+
appId: string;
|
|
71
|
+
groupId: string;
|
|
72
|
+
eventId: string;
|
|
73
|
+
questionnaireType: string;
|
|
74
|
+
eventData: EventDataItem[];
|
|
75
|
+
buttonLabel: string;
|
|
76
|
+
buttonBgColor: string;
|
|
77
|
+
buttonColor: string;
|
|
78
|
+
buttonHeight: string;
|
|
79
|
+
constructor(trigger: EventBasedTriggerService);
|
|
80
|
+
triggerEvent(): void;
|
|
81
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<QuaptEventFeedback, never>;
|
|
82
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<QuaptEventFeedback, "quapt-event-feedback", never, { "organizationId": { "alias": "organizationId"; "required": false; }; "appId": { "alias": "appId"; "required": false; }; "groupId": { "alias": "groupId"; "required": false; }; "eventId": { "alias": "eventId"; "required": false; }; "questionnaireType": { "alias": "questionnaireType"; "required": false; }; "eventData": { "alias": "eventData"; "required": false; }; "buttonLabel": { "alias": "buttonLabel"; "required": false; }; "buttonBgColor": { "alias": "buttonBgColor"; "required": false; }; "buttonColor": { "alias": "buttonColor"; "required": false; }; "buttonHeight": { "alias": "buttonHeight"; "required": false; }; }, {}, never, never, true, never>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Default base URL for the event-based API (core-service). */
|
|
86
|
+
declare const EVENT_BASED_DEFAULT_API_BASE_URL = "https://iszg9dimg9.execute-api.ap-south-1.amazonaws.com/core-service/api/v1";
|
|
87
|
+
/**
|
|
88
|
+
* Base URL for the event-based API (e.g. `https://api.example.com`).
|
|
89
|
+
* The service will call `PATCH {baseUrl}/{organizationId}/questionnaires/trigger`.
|
|
90
|
+
*/
|
|
91
|
+
declare const EVENT_BASED_API_BASE_URL: InjectionToken<string>;
|
|
92
|
+
/**
|
|
93
|
+
* Optional global config for the event-based library.
|
|
94
|
+
*/
|
|
95
|
+
interface EventBasedConfig {
|
|
96
|
+
/** Base URL for the API. Required for the trigger service to work. */
|
|
97
|
+
apiBaseUrl: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Provide the event-based trigger service with optional config.
|
|
102
|
+
* Uses the default core-service API base URL when no config is passed.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* // main.ts (standalone) – uses default URL
|
|
106
|
+
* bootstrapApplication(AppComponent, {
|
|
107
|
+
* providers: [provideHttpClient(), provideEventBased()]
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* // With custom URL
|
|
112
|
+
* provideEventBased({ apiBaseUrl: 'https://api.example.com' })
|
|
113
|
+
*/
|
|
114
|
+
declare function provideEventBased(config?: EventBasedConfig): Provider[];
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* NgModule for the event-based library.
|
|
118
|
+
* Use forRoot() to configure the API base URL when using modules.
|
|
119
|
+
*/
|
|
120
|
+
declare class EventBasedModule {
|
|
121
|
+
static forRoot(config: EventBasedConfig): ModuleWithProviders<EventBasedModule>;
|
|
122
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<EventBasedModule, never>;
|
|
123
|
+
static ɵmod: i0.ɵɵNgModuleDeclaration<EventBasedModule, never, [typeof QuaptEventFeedback], [typeof QuaptEventFeedback]>;
|
|
124
|
+
static ɵinj: i0.ɵɵInjectorDeclaration<EventBasedModule>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { EVENT_BASED_API_BASE_URL, EVENT_BASED_DEFAULT_API_BASE_URL, EventBasedModule, EventBasedTriggerService, QuaptEventFeedback, provideEventBased };
|
|
128
|
+
export type { EventBasedConfig, EventDataItem, TriggerEventOptions, TriggerEventSuccess };
|