@monterosa/sdk-core 0.17.1-rc.6

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,395 @@
1
+ import { v4 } from 'uuid';
2
+ import { checkAvailability, getItem, setItem } from '@monterosa/sdk-util';
3
+
4
+ var version = "0.17.1";
5
+
6
+ /**
7
+ * @license
8
+ * constants.ts
9
+ * core
10
+ *
11
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-03-21
12
+ * Copyright © 2023 Monterosa. All rights reserved.
13
+ *
14
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
15
+ */
16
+ /**
17
+ * Default sdk name.
18
+ *
19
+ * @internal
20
+ */
21
+ var DEFAULT_SDK_NAME = '[DEFAULT]';
22
+ /**
23
+ * The current SDK version.
24
+ *
25
+ * @public
26
+ */
27
+ var VERSION = version;
28
+ /**
29
+ * Device ID storage key name
30
+ *
31
+ * @internal
32
+ */
33
+ var DEVICE_ID_KEY = 'device_id';
34
+
35
+ /*! *****************************************************************************
36
+ Copyright (c) Microsoft Corporation.
37
+
38
+ Permission to use, copy, modify, and/or distribute this software for any
39
+ purpose with or without fee is hereby granted.
40
+
41
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
42
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
43
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
44
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
45
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
46
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
47
+ PERFORMANCE OF THIS SOFTWARE.
48
+ ***************************************************************************** */
49
+
50
+ var __assign = function() {
51
+ __assign = Object.assign || function __assign(t) {
52
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
53
+ s = arguments[i];
54
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
55
+ }
56
+ return t;
57
+ };
58
+ return __assign.apply(this, arguments);
59
+ };
60
+
61
+ function __spreadArray(to, from) {
62
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
63
+ to[j] = from[i];
64
+ return to;
65
+ }
66
+
67
+ /**
68
+ * @license
69
+ * sdk.ts
70
+ * core
71
+ *
72
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2021-09-23
73
+ * Copyright © 2022 Monterosa. All rights reserved.
74
+ *
75
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
76
+ */
77
+ /**
78
+ * @internal
79
+ */
80
+ var Sdk = /** @class */ (function () {
81
+ function Sdk(options, name) {
82
+ this._isDestroyed = false;
83
+ this._options = __assign({}, options);
84
+ this._name = name;
85
+ this._kits = new Map();
86
+ }
87
+ Object.defineProperty(Sdk.prototype, "name", {
88
+ get: function () {
89
+ this.checkDestroyed();
90
+ return this._name;
91
+ },
92
+ enumerable: false,
93
+ configurable: true
94
+ });
95
+ Object.defineProperty(Sdk.prototype, "options", {
96
+ get: function () {
97
+ this.checkDestroyed();
98
+ return this._options;
99
+ },
100
+ enumerable: false,
101
+ configurable: true
102
+ });
103
+ Object.defineProperty(Sdk.prototype, "isDestroyed", {
104
+ get: function () {
105
+ return this._isDestroyed;
106
+ },
107
+ set: function (value) {
108
+ this._isDestroyed = value;
109
+ },
110
+ enumerable: false,
111
+ configurable: true
112
+ });
113
+ Object.defineProperty(Sdk.prototype, "kits", {
114
+ get: function () {
115
+ return this._kits;
116
+ },
117
+ enumerable: false,
118
+ configurable: true
119
+ });
120
+ Sdk.prototype.deleteKits = function () {
121
+ var _this = this;
122
+ this.kits.forEach(function (kit, name) {
123
+ _this.kits.delete(name);
124
+ kit.delete();
125
+ });
126
+ };
127
+ Sdk.prototype.checkDestroyed = function () {
128
+ if (this.isDestroyed) {
129
+ throw new Error("SDK named " + this.name + " destroyed");
130
+ }
131
+ };
132
+ return Sdk;
133
+ }());
134
+ /**
135
+ * @internal
136
+ */
137
+ function addKit(sdk, name, kit) {
138
+ sdk.kits.set(name, kit);
139
+ }
140
+ /**
141
+ * @internal
142
+ */
143
+ function getKit(sdk, name) {
144
+ return sdk.kits.get(name);
145
+ }
146
+ /**
147
+ * @internal
148
+ */
149
+ function deleteKit(sdk, name) {
150
+ sdk.kits.delete(name);
151
+ }
152
+
153
+ /**
154
+ * @license
155
+ * api.ts
156
+ * core
157
+ *
158
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
159
+ * Copyright © 2022 Monterosa. All rights reserved.
160
+ *
161
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
162
+ */
163
+ var sdks = new Map();
164
+ var DEVICE_ID;
165
+ /**
166
+ * An array of all configured sdks.
167
+ *
168
+ * @public
169
+ */
170
+ function getSdks() {
171
+ return Array.from(sdks.values());
172
+ }
173
+ /**
174
+ * Retrieves an SDK instance by its name.
175
+ *
176
+ * @example
177
+ * ```javascript
178
+ * const sdk = getSdk('my-sdk');
179
+ * ```
180
+ *
181
+ * @param name - Optional name of the sdk to initialise.
182
+ * If name is not provided, the default is "[DEFAULT]"
183
+ *
184
+ * @public
185
+ */
186
+ function getSdk(name) {
187
+ if (name === void 0) { name = DEFAULT_SDK_NAME; }
188
+ var sdk = sdks.get(name);
189
+ if (!sdk) {
190
+ throw new Error("No Monterosa Sdk \"" + name + "\" has been configured.\n You need to call configure() first");
191
+ }
192
+ return sdk;
193
+ }
194
+ /**
195
+ * @internal
196
+ */
197
+ function getDeviceId() {
198
+ if (DEVICE_ID !== undefined) {
199
+ return DEVICE_ID;
200
+ }
201
+ if (!checkAvailability()) {
202
+ DEVICE_ID = v4();
203
+ return DEVICE_ID;
204
+ }
205
+ var value = getItem(DEVICE_ID_KEY);
206
+ if (value === null) {
207
+ DEVICE_ID = v4();
208
+ setItem(DEVICE_ID_KEY, DEVICE_ID);
209
+ }
210
+ else {
211
+ DEVICE_ID = value;
212
+ }
213
+ return DEVICE_ID;
214
+ }
215
+ /**
216
+ * Creates an SDK instance.
217
+ *
218
+ * @example
219
+ *
220
+ * Configure default sdk with host and project id
221
+ *
222
+ * ```javascript
223
+ * configure({
224
+ * host: "...",
225
+ * projectId: "..."
226
+ * });
227
+ * ```
228
+ *
229
+ * @param options - Studio host
230
+ * @param name - Optional name of the sdk to initialise.
231
+ * If name is not provided, the default is "[DEFAULT]"
232
+ *
233
+ * @returns Configured SDK instance.
234
+ *
235
+ * @public
236
+ */
237
+ function configure(options, name) {
238
+ if (name === void 0) { name = DEFAULT_SDK_NAME; }
239
+ var existingSdk = sdks.get(name);
240
+ if (existingSdk) {
241
+ return existingSdk;
242
+ }
243
+ var sdk = new Sdk(options, name);
244
+ sdks.set(name, sdk);
245
+ return sdk;
246
+ }
247
+ /**
248
+ * Destroy initialised sdk
249
+ *
250
+ * @example
251
+ * ```javascript
252
+ * const sdk = configure(...);
253
+ *
254
+ * destroy(sdk);
255
+ * ```
256
+ *
257
+ * @param sdk - sdk instance
258
+ */
259
+ function destroy(sdk) {
260
+ var name = sdk.name;
261
+ sdks.delete(name);
262
+ sdk.deleteKits();
263
+ sdk.isDestroyed = true;
264
+ }
265
+
266
+ /**
267
+ * @license
268
+ * logger.ts
269
+ * core
270
+ *
271
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-05-31
272
+ * Copyright © 2022 Monterosa. All rights reserved.
273
+ *
274
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
275
+ */
276
+ var _a;
277
+ /* eslint-disable no-console */
278
+ /**
279
+ * Represents the possible log levels.
280
+ */
281
+ var LogLevel;
282
+ (function (LogLevel) {
283
+ /**
284
+ * Verbose level. Provides detailed and extensive logging.
285
+ */
286
+ LogLevel[LogLevel["Verbose"] = 0] = "Verbose";
287
+ /**
288
+ * Debug level. Used for debugging and development purposes.
289
+ */
290
+ LogLevel[LogLevel["Debug"] = 1] = "Debug";
291
+ /**
292
+ * Info level. Used to provide general information about the system's state.
293
+ */
294
+ LogLevel[LogLevel["Info"] = 2] = "Info";
295
+ /**
296
+ * Warn level. Indicates potential issues or situations that might cause problems in the future.
297
+ */
298
+ LogLevel[LogLevel["Warn"] = 3] = "Warn";
299
+ /**
300
+ * Error level. Indicates critical errors and issues that require immediate attention.
301
+ */
302
+ LogLevel[LogLevel["Error"] = 4] = "Error";
303
+ /**
304
+ * Silent level. No logs will be output.
305
+ */
306
+ LogLevel[LogLevel["Silent"] = 5] = "Silent";
307
+ })(LogLevel || (LogLevel = {}));
308
+ var Methods = (_a = {},
309
+ _a[LogLevel.Verbose] = 'log',
310
+ // `console.debug` is not shown in Chrome and Edge by default. It must be
311
+ // enabled manually. To avoid hassle for developers with settings debug
312
+ // messages are sent to `console.log`
313
+ _a[LogLevel.Debug] = 'log',
314
+ _a[LogLevel.Info] = 'info',
315
+ _a[LogLevel.Warn] = 'warn',
316
+ _a[LogLevel.Error] = 'error',
317
+ _a);
318
+ var logHandler = function (logger, logLevel) {
319
+ var args = [];
320
+ for (var _i = 2; _i < arguments.length; _i++) {
321
+ args[_i - 2] = arguments[_i];
322
+ }
323
+ if (logger.logLevel > logLevel) {
324
+ return;
325
+ }
326
+ var method = Methods[logLevel];
327
+ console[method].apply(console, __spreadArray([new Date().toISOString().replace(/[TZ]/gi, ' ').trim(), LogLevel[logLevel] + "/" + logger.name + ":"], args));
328
+ };
329
+ /** @internal */
330
+ var Logger = /** @class */ (function () {
331
+ function Logger(name) {
332
+ this.name = name;
333
+ this._logLevel = LogLevel.Warn;
334
+ this._logHandler = logHandler;
335
+ }
336
+ Object.defineProperty(Logger.prototype, "logLevel", {
337
+ get: function () {
338
+ return this._logLevel;
339
+ },
340
+ set: function (level) {
341
+ this._logLevel = level;
342
+ },
343
+ enumerable: false,
344
+ configurable: true
345
+ });
346
+ Object.defineProperty(Logger.prototype, "logHandler", {
347
+ get: function () {
348
+ return this._logHandler;
349
+ },
350
+ set: function (handler) {
351
+ this.logHandler = handler;
352
+ },
353
+ enumerable: false,
354
+ configurable: true
355
+ });
356
+ Logger.prototype.log = function () {
357
+ var args = [];
358
+ for (var _i = 0; _i < arguments.length; _i++) {
359
+ args[_i] = arguments[_i];
360
+ }
361
+ this.logHandler.apply(this, __spreadArray([this, LogLevel.Verbose], args));
362
+ };
363
+ Logger.prototype.debug = function () {
364
+ var args = [];
365
+ for (var _i = 0; _i < arguments.length; _i++) {
366
+ args[_i] = arguments[_i];
367
+ }
368
+ this.logHandler.apply(this, __spreadArray([this, LogLevel.Debug], args));
369
+ };
370
+ Logger.prototype.info = function () {
371
+ var args = [];
372
+ for (var _i = 0; _i < arguments.length; _i++) {
373
+ args[_i] = arguments[_i];
374
+ }
375
+ this.logHandler.apply(this, __spreadArray([this, LogLevel.Info], args));
376
+ };
377
+ Logger.prototype.warn = function () {
378
+ var args = [];
379
+ for (var _i = 0; _i < arguments.length; _i++) {
380
+ args[_i] = arguments[_i];
381
+ }
382
+ this.logHandler.apply(this, __spreadArray([this, LogLevel.Warn], args));
383
+ };
384
+ Logger.prototype.error = function () {
385
+ var args = [];
386
+ for (var _i = 0; _i < arguments.length; _i++) {
387
+ args[_i] = arguments[_i];
388
+ }
389
+ this.logHandler.apply(this, __spreadArray([this, LogLevel.Error], args));
390
+ };
391
+ return Logger;
392
+ }());
393
+
394
+ export { DEFAULT_SDK_NAME, DEVICE_ID_KEY, LogLevel, Logger, Sdk, VERSION, addKit, configure, deleteKit, destroy, getDeviceId, getKit, getSdk, getSdks };
395
+ //# sourceMappingURL=index.esm5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm5.js","sources":["../src/constants.ts","../src/sdk.ts","../src/api.ts","../src/utils/logger.ts"],"sourcesContent":["/**\n * @license\n * constants.ts\n * core\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-03-21\n * Copyright © 2023 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { version } from '../package.json';\n\n/**\n * Default sdk name.\n *\n * @internal\n */\nexport const DEFAULT_SDK_NAME = '[DEFAULT]';\n\n/**\n * The current SDK version.\n *\n * @public\n */\nexport const VERSION = version;\n\n/**\n * Device ID storage key name\n *\n * @internal\n */\nexport const DEVICE_ID_KEY = 'device_id';\n","/**\n * @license\n * sdk.ts\n * core\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2021-09-23\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, MonterosaKit, Kits, SdkOptions } from './types';\n\n/**\n * @internal\n */\nexport class Sdk implements MonterosaSdk {\n private readonly _options: SdkOptions;\n private readonly _name: string;\n private _isDestroyed: boolean = false;\n private _kits: Kits;\n\n constructor(options: SdkOptions, name: string) {\n this._options = { ...options };\n this._name = name;\n this._kits = new Map();\n }\n\n get name(): string {\n this.checkDestroyed();\n return this._name;\n }\n\n get options(): SdkOptions {\n this.checkDestroyed();\n return this._options;\n }\n\n get isDestroyed(): boolean {\n return this._isDestroyed;\n }\n\n get kits(): Kits {\n return this._kits;\n }\n\n set isDestroyed(value: boolean) {\n this._isDestroyed = value;\n }\n\n public deleteKits() {\n this.kits.forEach((kit, name) => {\n this.kits.delete(name);\n kit.delete();\n });\n }\n\n private checkDestroyed(): void {\n if (this.isDestroyed) {\n throw new Error(`SDK named ${this.name} destroyed`);\n }\n }\n}\n\n/**\n * @internal\n */\nexport function addKit(sdk: MonterosaSdk, name: string, kit: MonterosaKit) {\n sdk.kits.set(name, kit);\n}\n\n/**\n * @internal\n */\nexport function getKit(\n sdk: MonterosaSdk,\n name: string,\n): MonterosaKit | undefined {\n return sdk.kits.get(name);\n}\n\n/**\n * @internal\n */\nexport function deleteKit(sdk: MonterosaSdk, name: string): void {\n sdk.kits.delete(name);\n}\n","/**\n * @license\n * api.ts\n * core\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { v4 as uuidv4 } from 'uuid';\nimport {\n getItem as getStorageItem,\n setItem as setStorageItem,\n checkAvailability as checkStorageAvailability,\n} from '@monterosa/sdk-util';\n\nimport { MonterosaSdk, SdkOptions } from './types';\nimport { DEFAULT_SDK_NAME, DEVICE_ID_KEY } from './constants';\nimport { Sdk } from './sdk';\n\nconst sdks = new Map<string, MonterosaSdk>();\n\nlet DEVICE_ID: string;\n\n/**\n * An array of all configured sdks.\n *\n * @public\n */\nexport function getSdks(): MonterosaSdk[] {\n return Array.from(sdks.values());\n}\n\n/**\n * Retrieves an SDK instance by its name.\n *\n * @example\n * ```javascript\n * const sdk = getSdk('my-sdk');\n * ```\n *\n * @param name - Optional name of the sdk to initialise.\n * If name is not provided, the default is \"[DEFAULT]\"\n *\n * @public\n */\nexport function getSdk(name: string = DEFAULT_SDK_NAME): MonterosaSdk {\n const sdk = sdks.get(name);\n\n if (!sdk) {\n throw new Error(\n `No Monterosa Sdk \"${name}\" has been configured.\n You need to call configure() first`,\n );\n }\n\n return sdk;\n}\n\n/**\n * @internal\n */\nexport function getDeviceId() {\n if (DEVICE_ID !== undefined) {\n return DEVICE_ID;\n }\n\n if (!checkStorageAvailability()) {\n DEVICE_ID = uuidv4();\n\n return DEVICE_ID;\n }\n\n const value = getStorageItem(DEVICE_ID_KEY);\n\n if (value === null) {\n DEVICE_ID = uuidv4();\n\n setStorageItem(DEVICE_ID_KEY, DEVICE_ID);\n } else {\n DEVICE_ID = value;\n }\n\n return DEVICE_ID;\n}\n\n/**\n * Creates an SDK instance.\n *\n * @example\n *\n * Configure default sdk with host and project id\n *\n * ```javascript\n * configure({\n * host: \"...\",\n * projectId: \"...\"\n * });\n * ```\n *\n * @param options - Studio host\n * @param name - Optional name of the sdk to initialise.\n * If name is not provided, the default is \"[DEFAULT]\"\n *\n * @returns Configured SDK instance.\n *\n * @public\n */\nexport function configure(\n options: SdkOptions,\n name: string = DEFAULT_SDK_NAME,\n): MonterosaSdk {\n const existingSdk = sdks.get(name);\n\n if (existingSdk) {\n return existingSdk;\n }\n\n const sdk = new Sdk(options, name);\n\n sdks.set(name, sdk);\n\n return sdk;\n}\n\n/**\n * Destroy initialised sdk\n *\n * @example\n * ```javascript\n * const sdk = configure(...);\n *\n * destroy(sdk);\n * ```\n *\n * @param sdk - sdk instance\n */\nexport function destroy(sdk: MonterosaSdk) {\n const { name } = sdk;\n\n sdks.delete(name);\n sdk.deleteKits();\n sdk.isDestroyed = true;\n}\n","/**\n * @license\n * logger.ts\n * core\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-05-31\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint-disable no-console */\n\n/**\n * Represents the possible log levels.\n */\nexport enum LogLevel {\n /**\n * Verbose level. Provides detailed and extensive logging.\n */\n Verbose,\n /**\n * Debug level. Used for debugging and development purposes.\n */\n Debug,\n /**\n * Info level. Used to provide general information about the system's state.\n */\n Info,\n /**\n * Warn level. Indicates potential issues or situations that might cause problems in the future.\n */\n Warn,\n /**\n * Error level. Indicates critical errors and issues that require immediate attention.\n */\n Error,\n /**\n * Silent level. No logs will be output.\n */\n Silent,\n}\n\n/** @internal */\nexport type LogHandler = (\n logger: Logger,\n logType: LogLevel,\n ...args: unknown[]\n) => void;\n\nconst Methods = {\n [LogLevel.Verbose]: 'log',\n // `console.debug` is not shown in Chrome and Edge by default. It must be\n // enabled manually. To avoid hassle for developers with settings debug\n // messages are sent to `console.log`\n [LogLevel.Debug]: 'log',\n [LogLevel.Info]: 'info',\n [LogLevel.Warn]: 'warn',\n [LogLevel.Error]: 'error',\n} as const;\n\nconst logHandler: LogHandler = (logger, logLevel, ...args) => {\n if (logger.logLevel > logLevel) {\n return;\n }\n\n const method = Methods[logLevel as keyof typeof Methods];\n\n console[method](\n new Date().toISOString().replace(/[TZ]/gi, ' ').trim(),\n `${LogLevel[logLevel]}/${logger.name}:`,\n ...args,\n );\n};\n\n/** @internal */\nexport class Logger {\n private _logLevel: LogLevel = LogLevel.Warn;\n private _logHandler: LogHandler = logHandler;\n\n constructor(public name: string) {}\n\n get logLevel(): LogLevel {\n return this._logLevel;\n }\n\n set logLevel(level: LogLevel) {\n this._logLevel = level;\n }\n\n get logHandler(): LogHandler {\n return this._logHandler;\n }\n\n set logHandler(handler: LogHandler) {\n this.logHandler = handler;\n }\n\n log(...args: unknown[]) {\n this.logHandler(this, LogLevel.Verbose, ...args);\n }\n\n debug(...args: unknown[]) {\n this.logHandler(this, LogLevel.Debug, ...args);\n }\n\n info(...args: unknown[]) {\n this.logHandler(this, LogLevel.Info, ...args);\n }\n\n warn(...args: unknown[]) {\n this.logHandler(this, LogLevel.Warn, ...args);\n }\n\n error(...args: unknown[]) {\n this.logHandler(this, LogLevel.Error, ...args);\n }\n}\n"],"names":["checkStorageAvailability","uuidv4","getStorageItem","setStorageItem"],"mappings":";;;;;AAAA;;;;;;;;;;AAaA;;;;;IAKa,gBAAgB,GAAG,YAAY;AAE5C;;;;;IAKa,OAAO,GAAG,QAAQ;AAE/B;;;;;IAKa,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AChC7B;;;;;;;;;;AAaA;;;;IASE,aAAY,OAAmB,EAAE,IAAY;QAHrC,iBAAY,GAAY,KAAK,CAAC;QAIpC,IAAI,CAAC,QAAQ,gBAAQ,OAAO,CAAE,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;KACxB;IAED,sBAAI,qBAAI;aAAR;YACE,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,KAAK,CAAC;SACnB;;;OAAA;IA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I,iBAAY,IAAI,EAAE,QAAQ,CAAC,KAAK,GAAK,OAAM;KAChD;IACH,aAAC;AAAD,CAAC;;;;"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @license
3
+ * api.ts
4
+ * core
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ import { MonterosaSdk, SdkOptions } from './types';
12
+ /**
13
+ * An array of all configured sdks.
14
+ *
15
+ * @public
16
+ */
17
+ export declare function getSdks(): MonterosaSdk[];
18
+ /**
19
+ * Retrieves an SDK instance by its name.
20
+ *
21
+ * @example
22
+ * ```javascript
23
+ * const sdk = getSdk('my-sdk');
24
+ * ```
25
+ *
26
+ * @param name - Optional name of the sdk to initialise.
27
+ * If name is not provided, the default is "[DEFAULT]"
28
+ *
29
+ * @public
30
+ */
31
+ export declare function getSdk(name?: string): MonterosaSdk;
32
+ /**
33
+ * @internal
34
+ */
35
+ export declare function getDeviceId(): string;
36
+ /**
37
+ * Creates an SDK instance.
38
+ *
39
+ * @example
40
+ *
41
+ * Configure default sdk with host and project id
42
+ *
43
+ * ```javascript
44
+ * configure({
45
+ * host: "...",
46
+ * projectId: "..."
47
+ * });
48
+ * ```
49
+ *
50
+ * @param options - Studio host
51
+ * @param name - Optional name of the sdk to initialise.
52
+ * If name is not provided, the default is "[DEFAULT]"
53
+ *
54
+ * @returns Configured SDK instance.
55
+ *
56
+ * @public
57
+ */
58
+ export declare function configure(options: SdkOptions, name?: string): MonterosaSdk;
59
+ /**
60
+ * Destroy initialised sdk
61
+ *
62
+ * @example
63
+ * ```javascript
64
+ * const sdk = configure(...);
65
+ *
66
+ * destroy(sdk);
67
+ * ```
68
+ *
69
+ * @param sdk - sdk instance
70
+ */
71
+ export declare function destroy(sdk: MonterosaSdk): void;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @license
3
+ * constants.ts
4
+ * core
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-03-21
7
+ * Copyright © 2023 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ /**
12
+ * Default sdk name.
13
+ *
14
+ * @internal
15
+ */
16
+ export declare const DEFAULT_SDK_NAME = "[DEFAULT]";
17
+ /**
18
+ * The current SDK version.
19
+ *
20
+ * @public
21
+ */
22
+ export declare const VERSION: string;
23
+ /**
24
+ * Device ID storage key name
25
+ *
26
+ * @internal
27
+ */
28
+ export declare const DEVICE_ID_KEY = "device_id";
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license
3
+ * index.ts
4
+ * core
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2021-09-23
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ /**
12
+ * Monterosa SDK / Core
13
+ *
14
+ * @packageDocumentation
15
+ */
16
+ export * from './constants';
17
+ export * from './api';
18
+ export * from './sdk';
19
+ export * from './types';
20
+ export * from './utils/logger';
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license
3
+ * sdk.ts
4
+ * core
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2021-09-23
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ import { MonterosaSdk, MonterosaKit, Kits, SdkOptions } from './types';
12
+ /**
13
+ * @internal
14
+ */
15
+ export declare class Sdk implements MonterosaSdk {
16
+ private readonly _options;
17
+ private readonly _name;
18
+ private _isDestroyed;
19
+ private _kits;
20
+ constructor(options: SdkOptions, name: string);
21
+ get name(): string;
22
+ get options(): SdkOptions;
23
+ get isDestroyed(): boolean;
24
+ get kits(): Kits;
25
+ set isDestroyed(value: boolean);
26
+ deleteKits(): void;
27
+ private checkDestroyed;
28
+ }
29
+ /**
30
+ * @internal
31
+ */
32
+ export declare function addKit(sdk: MonterosaSdk, name: string, kit: MonterosaKit): void;
33
+ /**
34
+ * @internal
35
+ */
36
+ export declare function getKit(sdk: MonterosaSdk, name: string): MonterosaKit | undefined;
37
+ /**
38
+ * @internal
39
+ */
40
+ export declare function deleteKit(sdk: MonterosaSdk, name: string): void;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @license
3
+ * types.ts
4
+ * core
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2021-09-23
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ /** @internal */
12
+ export declare type Kits = Map<string, MonterosaKit>;
13
+ /**
14
+ * Configuration object that used to initialise SDK and kits. Required values
15
+ * can be found in Monterosa / Interaction Cloud under
16
+ * {@link https://products.monterosa.co/mic/producer-guide/studio/project-settings | Project Settings tab}.
17
+ */
18
+ export interface SdkOptions {
19
+ /**
20
+ * Studio instance host
21
+ */
22
+ readonly host: string;
23
+ /**
24
+ * Unique identifier for the Studio project
25
+ */
26
+ readonly projectId: string;
27
+ }
28
+ /**
29
+ * Monterosa SDK holds the information about the initialised SDK
30
+ */
31
+ export interface MonterosaSdk {
32
+ /**
33
+ * SDK options
34
+ */
35
+ readonly options: SdkOptions;
36
+ /**
37
+ * SDK name
38
+ */
39
+ readonly name: string;
40
+ /**
41
+ * @internal
42
+ */
43
+ isDestroyed: boolean;
44
+ /**
45
+ * @internal
46
+ */
47
+ kits: Kits;
48
+ /**
49
+ * @internal
50
+ */
51
+ deleteKits(): void;
52
+ }
53
+ /** @internal */
54
+ export interface MonterosaKit {
55
+ delete(): void;
56
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @license
3
+ * logger.ts
4
+ * core
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-05-31
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ /**
12
+ * Represents the possible log levels.
13
+ */
14
+ export declare enum LogLevel {
15
+ /**
16
+ * Verbose level. Provides detailed and extensive logging.
17
+ */
18
+ Verbose = 0,
19
+ /**
20
+ * Debug level. Used for debugging and development purposes.
21
+ */
22
+ Debug = 1,
23
+ /**
24
+ * Info level. Used to provide general information about the system's state.
25
+ */
26
+ Info = 2,
27
+ /**
28
+ * Warn level. Indicates potential issues or situations that might cause problems in the future.
29
+ */
30
+ Warn = 3,
31
+ /**
32
+ * Error level. Indicates critical errors and issues that require immediate attention.
33
+ */
34
+ Error = 4,
35
+ /**
36
+ * Silent level. No logs will be output.
37
+ */
38
+ Silent = 5
39
+ }
40
+ /** @internal */
41
+ export declare type LogHandler = (logger: Logger, logType: LogLevel, ...args: unknown[]) => void;
42
+ /** @internal */
43
+ export declare class Logger {
44
+ name: string;
45
+ private _logLevel;
46
+ private _logHandler;
47
+ constructor(name: string);
48
+ get logLevel(): LogLevel;
49
+ set logLevel(level: LogLevel);
50
+ get logHandler(): LogHandler;
51
+ set logHandler(handler: LogHandler);
52
+ log(...args: unknown[]): void;
53
+ debug(...args: unknown[]): void;
54
+ info(...args: unknown[]): void;
55
+ warn(...args: unknown[]): void;
56
+ error(...args: unknown[]): void;
57
+ }