@ogcio/analytics-sdk 0.0.1-beta.1 → 0.0.1-beta.2

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 (50) hide show
  1. package/dist/index.d.ts +547 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +86 -9
  4. package/dist/matomo/helpers.d.ts +8 -0
  5. package/dist/matomo/helpers.d.ts.map +1 -1
  6. package/dist/matomo/helpers.js +79 -0
  7. package/dist/matomo/types.d.ts +5 -2
  8. package/dist/matomo/types.d.ts.map +1 -1
  9. package/dist/schema.d.ts +209 -13
  10. package/dist/schema.d.ts.map +1 -1
  11. package/package.json +8 -8
  12. package/src/index.ts +109 -15
  13. package/src/matomo/helpers.ts +101 -0
  14. package/src/matomo/types.ts +18 -2
  15. package/src/schema.ts +209 -13
  16. package/test-report.xml +181 -0
  17. package/dist/ogcio-analytics-sdk-0.0.1.tgz +0 -0
  18. package/dist/package/dist/base/base-client.d.ts +0 -36
  19. package/dist/package/dist/base/base-client.d.ts.map +0 -1
  20. package/dist/package/dist/base/base-client.js +0 -96
  21. package/dist/package/dist/index.d.ts +0 -651
  22. package/dist/package/dist/index.d.ts.map +0 -1
  23. package/dist/package/dist/index.js +0 -321
  24. package/dist/package/dist/matomo/helpers.d.ts +0 -9
  25. package/dist/package/dist/matomo/helpers.d.ts.map +0 -1
  26. package/dist/package/dist/matomo/helpers.js +0 -10
  27. package/dist/package/dist/matomo/types.d.ts +0 -33
  28. package/dist/package/dist/matomo/types.d.ts.map +0 -1
  29. package/dist/package/dist/matomo/types.js +0 -1
  30. package/dist/package/dist/schema.d.ts +0 -1295
  31. package/dist/package/dist/schema.d.ts.map +0 -1
  32. package/dist/package/dist/schema.js +0 -5
  33. package/dist/package/dist/support-files/auth/index.d.ts +0 -3
  34. package/dist/package/dist/support-files/auth/index.d.ts.map +0 -1
  35. package/dist/package/dist/support-files/auth/index.js +0 -76
  36. package/dist/package/dist/support-files/auth/types.d.ts +0 -31
  37. package/dist/package/dist/support-files/auth/types.d.ts.map +0 -1
  38. package/dist/package/dist/support-files/auth/types.js +0 -1
  39. package/dist/package/dist/support-files/building-blocks-sdk.d.ts +0 -17
  40. package/dist/package/dist/support-files/building-blocks-sdk.d.ts.map +0 -1
  41. package/dist/package/dist/support-files/building-blocks-sdk.js +0 -11
  42. package/dist/package/dist/utils/index.d.ts +0 -7
  43. package/dist/package/dist/utils/index.d.ts.map +0 -1
  44. package/dist/package/dist/utils/index.js +0 -19
  45. package/dist/package/examples/environment.d.ts +0 -11
  46. package/dist/package/examples/index.ts +0 -201
  47. package/dist/package/examples/tsconfig.json +0 -15
  48. package/dist/package/package.json +0 -56
  49. package/dist/package/tsconfig.json +0 -18
  50. package/dist/package/types.d.ts +0 -19
package/src/schema.ts CHANGED
@@ -715,6 +715,8 @@ export interface paths {
715
715
  value?: number;
716
716
  };
717
717
  metadata?: {
718
+ /** @description The URL of the page */
719
+ url?: string;
718
720
  /** @description The user agent of the user */
719
721
  userAgent?: string;
720
722
  /** @description The referrer of the user */
@@ -806,6 +808,8 @@ export interface paths {
806
808
  action_name: string;
807
809
  };
808
810
  metadata?: {
811
+ /** @description The URL of the page */
812
+ url?: string;
809
813
  /** @description The user agent of the user */
810
814
  userAgent?: string;
811
815
  /** @description The referrer of the user */
@@ -901,6 +905,8 @@ export interface paths {
901
905
  search_count?: number;
902
906
  };
903
907
  metadata?: {
908
+ /** @description The URL of the page */
909
+ url?: string;
904
910
  /** @description The user agent of the user */
905
911
  userAgent?: string;
906
912
  /** @description The referrer of the user */
@@ -959,7 +965,7 @@ export interface paths {
959
965
  patch?: never;
960
966
  trace?: never;
961
967
  };
962
- "/api/v1/websites/{id}/track-out-link": {
968
+ "/api/v1/websites/{id}/track-link": {
963
969
  parameters: {
964
970
  query?: never;
965
971
  header?: never;
@@ -968,7 +974,7 @@ export interface paths {
968
974
  };
969
975
  get?: never;
970
976
  put?: never;
971
- /** @description Track outgoing link */
977
+ /** @description Track link that could be an outgoing link or a download link */
972
978
  post: {
973
979
  parameters: {
974
980
  query?: {
@@ -988,20 +994,210 @@ export interface paths {
988
994
  /** @description Array of site IDs */
989
995
  site_ids?: number[];
990
996
  event: {
991
- /** @description An external URL the user has opened. Used for tracking outlink clicks. */
997
+ /** @description The type of the link - either 'link' for outgoing links or 'download' for downloads */
998
+ linkType: "link" | "download";
999
+ /** @description The URL of the link */
992
1000
  link: string;
993
- /**
994
- * @description Custom dimensions example: { 'dimension1': 'value1', 'dimension2': 'value2' }
995
- * @example {
996
- * "dimension1": "value1",
997
- * "dimension2": "value2"
998
- * }
999
- */
1000
- dimensions?: {
1001
- [key: string]: string;
1002
- };
1003
1001
  };
1004
1002
  metadata?: {
1003
+ /** @description The URL of the page */
1004
+ url?: string;
1005
+ /** @description The user agent of the user */
1006
+ userAgent?: string;
1007
+ /** @description The referrer of the user */
1008
+ referrer?: string;
1009
+ /** @description The language of the user */
1010
+ language?: string;
1011
+ /** @description The resolution of the device */
1012
+ screenResolution?: string;
1013
+ /** @description The user ID of the user, User ID is any non-empty unique string identifying the user (such as an email address or a username). */
1014
+ userId?: string;
1015
+ };
1016
+ };
1017
+ };
1018
+ };
1019
+ responses: {
1020
+ /** @description Default Response */
1021
+ 200: {
1022
+ headers: {
1023
+ [name: string]: unknown;
1024
+ };
1025
+ content: {
1026
+ "application/json": {
1027
+ data: unknown;
1028
+ };
1029
+ };
1030
+ };
1031
+ /** @description Default Response */
1032
+ 500: {
1033
+ headers: {
1034
+ [name: string]: unknown;
1035
+ };
1036
+ content: {
1037
+ "application/json": {
1038
+ /** @description Code used to categorize the error */
1039
+ code: string;
1040
+ /** @description Description of the error */
1041
+ detail: string;
1042
+ /** @description Unique request id. This one will be used to troubleshoot the problems */
1043
+ requestId: string;
1044
+ /** @description Name of the error type */
1045
+ name: string;
1046
+ /** @description List of the validation errors */
1047
+ validation?: {
1048
+ fieldName: string;
1049
+ message: string;
1050
+ }[];
1051
+ validationContext?: string;
1052
+ };
1053
+ };
1054
+ };
1055
+ };
1056
+ };
1057
+ delete?: never;
1058
+ options?: never;
1059
+ head?: never;
1060
+ patch?: never;
1061
+ trace?: never;
1062
+ };
1063
+ "/api/v1/websites/{id}/track-content-impression": {
1064
+ parameters: {
1065
+ query?: never;
1066
+ header?: never;
1067
+ path?: never;
1068
+ cookie?: never;
1069
+ };
1070
+ get?: never;
1071
+ put?: never;
1072
+ /** @description Track content impression for a website */
1073
+ post: {
1074
+ parameters: {
1075
+ query?: {
1076
+ /** @description If true, use code-based tracking */
1077
+ code?: boolean;
1078
+ };
1079
+ header?: never;
1080
+ path: {
1081
+ /** @description Website UUID */
1082
+ id: string;
1083
+ };
1084
+ cookie?: never;
1085
+ };
1086
+ requestBody: {
1087
+ content: {
1088
+ "application/json": {
1089
+ /** @description Array of site IDs */
1090
+ site_ids?: number[];
1091
+ event: {
1092
+ /** @description The name of the content block */
1093
+ content_name: string;
1094
+ /** @description The piece of the content that was displayed (e.g. link to an image) */
1095
+ content_piece: string;
1096
+ /** @description The target of the content leads to (e.g. URL of some external website) */
1097
+ content_target: string;
1098
+ };
1099
+ metadata?: {
1100
+ /** @description The URL of the page */
1101
+ url?: string;
1102
+ /** @description The user agent of the user */
1103
+ userAgent?: string;
1104
+ /** @description The referrer of the user */
1105
+ referrer?: string;
1106
+ /** @description The language of the user */
1107
+ language?: string;
1108
+ /** @description The resolution of the device */
1109
+ screenResolution?: string;
1110
+ /** @description The user ID of the user, User ID is any non-empty unique string identifying the user (such as an email address or a username). */
1111
+ userId?: string;
1112
+ };
1113
+ };
1114
+ };
1115
+ };
1116
+ responses: {
1117
+ /** @description Default Response */
1118
+ 200: {
1119
+ headers: {
1120
+ [name: string]: unknown;
1121
+ };
1122
+ content: {
1123
+ "application/json": {
1124
+ data: unknown;
1125
+ };
1126
+ };
1127
+ };
1128
+ /** @description Default Response */
1129
+ 500: {
1130
+ headers: {
1131
+ [name: string]: unknown;
1132
+ };
1133
+ content: {
1134
+ "application/json": {
1135
+ /** @description Code used to categorize the error */
1136
+ code: string;
1137
+ /** @description Description of the error */
1138
+ detail: string;
1139
+ /** @description Unique request id. This one will be used to troubleshoot the problems */
1140
+ requestId: string;
1141
+ /** @description Name of the error type */
1142
+ name: string;
1143
+ /** @description List of the validation errors */
1144
+ validation?: {
1145
+ fieldName: string;
1146
+ message: string;
1147
+ }[];
1148
+ validationContext?: string;
1149
+ };
1150
+ };
1151
+ };
1152
+ };
1153
+ };
1154
+ delete?: never;
1155
+ options?: never;
1156
+ head?: never;
1157
+ patch?: never;
1158
+ trace?: never;
1159
+ };
1160
+ "/api/v1/websites/{id}/track-content-interaction": {
1161
+ parameters: {
1162
+ query?: never;
1163
+ header?: never;
1164
+ path?: never;
1165
+ cookie?: never;
1166
+ };
1167
+ get?: never;
1168
+ put?: never;
1169
+ /** @description Track content interaction for a website */
1170
+ post: {
1171
+ parameters: {
1172
+ query?: {
1173
+ /** @description If true, use code-based tracking */
1174
+ code?: boolean;
1175
+ };
1176
+ header?: never;
1177
+ path: {
1178
+ /** @description Website UUID */
1179
+ id: string;
1180
+ };
1181
+ cookie?: never;
1182
+ };
1183
+ requestBody: {
1184
+ content: {
1185
+ "application/json": {
1186
+ /** @description Array of site IDs */
1187
+ site_ids?: number[];
1188
+ event: {
1189
+ /** @description The name of the content block */
1190
+ content_name: string;
1191
+ /** @description The piece of the content that was displayed (e.g. link to an image) */
1192
+ content_piece: string;
1193
+ /** @description The target of the content leads to (e.g. URL of some external website) */
1194
+ content_target: string;
1195
+ /** @description The interaction of the content, example: 'click' */
1196
+ content_interaction: string;
1197
+ };
1198
+ metadata?: {
1199
+ /** @description The URL of the page */
1200
+ url?: string;
1005
1201
  /** @description The user agent of the user */
1006
1202
  userAgent?: string;
1007
1203
  /** @description The referrer of the user */
@@ -0,0 +1,181 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <testsuites id="20241030_131304618" name="TAP Tests" tests="35" failures="0" assertions="23" skipped="0" time="1.039021">
3
+ <properties>
4
+ <property name="ok" value="true" />
5
+ <property name="plan"><![CDATA[
6
+ start: 1
7
+ end: 2
8
+ skipAll: false
9
+ skipReason: ""
10
+ comment: ""
11
+ ]]></property>
12
+ </properties>
13
+ <testsuite name="src/index.test.ts" tests="19" failures="0" assertions="14" skipped="0" time="0.948131">
14
+ <properties>
15
+ <property name="ok" value="true" />
16
+ <property name="plan"><![CDATA[
17
+ start: 1
18
+ end: 1
19
+ skipAll: false
20
+ skipReason: ""
21
+ comment: ""
22
+ ]]></property>
23
+ </properties>
24
+ <testsuite name="Analytics - Dry Run and Opt Out" tests="17" failures="0" assertions="13" skipped="0" time="0.026081">
25
+ <properties>
26
+ <property name="ok" value="true" />
27
+ <property name="plan"><![CDATA[
28
+ start: 1
29
+ end: 3
30
+ skipAll: false
31
+ skipReason: ""
32
+ comment: ""
33
+ ]]></property>
34
+ </properties>
35
+ <testsuite name="Analytics Config" tests="5" failures="0" assertions="4" skipped="0" time="0.009041">
36
+ <properties>
37
+ <property name="ok" value="true" />
38
+ <property name="plan"><![CDATA[
39
+ start: 1
40
+ end: 4
41
+ skipAll: false
42
+ skipReason: ""
43
+ comment: ""
44
+ ]]></property>
45
+ </properties>
46
+
47
+ <testcase id="1" name="Dry run should be set to true" classname="src/index.test.ts &gt; Analytics - Dry Run and Opt Out &gt; Analytics Config" />
48
+ <testcase id="2" name="Opt out should be set to false" classname="src/index.test.ts &gt; Analytics - Dry Run and Opt Out &gt; Analytics Config" />
49
+ <testcase id="3" name="Dry run should be set to false" classname="src/index.test.ts &gt; Analytics - Dry Run and Opt Out &gt; Analytics Config" />
50
+ <testcase id="4" name="Opt out should be set to true" classname="src/index.test.ts &gt; Analytics - Dry Run and Opt Out &gt; Analytics Config" />
51
+ </testsuite>
52
+
53
+ <testsuite name="Dry Run" tests="4" failures="0" assertions="3" skipped="0" time="0.013317">
54
+ <properties>
55
+ <property name="ok" value="true" />
56
+ <property name="plan"><![CDATA[
57
+ start: 1
58
+ end: 3
59
+ skipAll: false
60
+ skipReason: ""
61
+ comment: ""
62
+ ]]></property>
63
+ </properties>
64
+
65
+ <testcase id="1" name="No data should be returned in dry run mode" classname="src/index.test.ts &gt; Analytics - Dry Run and Opt Out &gt; Dry Run" />
66
+ <testcase id="2" name="No error should be returned in dry run mode" classname="src/index.test.ts &gt; Analytics - Dry Run and Opt Out &gt; Dry Run" />
67
+ <testcase id="3" name="Console warning should be logged" classname="src/index.test.ts &gt; Analytics - Dry Run and Opt Out &gt; Dry Run" />
68
+ </testsuite>
69
+
70
+ <testsuite name="Opt Out" tests="4" failures="0" assertions="3" skipped="0" time="0.001899">
71
+ <properties>
72
+ <property name="ok" value="true" />
73
+ <property name="plan"><![CDATA[
74
+ start: 1
75
+ end: 3
76
+ skipAll: false
77
+ skipReason: ""
78
+ comment: ""
79
+ ]]></property>
80
+ </properties>
81
+
82
+ <testcase id="1" name="No data should be returned when opted out" classname="src/index.test.ts &gt; Analytics - Dry Run and Opt Out &gt; Opt Out" />
83
+ <testcase id="2" name="No error should be returned when opted out" classname="src/index.test.ts &gt; Analytics - Dry Run and Opt Out &gt; Opt Out" />
84
+ <testcase id="3" name="Console warning should be logged" classname="src/index.test.ts &gt; Analytics - Dry Run and Opt Out &gt; Opt Out" />
85
+ </testsuite>
86
+ <testcase id="1" name="Analytics Config" classname="src/index.test.ts &gt; Analytics - Dry Run and Opt Out" time="0.009041" />
87
+ <testcase id="2" name="Dry Run" classname="src/index.test.ts &gt; Analytics - Dry Run and Opt Out" time="0.013317" />
88
+ <testcase id="3" name="Opt Out" classname="src/index.test.ts &gt; Analytics - Dry Run and Opt Out" time="0.001899" />
89
+ </testsuite>
90
+ <testcase id="1" name="Analytics - Dry Run and Opt Out" classname="src/index.test.ts" time="0.026081" />
91
+ </testsuite>
92
+
93
+ <testsuite name="src/utils/index.test.ts" tests="15" failures="0" assertions="9" skipped="0" time="0.597372">
94
+ <properties>
95
+ <property name="ok" value="true" />
96
+ <property name="plan"><![CDATA[
97
+ start: 1
98
+ end: 1
99
+ skipAll: false
100
+ skipReason: ""
101
+ comment: ""
102
+ ]]></property>
103
+ </properties>
104
+ <testsuite name="ensureTrailingSlash" tests="13" failures="0" assertions="8" skipped="0" time="0.004302">
105
+ <properties>
106
+ <property name="ok" value="true" />
107
+ <property name="plan"><![CDATA[
108
+ start: 1
109
+ end: 4
110
+ skipAll: false
111
+ skipReason: ""
112
+ comment: ""
113
+ ]]></property>
114
+ </properties>
115
+ <testsuite name="should add a trailing slash if not present" tests="2" failures="0" assertions="1" skipped="0" time="0.001184">
116
+ <properties>
117
+ <property name="ok" value="true" />
118
+ <property name="plan"><![CDATA[
119
+ start: 1
120
+ end: 1
121
+ skipAll: false
122
+ skipReason: ""
123
+ comment: ""
124
+ ]]></property>
125
+ </properties>
126
+
127
+ <testcase id="1" name="Adds trailing slash" classname="src/utils/index.test.ts &gt; ensureTrailingSlash &gt; should add a trailing slash if not present" />
128
+ </testsuite>
129
+
130
+ <testsuite name="should not add a trailing slash if already present" tests="2" failures="0" assertions="1" skipped="0" time="0.000165">
131
+ <properties>
132
+ <property name="ok" value="true" />
133
+ <property name="plan"><![CDATA[
134
+ start: 1
135
+ end: 1
136
+ skipAll: false
137
+ skipReason: ""
138
+ comment: ""
139
+ ]]></property>
140
+ </properties>
141
+
142
+ <testcase id="1" name="Keeps existing trailing slash" classname="src/utils/index.test.ts &gt; ensureTrailingSlash &gt; should not add a trailing slash if already present" />
143
+ </testsuite>
144
+
145
+ <testsuite name="should handle empty string" tests="2" failures="0" assertions="1" skipped="0" time="0.000154">
146
+ <properties>
147
+ <property name="ok" value="true" />
148
+ <property name="plan"><![CDATA[
149
+ start: 1
150
+ end: 1
151
+ skipAll: false
152
+ skipReason: ""
153
+ comment: ""
154
+ ]]></property>
155
+ </properties>
156
+
157
+ <testcase id="1" name="Adds trailing slash to empty string" classname="src/utils/index.test.ts &gt; ensureTrailingSlash &gt; should handle empty string" />
158
+ </testsuite>
159
+
160
+ <testsuite name="should not add a trailing slash if already present" tests="2" failures="0" assertions="1" skipped="0" time="0.000143">
161
+ <properties>
162
+ <property name="ok" value="true" />
163
+ <property name="plan"><![CDATA[
164
+ start: 1
165
+ end: 1
166
+ skipAll: false
167
+ skipReason: ""
168
+ comment: ""
169
+ ]]></property>
170
+ </properties>
171
+
172
+ <testcase id="1" name="Keeps existing trailing slash" classname="src/utils/index.test.ts &gt; ensureTrailingSlash &gt; should not add a trailing slash if already present" />
173
+ </testsuite>
174
+ <testcase id="1" name="should add a trailing slash if not present" classname="src/utils/index.test.ts &gt; ensureTrailingSlash" time="0.001184" />
175
+ <testcase id="2" name="should not add a trailing slash if already present" classname="src/utils/index.test.ts &gt; ensureTrailingSlash" time="0.000165" />
176
+ <testcase id="3" name="should handle empty string" classname="src/utils/index.test.ts &gt; ensureTrailingSlash" time="0.000154" />
177
+ <testcase id="4" name="should not add a trailing slash if already present" classname="src/utils/index.test.ts &gt; ensureTrailingSlash" time="0.000143" />
178
+ </testsuite>
179
+ <testcase id="1" name="ensureTrailingSlash" classname="src/utils/index.test.ts" time="0.004302" />
180
+ </testsuite>
181
+ </testsuites>
Binary file
@@ -1,36 +0,0 @@
1
- import createClient, { type FetchResponse, ParseAsResponse } from "openapi-fetch";
2
- import type { ErrorStatus, FilterKeys, OkStatus, ResponseContent, ResponseObjectMap } from "openapi-typescript-helpers";
3
- export declare const ANALYTICS: "analytics";
4
- export type SERVICE_NAME = typeof ANALYTICS;
5
- export type TokenFunction = (serviceName: SERVICE_NAME) => Promise<string> | string;
6
- export type SDKClientParams = {
7
- baseUrl?: string;
8
- };
9
- export type BaseApiClientParams = SDKClientParams & {
10
- getTokenFn?: TokenFunction;
11
- };
12
- export type DataResponseValue<T, O> = ParseAsResponse<FilterKeys<ResponseContent<FilterKeys<ResponseObjectMap<T>, OkStatus>>, "application/json">, O> & {
13
- error: ParseAsResponse<FilterKeys<ResponseContent<FilterKeys<ResponseObjectMap<T>, ErrorStatus>>, "application/json">, O>;
14
- };
15
- /**
16
- * This decorator is used to check if the baseUrl or token of the client are set.
17
- * If the baseUrl or token are not set, it throws an error
18
- */
19
- export declare function needsBackend(target: unknown, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
20
- declare abstract class BaseClient<T extends object> {
21
- private baseUrl?;
22
- private initialized;
23
- protected token?: string;
24
- protected getTokenFn?: TokenFunction;
25
- protected serviceName: SERVICE_NAME | undefined;
26
- protected client: ReturnType<typeof createClient<T>>;
27
- constructor({ baseUrl, getTokenFn }: BaseApiClientParams);
28
- deleteToken(): void;
29
- protected getToken(): Promise<string | undefined>;
30
- isInitialized(): boolean;
31
- protected formatResponse<G extends Record<string, unknown>, O>(response: FetchResponse<G, O, "application/json">): DataResponseValue<G, O>;
32
- protected formatError<G, O>(reason: unknown): DataResponseValue<G, O>;
33
- protected checkBackend(): Promise<void>;
34
- }
35
- export default BaseClient;
36
- //# sourceMappingURL=base-client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base-client.d.ts","sourceRoot":"","sources":["../../src/base/base-client.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,EAAE,EAEnB,KAAK,aAAa,EAClB,eAAe,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,QAAQ,EACR,eAAe,EACf,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAEpC,eAAO,MAAM,SAAS,aAAuB,CAAC;AAE9C,MAAM,MAAM,YAAY,GAAG,OAAO,SAAS,CAAC;AAE5C,MAAM,MAAM,aAAa,GAAG,CAC1B,WAAW,EAAE,YAAY,KACtB,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AAE9B,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG;IAClD,UAAU,CAAC,EAAE,aAAa,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,CAAC,IAAI,eAAe,CACnD,UAAU,CACR,eAAe,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,EAC3D,kBAAkB,CACnB,EACD,CAAC,CACF,GAAG;IACF,KAAK,EAAE,eAAe,CACpB,UAAU,CACR,eAAe,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,EAC9D,kBAAkB,CACnB,EACD,CAAC,CACF,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,kBAAkB,sBAW/B;AAED,uBAAe,UAAU,CAAC,CAAC,SAAS,MAAM;IACxC,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,WAAW,CAAC;IAEpB,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC;IACrC,SAAS,CAAC,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC;IAEhD,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;gBAEzC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,mBAAmB;IA6BjD,WAAW;cAIF,QAAQ;IASjB,aAAa;IAIpB,SAAS,CAAC,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,EAC3D,QAAQ,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,kBAAkB,CAAC,GAChD,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC;IA0B1B,SAAS,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC;cAKrD,YAAY;CAe7B;AAED,eAAe,UAAU,CAAC"}
@@ -1,96 +0,0 @@
1
- import createClient from "openapi-fetch";
2
- export const ANALYTICS = "analytics";
3
- /**
4
- * This decorator is used to check if the baseUrl or token of the client are set.
5
- * If the baseUrl or token are not set, it throws an error
6
- */
7
- export function needsBackend(target, propertyKey, descriptor) {
8
- const originalMethod = descriptor.value;
9
- descriptor.value = async function (...args) {
10
- this.checkBackend();
11
- return originalMethod.apply(this, args);
12
- };
13
- return descriptor;
14
- }
15
- class BaseClient {
16
- baseUrl;
17
- initialized;
18
- token;
19
- getTokenFn;
20
- serviceName;
21
- client;
22
- constructor({ baseUrl, getTokenFn }) {
23
- this.initialized = false;
24
- if (baseUrl) {
25
- this.baseUrl = baseUrl;
26
- this.initialized = true;
27
- }
28
- if (getTokenFn) {
29
- this.getTokenFn = getTokenFn;
30
- }
31
- this.token = undefined;
32
- this.client = createClient({ baseUrl: this.baseUrl });
33
- const authMiddleware = {
34
- onRequest: async ({ request }) => {
35
- if (!this.token && this.getTokenFn) {
36
- this.token = await this.getTokenFn(this.serviceName);
37
- }
38
- if (this.token) {
39
- request.headers.set("Authorization", `Bearer ${this.token}`);
40
- }
41
- return request;
42
- },
43
- };
44
- this.client.use(authMiddleware);
45
- }
46
- deleteToken() {
47
- this.token = undefined;
48
- }
49
- async getToken() {
50
- if (this.getTokenFn) {
51
- const token = await this.getTokenFn(this.serviceName);
52
- this.token = token;
53
- }
54
- return this.token;
55
- }
56
- isInitialized() {
57
- return this.initialized;
58
- }
59
- formatResponse(response) {
60
- let outputData = undefined;
61
- let outputMetadata = undefined;
62
- if (!response) {
63
- return {};
64
- }
65
- if (response.data) {
66
- const dataEntries = Object.entries(response.data);
67
- // by docs the body should contain a "data"
68
- // properties with the response values
69
- const containsData = dataEntries.find((x) => x[0] === "data");
70
- const containsMetadata = dataEntries.find((x) => x[0] === "metadata");
71
- if (containsMetadata) {
72
- outputMetadata = containsMetadata[1];
73
- }
74
- outputData = containsData ? containsData[1] : response.data;
75
- }
76
- return {
77
- data: outputData,
78
- metadata: outputMetadata,
79
- error: response.error,
80
- };
81
- }
82
- formatError(reason) {
83
- return { error: reason };
84
- }
85
- /* checkBackend is a protected method used by needsBackend decorator */
86
- async checkBackend() {
87
- const className = this.constructor.name;
88
- if (!this.baseUrl) {
89
- throw new Error(`${className} baseUrl is not set. Please provide a valid baseUrl when initializing ${className} SDK methods.`);
90
- }
91
- if (!this.token && !this.getTokenFn) {
92
- throw new Error(`${className} token is not set. Please provide a valid getTokenFn function when initializing ${className} SDK methods.`);
93
- }
94
- }
95
- }
96
- export default BaseClient;