@snugdesk/core 0.2.12 → 0.2.15
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/fesm2022/snugdesk-core.mjs +264 -1
- package/fesm2022/snugdesk-core.mjs.map +1 -1
- package/index.d.ts +39 -2
- package/package.json +1 -1
|
@@ -2253,6 +2253,80 @@ class InteractionService {
|
|
|
2253
2253
|
const response = await this.appSyncService.query(statement, gqlAPIServiceArguments);
|
|
2254
2254
|
return response.data.listInteractionsByTenantId;
|
|
2255
2255
|
}
|
|
2256
|
+
async ListInteractionsByEntityId(entityId, createdAt, sortDirection, filter, limit, nextToken) {
|
|
2257
|
+
const statement = `query ListInteractionsByEntityId($entityId: ID!, $createdAt: ModelIntKeyConditionInput, $sortDirection: ModelSortDirection, $filter: ModelInteractionFilterInput, $limit: Int, $nextToken: String) {
|
|
2258
|
+
listInteractionsByEntityId(
|
|
2259
|
+
entityId: $entityId
|
|
2260
|
+
createdAt: $createdAt
|
|
2261
|
+
sortDirection: $sortDirection
|
|
2262
|
+
filter: $filter
|
|
2263
|
+
limit: $limit
|
|
2264
|
+
nextToken: $nextToken
|
|
2265
|
+
) {
|
|
2266
|
+
items {
|
|
2267
|
+
${FIELDS_INTERACTION}
|
|
2268
|
+
}
|
|
2269
|
+
nextToken
|
|
2270
|
+
}
|
|
2271
|
+
}`;
|
|
2272
|
+
const gqlAPIServiceArguments = {
|
|
2273
|
+
entityId,
|
|
2274
|
+
};
|
|
2275
|
+
if (createdAt) {
|
|
2276
|
+
gqlAPIServiceArguments.createdAt = createdAt;
|
|
2277
|
+
}
|
|
2278
|
+
if (sortDirection) {
|
|
2279
|
+
gqlAPIServiceArguments.sortDirection = sortDirection;
|
|
2280
|
+
}
|
|
2281
|
+
if (filter) {
|
|
2282
|
+
gqlAPIServiceArguments.filter = filter;
|
|
2283
|
+
}
|
|
2284
|
+
if (limit) {
|
|
2285
|
+
gqlAPIServiceArguments.limit = limit;
|
|
2286
|
+
}
|
|
2287
|
+
if (nextToken) {
|
|
2288
|
+
gqlAPIServiceArguments.nextToken = nextToken;
|
|
2289
|
+
}
|
|
2290
|
+
const response = await this.appSyncService.query(statement, gqlAPIServiceArguments);
|
|
2291
|
+
return response.data.listInteractionsByEntityId;
|
|
2292
|
+
}
|
|
2293
|
+
async ListInteractionsByEntityConversationId(entityConversationId, createdAt, sortDirection, filter, limit, nextToken) {
|
|
2294
|
+
const statement = `query ListInteractionsByEntityConversationId($entityConversationId: ID!, $createdAt: ModelIntKeyConditionInput, $sortDirection: ModelSortDirection, $filter: ModelInteractionFilterInput, $limit: Int, $nextToken: String) {
|
|
2295
|
+
listInteractionsByEntityConversationId(
|
|
2296
|
+
entityConversationId: $entityConversationId
|
|
2297
|
+
createdAt: $createdAt
|
|
2298
|
+
sortDirection: $sortDirection
|
|
2299
|
+
filter: $filter
|
|
2300
|
+
limit: $limit
|
|
2301
|
+
nextToken: $nextToken
|
|
2302
|
+
) {
|
|
2303
|
+
items {
|
|
2304
|
+
${FIELDS_INTERACTION}
|
|
2305
|
+
}
|
|
2306
|
+
nextToken
|
|
2307
|
+
}
|
|
2308
|
+
}`;
|
|
2309
|
+
const gqlAPIServiceArguments = {
|
|
2310
|
+
entityConversationId,
|
|
2311
|
+
};
|
|
2312
|
+
if (createdAt) {
|
|
2313
|
+
gqlAPIServiceArguments.createdAt = createdAt;
|
|
2314
|
+
}
|
|
2315
|
+
if (sortDirection) {
|
|
2316
|
+
gqlAPIServiceArguments.sortDirection = sortDirection;
|
|
2317
|
+
}
|
|
2318
|
+
if (filter) {
|
|
2319
|
+
gqlAPIServiceArguments.filter = filter;
|
|
2320
|
+
}
|
|
2321
|
+
if (limit) {
|
|
2322
|
+
gqlAPIServiceArguments.limit = limit;
|
|
2323
|
+
}
|
|
2324
|
+
if (nextToken) {
|
|
2325
|
+
gqlAPIServiceArguments.nextToken = nextToken;
|
|
2326
|
+
}
|
|
2327
|
+
const response = await this.appSyncService.query(statement, gqlAPIServiceArguments);
|
|
2328
|
+
return response.data.listInteractionsByEntityConversationId;
|
|
2329
|
+
}
|
|
2256
2330
|
async ListInteractionInviteesByUserId(userId, createdAt, sortDirection, filter, limit, nextToken) {
|
|
2257
2331
|
const statement = `query ListInteractionInviteesByUserId($userId: ID!, $createdAt: ModelIntKeyConditionInput, $sortDirection: ModelSortDirection, $filter: ModelInteractionInviteeFilterInput, $limit: Int, $nextToken: String) {
|
|
2258
2332
|
listInteractionInviteesByUserId(
|
|
@@ -3198,6 +3272,195 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
|
|
|
3198
3272
|
}]
|
|
3199
3273
|
}], ctorParameters: () => [{ type: AppSyncHelperService }] });
|
|
3200
3274
|
|
|
3275
|
+
var StorageType;
|
|
3276
|
+
(function (StorageType) {
|
|
3277
|
+
StorageType["SessionStorage"] = "sessionStorage";
|
|
3278
|
+
StorageType["LocalStorage"] = "localStorage";
|
|
3279
|
+
})(StorageType || (StorageType = {}));
|
|
3280
|
+
class EncryptedStorageService {
|
|
3281
|
+
authenticationService;
|
|
3282
|
+
DEFAULT_TTL_SECONDS = 60 * 60 * 12; // 12 hours
|
|
3283
|
+
constructor(authenticationService) {
|
|
3284
|
+
this.authenticationService = authenticationService;
|
|
3285
|
+
}
|
|
3286
|
+
buildKeys(baseKey) {
|
|
3287
|
+
const dataKey = this.scopedKey(baseKey);
|
|
3288
|
+
return {
|
|
3289
|
+
dataKey,
|
|
3290
|
+
cryptoKey: this.scopedKey(`${baseKey}_KEY`),
|
|
3291
|
+
cryptoKeyCreatedAt: this.scopedKey(`${baseKey}_KEY_CREATED_AT`),
|
|
3292
|
+
};
|
|
3293
|
+
}
|
|
3294
|
+
async getJsonByKey(storageType, baseKey, ttlSeconds) {
|
|
3295
|
+
return this.getJson(storageType, this.buildKeys(baseKey), ttlSeconds);
|
|
3296
|
+
}
|
|
3297
|
+
async setJsonByKey(storageType, baseKey, value, ttlSeconds) {
|
|
3298
|
+
await this.setJson(storageType, this.buildKeys(baseKey), value, ttlSeconds);
|
|
3299
|
+
}
|
|
3300
|
+
async updateJsonByKey(storageType, baseKey, value, ttlSeconds) {
|
|
3301
|
+
await this.updateJson(storageType, this.buildKeys(baseKey), ttlSeconds, () => value);
|
|
3302
|
+
}
|
|
3303
|
+
clearByKey(storageType, baseKey) {
|
|
3304
|
+
this.clear(storageType, this.buildKeys(baseKey));
|
|
3305
|
+
}
|
|
3306
|
+
async getJson(storageType, keys, ttlSeconds) {
|
|
3307
|
+
const storage = this.getStorage(storageType);
|
|
3308
|
+
if (!storage)
|
|
3309
|
+
return null;
|
|
3310
|
+
try {
|
|
3311
|
+
const encrypted = storage.getItem(keys.dataKey);
|
|
3312
|
+
if (!encrypted)
|
|
3313
|
+
return null;
|
|
3314
|
+
const decrypted = await this.decryptString(encrypted, keys, ttlSeconds, storage);
|
|
3315
|
+
if (!decrypted)
|
|
3316
|
+
return null;
|
|
3317
|
+
return JSON.parse(decrypted);
|
|
3318
|
+
}
|
|
3319
|
+
catch (err) {
|
|
3320
|
+
console.warn('Failed to read encrypted storage value:', err);
|
|
3321
|
+
return null;
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
async setJson(storageType, keys, value, ttlSeconds) {
|
|
3325
|
+
const storage = this.getStorage(storageType);
|
|
3326
|
+
if (!storage)
|
|
3327
|
+
return;
|
|
3328
|
+
try {
|
|
3329
|
+
const payload = JSON.stringify(value);
|
|
3330
|
+
const encrypted = await this.encryptString(payload, keys, ttlSeconds, storage);
|
|
3331
|
+
if (!encrypted)
|
|
3332
|
+
return;
|
|
3333
|
+
storage.setItem(keys.dataKey, encrypted);
|
|
3334
|
+
}
|
|
3335
|
+
catch (err) {
|
|
3336
|
+
console.warn('Failed to persist encrypted storage value:', err);
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3339
|
+
async updateJson(storageType, keys, ttlSeconds, updater) {
|
|
3340
|
+
const current = await this.getJson(storageType, keys, ttlSeconds);
|
|
3341
|
+
const next = await updater(current);
|
|
3342
|
+
if (!next)
|
|
3343
|
+
return;
|
|
3344
|
+
await this.setJson(storageType, keys, next, ttlSeconds);
|
|
3345
|
+
}
|
|
3346
|
+
clear(storageType, keys) {
|
|
3347
|
+
const storage = this.getStorage(storageType);
|
|
3348
|
+
if (!storage)
|
|
3349
|
+
return;
|
|
3350
|
+
try {
|
|
3351
|
+
storage.removeItem(keys.dataKey);
|
|
3352
|
+
}
|
|
3353
|
+
catch (err) {
|
|
3354
|
+
console.warn('Failed to clear encrypted storage value:', err);
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3357
|
+
getStorage(storageType) {
|
|
3358
|
+
if (typeof window === 'undefined')
|
|
3359
|
+
return null;
|
|
3360
|
+
return storageType === StorageType.LocalStorage ? window.localStorage : window.sessionStorage;
|
|
3361
|
+
}
|
|
3362
|
+
scopedKey(baseKey) {
|
|
3363
|
+
const tenantId = this.authenticationService.getTenantId();
|
|
3364
|
+
return tenantId ? `${baseKey}:${tenantId}` : baseKey;
|
|
3365
|
+
}
|
|
3366
|
+
nowSeconds() {
|
|
3367
|
+
return Math.floor(Date.now() / 1000);
|
|
3368
|
+
}
|
|
3369
|
+
resolveTtlSeconds(ttlSeconds) {
|
|
3370
|
+
return typeof ttlSeconds === 'number' && ttlSeconds > 0 ? ttlSeconds : this.DEFAULT_TTL_SECONDS;
|
|
3371
|
+
}
|
|
3372
|
+
async getOrCreateCryptoKey(keys, ttlSeconds, storage) {
|
|
3373
|
+
if (!window?.crypto?.subtle)
|
|
3374
|
+
return null;
|
|
3375
|
+
try {
|
|
3376
|
+
const createdAtRaw = storage.getItem(keys.cryptoKeyCreatedAt);
|
|
3377
|
+
const keyRaw = storage.getItem(keys.cryptoKey);
|
|
3378
|
+
const now = this.nowSeconds();
|
|
3379
|
+
const ttl = this.resolveTtlSeconds(ttlSeconds);
|
|
3380
|
+
if (createdAtRaw && keyRaw) {
|
|
3381
|
+
const createdAt = Number(createdAtRaw);
|
|
3382
|
+
const isExpired = !Number.isFinite(createdAt) || now - createdAt > ttl;
|
|
3383
|
+
if (!isExpired) {
|
|
3384
|
+
const jwk = JSON.parse(keyRaw);
|
|
3385
|
+
return await crypto.subtle.importKey('jwk', jwk, { name: 'AES-GCM' }, true, ['encrypt', 'decrypt']);
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
const key = await crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt']);
|
|
3389
|
+
const jwk = await crypto.subtle.exportKey('jwk', key);
|
|
3390
|
+
storage.setItem(keys.cryptoKey, JSON.stringify(jwk));
|
|
3391
|
+
storage.setItem(keys.cryptoKeyCreatedAt, String(now));
|
|
3392
|
+
return key;
|
|
3393
|
+
}
|
|
3394
|
+
catch (err) {
|
|
3395
|
+
console.warn('Failed to create crypto key:', err);
|
|
3396
|
+
return null;
|
|
3397
|
+
}
|
|
3398
|
+
}
|
|
3399
|
+
async encryptString(plainText, keys, ttlSeconds, storage) {
|
|
3400
|
+
const key = await this.getOrCreateCryptoKey(keys, ttlSeconds, storage);
|
|
3401
|
+
if (!key)
|
|
3402
|
+
return null;
|
|
3403
|
+
try {
|
|
3404
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
3405
|
+
const encoded = new TextEncoder().encode(plainText);
|
|
3406
|
+
const cipherBuffer = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, encoded);
|
|
3407
|
+
const payload = {
|
|
3408
|
+
iv: this.bytesToBase64(iv),
|
|
3409
|
+
data: this.bytesToBase64(new Uint8Array(cipherBuffer)),
|
|
3410
|
+
};
|
|
3411
|
+
return JSON.stringify(payload);
|
|
3412
|
+
}
|
|
3413
|
+
catch (err) {
|
|
3414
|
+
console.warn('Failed to encrypt cache payload:', err);
|
|
3415
|
+
return null;
|
|
3416
|
+
}
|
|
3417
|
+
}
|
|
3418
|
+
async decryptString(cipherText, keys, ttlSeconds, storage) {
|
|
3419
|
+
const key = await this.getOrCreateCryptoKey(keys, ttlSeconds, storage);
|
|
3420
|
+
if (!key)
|
|
3421
|
+
return null;
|
|
3422
|
+
try {
|
|
3423
|
+
const payload = JSON.parse(cipherText);
|
|
3424
|
+
const iv = this.base64ToBytes(payload?.iv);
|
|
3425
|
+
const data = this.base64ToBytes(payload?.data);
|
|
3426
|
+
if (!iv?.length || !data?.length)
|
|
3427
|
+
return null;
|
|
3428
|
+
// Re-wrap into fresh Uint8Arrays backed by ArrayBuffer (not SharedArrayBuffer).
|
|
3429
|
+
const ivBytes = new Uint8Array(iv);
|
|
3430
|
+
const dataBytes = new Uint8Array(data);
|
|
3431
|
+
const plainBuffer = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: ivBytes }, key, dataBytes);
|
|
3432
|
+
return new TextDecoder().decode(plainBuffer);
|
|
3433
|
+
}
|
|
3434
|
+
catch (err) {
|
|
3435
|
+
console.warn('Failed to decrypt cache payload:', err);
|
|
3436
|
+
return null;
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
bytesToBase64(bytes) {
|
|
3440
|
+
let binary = '';
|
|
3441
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
3442
|
+
binary += String.fromCharCode(bytes[i]);
|
|
3443
|
+
}
|
|
3444
|
+
return btoa(binary);
|
|
3445
|
+
}
|
|
3446
|
+
base64ToBytes(base64) {
|
|
3447
|
+
const binary = atob(base64 || '');
|
|
3448
|
+
const bytes = new Uint8Array(binary.length);
|
|
3449
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
3450
|
+
bytes[i] = binary.charCodeAt(i);
|
|
3451
|
+
}
|
|
3452
|
+
return bytes;
|
|
3453
|
+
}
|
|
3454
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: EncryptedStorageService, deps: [{ token: SnugdeskAuthenticationService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
3455
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: EncryptedStorageService, providedIn: 'root' });
|
|
3456
|
+
}
|
|
3457
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: EncryptedStorageService, decorators: [{
|
|
3458
|
+
type: Injectable,
|
|
3459
|
+
args: [{
|
|
3460
|
+
providedIn: 'root',
|
|
3461
|
+
}]
|
|
3462
|
+
}], ctorParameters: () => [{ type: SnugdeskAuthenticationService }] });
|
|
3463
|
+
|
|
3201
3464
|
class CleanDeep {
|
|
3202
3465
|
static clean(obj) {
|
|
3203
3466
|
Object.keys(obj).forEach((key) => {
|
|
@@ -3301,5 +3564,5 @@ class CustomValidators {
|
|
|
3301
3564
|
* Generated bundle index. Do not edit.
|
|
3302
3565
|
*/
|
|
3303
3566
|
|
|
3304
|
-
export { AMPLIFY_CONFIG, AppSyncHelperService, CleanDeep, CustomPipesModule, CustomValidators, DomainNamePipe, EntityConversationService, EntityService, ErrorComponent, FIELDS_ENTITY, FIELDS_ENTITY_CONVERSATION, FIELDS_ENTITY_CONVERSATION_EXPANDED, FIELDS_ENTITY_EXPANDED, FIELDS_ENTITY_MINIMAL, FIELDS_ENTITY_TYPE, FIELDS_INTERACTION, FIELDS_INTERACTION_ATTENDEE, FIELDS_INTERACTION_ATTENDEE_EXPANDED, FIELDS_INTERACTION_ENDPOINT, FIELDS_INTERACTION_EXPANDED, FIELDS_INTERACTION_HOST, FIELDS_INTERACTION_INVITEE, FIELDS_INTERACTION_MESSAGE, FIELDS_INTERACTION_MESSAGE_ATTACHMENT, FIELDS_INTERACTION_MESSAGE_EXPANDED, FIELDS_INTERACTION_WIDGET, FIELDS_INTERACTION_WIDGET_USER_SETTING, FIELDS_TEAM, FIELDS_TEAM_MEMBER, FIELDS_TENANT, FIELDS_TICKET, FIELDS_TICKET_PRIORITY, FIELDS_TICKET_STATUS, FIELDS_TICKET_TYPE, FIELDS_USER, FIELDS_USER_SESSION, FooterComponent, FormatEpochTimestampPipe, InteractionChannel, InteractionContext, InteractionDirection, InteractionEndpointService, InteractionProvider, InteractionRouteLogic, InteractionService, InteractionStatus, InteractionWidgetService, LoaderComponent, ModelAttributeTypes, ModelSortDirection, OpenSearchHelperService, S3HelperService, SafeHtmlPipe, SearchInnerFieldPipe, SearchPipe, SingularizePipe, SnugdeskAuthenticationService, SnugdeskCoreModule, SnugdeskIPRegistryService, TeamService, TenantSSOConfigurationProtocol, TenantService, TicketService, UserService, UserSessionService, UserStatus, UserType, provideAmplifyConfig };
|
|
3567
|
+
export { AMPLIFY_CONFIG, AppSyncHelperService, CleanDeep, CustomPipesModule, CustomValidators, DomainNamePipe, EncryptedStorageService, EntityConversationService, EntityService, ErrorComponent, FIELDS_ENTITY, FIELDS_ENTITY_CONVERSATION, FIELDS_ENTITY_CONVERSATION_EXPANDED, FIELDS_ENTITY_EXPANDED, FIELDS_ENTITY_MINIMAL, FIELDS_ENTITY_TYPE, FIELDS_INTERACTION, FIELDS_INTERACTION_ATTENDEE, FIELDS_INTERACTION_ATTENDEE_EXPANDED, FIELDS_INTERACTION_ENDPOINT, FIELDS_INTERACTION_EXPANDED, FIELDS_INTERACTION_HOST, FIELDS_INTERACTION_INVITEE, FIELDS_INTERACTION_MESSAGE, FIELDS_INTERACTION_MESSAGE_ATTACHMENT, FIELDS_INTERACTION_MESSAGE_EXPANDED, FIELDS_INTERACTION_WIDGET, FIELDS_INTERACTION_WIDGET_USER_SETTING, FIELDS_TEAM, FIELDS_TEAM_MEMBER, FIELDS_TENANT, FIELDS_TICKET, FIELDS_TICKET_PRIORITY, FIELDS_TICKET_STATUS, FIELDS_TICKET_TYPE, FIELDS_USER, FIELDS_USER_SESSION, FooterComponent, FormatEpochTimestampPipe, InteractionChannel, InteractionContext, InteractionDirection, InteractionEndpointService, InteractionProvider, InteractionRouteLogic, InteractionService, InteractionStatus, InteractionWidgetService, LoaderComponent, ModelAttributeTypes, ModelSortDirection, OpenSearchHelperService, S3HelperService, SafeHtmlPipe, SearchInnerFieldPipe, SearchPipe, SingularizePipe, SnugdeskAuthenticationService, SnugdeskCoreModule, SnugdeskIPRegistryService, StorageType, TeamService, TenantSSOConfigurationProtocol, TenantService, TicketService, UserService, UserSessionService, UserStatus, UserType, provideAmplifyConfig };
|
|
3305
3568
|
//# sourceMappingURL=snugdesk-core.mjs.map
|