@yomotech/view-toolkit 0.0.7 → 0.0.9

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.
@@ -53,8 +53,6 @@ import { NzTooltipModule } from 'ng-zorro-antd/tooltip';
53
53
  import { App } from '@capacitor/app';
54
54
  import { Browser } from '@capacitor/browser';
55
55
  import { OAuth2Client } from '@byteowls/capacitor-oauth2';
56
- import PouchDB from 'pouchdb';
57
- import JSZip from 'jszip';
58
56
 
59
57
  class PaginationComponent {
60
58
  platform;
@@ -2414,8 +2412,6 @@ class Couchdb {
2414
2412
  async getFileContentFromCouchDb(couchDbName, filePath) {
2415
2413
  try {
2416
2414
  const dbName = couchDbName;
2417
- console.log('dbName: ', dbName);
2418
- console.log('filePath: ', filePath);
2419
2415
  const docId = filePath?.trim();
2420
2416
  if (!docId) {
2421
2417
  console.error('Missing file path');
@@ -2506,12 +2502,25 @@ class Couchdb {
2506
2502
  }
2507
2503
  async buildTenantHeaders() {
2508
2504
  const tenantKey = await this.utilityService.getStorage('tenantKey');
2509
- if (typeof tenantKey !== 'string' || !tenantKey.trim()) {
2510
- throw new Error('Missing tenantKey');
2505
+ const tenantName = await this.utilityService.getStorage('tenantName');
2506
+ if (tenantKey) {
2507
+ console.log('tenantKey: ', tenantKey);
2508
+ if (typeof tenantKey !== 'string' || !tenantKey.trim()) {
2509
+ throw new Error('Missing tenantKey');
2510
+ }
2511
+ return {
2512
+ 'X-Tenant-Key': tenantKey.trim(),
2513
+ };
2514
+ }
2515
+ else {
2516
+ console.log('tenantName: ', tenantName);
2517
+ if (typeof tenantName !== 'string' || !tenantName.trim()) {
2518
+ throw new Error('Missing tenantName');
2519
+ }
2520
+ return {
2521
+ 'X-Tenant': tenantName.trim(),
2522
+ };
2511
2523
  }
2512
- return {
2513
- 'X-Tenant-Key': tenantKey.trim(),
2514
- };
2515
2524
  }
2516
2525
  async getImageSrcFromCouchDb(couchDbName, filePath) {
2517
2526
  const dbName = couchDbName;
@@ -3344,183 +3353,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImpor
3344
3353
  }]
3345
3354
  }], ctorParameters: () => [{ type: i1.Platform }] });
3346
3355
 
3347
- class PouchdbService {
3348
- db = new PouchDB("");
3349
- async uploadAndStoreZip(zipFile, couchDbURl) {
3350
- const zip = await JSZip.loadAsync(zipFile);
3351
- const fileName = zipFile?.name?.replace('.zip', '');
3352
- const envFilePath = `${fileName}/environments/environment.json`;
3353
- const envFile = zip.file(envFilePath);
3354
- if (envFile && !couchDbURl) {
3355
- const envFileContent = await envFile.async('string');
3356
- try {
3357
- const jsonData = JSON.parse(envFileContent);
3358
- if (jsonData?.environment?.couchdbUrl) {
3359
- this.db = new PouchDB(jsonData.environment.couchdbUrl);
3360
- }
3361
- }
3362
- catch (e) {
3363
- console.error('Invalid JSON in environment.json:', e);
3364
- }
3365
- }
3366
- else {
3367
- this.db = new PouchDB(couchDbURl);
3368
- }
3369
- // Proceed to upload all files
3370
- const savePromises = [];
3371
- zip.forEach((relativePath, file) => {
3372
- if (!file.dir) {
3373
- savePromises.push(file.async('base64').then((content) => {
3374
- const docId = relativePath.toString();
3375
- console.log('docId: ', docId);
3376
- return this.db.put({
3377
- _id: docId,
3378
- data: content,
3379
- type: 'file',
3380
- contentType: this.getMimeType(file.name)
3381
- }).catch((err) => {
3382
- if (err.status === 409) {
3383
- return this.db.get(docId).then((existing) => {
3384
- return this.db.put({
3385
- ...existing,
3386
- data: content,
3387
- contentType: this.getMimeType(file.name)
3388
- });
3389
- });
3390
- }
3391
- throw err;
3392
- });
3393
- }));
3394
- }
3395
- });
3396
- await Promise.all(savePromises);
3397
- }
3398
- async getFile(path, remoteDB) {
3399
- try {
3400
- if (remoteDB) {
3401
- this.db = new PouchDB(remoteDB);
3402
- }
3403
- const doc = await this.db.get(path);
3404
- return this.decodeBlob(doc);
3405
- }
3406
- catch (err) {
3407
- if (err.status === 404 && remoteDB) {
3408
- try {
3409
- const remoteDoc = await this.db.get(path);
3410
- return this.decodeBlob(remoteDoc);
3411
- }
3412
- catch (remoteErr) {
3413
- throw remoteErr;
3414
- }
3415
- }
3416
- else {
3417
- throw err;
3418
- }
3419
- }
3420
- }
3421
- decodeBlob(doc) {
3422
- const byteCharacters = atob(doc.data);
3423
- const byteNumbers = new Array(byteCharacters.length).fill(0).map((_, i) => byteCharacters.charCodeAt(i));
3424
- const byteArray = new Uint8Array(byteNumbers);
3425
- return new Blob([byteArray], { type: doc.contentType });
3426
- }
3427
- async getTextFile(path, remotedbUrl) {
3428
- const blob = await this.getFile(path, remotedbUrl);
3429
- if (blob?.type && blob?.type === 'application/x-x509-ca-cert') {
3430
- const base64Der = await this.blobToBase64(blob);
3431
- return base64Der;
3432
- }
3433
- if (blob?.type && blob?.type.startsWith('image/')) {
3434
- return URL.createObjectURL(blob);
3435
- }
3436
- else if (blob?.type && blob?.type === 'application/json') {
3437
- const text = await blob.text();
3438
- return JSON.parse(text);
3439
- }
3440
- else {
3441
- return await blob.text();
3442
- }
3443
- }
3444
- blobToBase64(blob) {
3445
- return new Promise((resolve, reject) => {
3446
- const reader = new FileReader();
3447
- reader.onloadend = () => {
3448
- const base64 = reader.result.split(',')[1];
3449
- resolve(base64);
3450
- };
3451
- reader.onerror = reject;
3452
- reader.readAsDataURL(blob);
3453
- });
3454
- }
3455
- getMimeType(fileName) {
3456
- const extension = fileName.split('.').pop()?.toLowerCase();
3457
- const mimeMap = {
3458
- 'json': 'application/json',
3459
- 'css': 'text/css',
3460
- 'scss': 'text/x-scss',
3461
- 'jpg': 'image/jpeg',
3462
- 'jpeg': 'image/jpeg',
3463
- 'png': 'image/png',
3464
- 'ico': 'image/x-icon',
3465
- 'svg': 'image/svg+xml',
3466
- 'html': 'text/html',
3467
- 'js': 'application/javascript',
3468
- 'ts': 'application/typescript',
3469
- 'txt': 'text/plain',
3470
- 'der': 'application/x-x509-ca-cert'
3471
- };
3472
- return mimeMap[extension || ''] || 'application/octet-stream';
3473
- }
3474
- async getAllDatabasesWithContent(couchdbBaseUrl) {
3475
- const connStr = couchdbBaseUrl;
3476
- const urlObj = new URL(connStr);
3477
- const credentials = `${urlObj.username}:${urlObj.password}`;
3478
- const originalPortMatch = connStr.match(/:(\d+)(?=\/|$)/);
3479
- const port = originalPortMatch ? originalPortMatch[1] : "";
3480
- const baseUrl = `${urlObj.protocol}//${urlObj.hostname}${port ? `:${port}` : ""}`;
3481
- const authHeader = {
3482
- 'Authorization': 'Basic ' + btoa(`${credentials}`)
3483
- };
3484
- const response = await fetch(`${baseUrl}/_all_dbs`, {
3485
- headers: authHeader
3486
- });
3487
- if (!response.ok) {
3488
- throw new Error(`Error fetching databases: ${response.statusText}`);
3489
- }
3490
- const dbNames = await response.json();
3491
- const results = [];
3492
- for (const dbName of dbNames) {
3493
- try {
3494
- const docsResponse = await fetch(`${baseUrl}/${dbName}/_all_docs?limit=1`, {
3495
- headers: authHeader
3496
- });
3497
- if (!docsResponse.ok) {
3498
- results.push({ databaseName: dbName, content: false });
3499
- continue;
3500
- }
3501
- const docsData = await docsResponse.json();
3502
- results.push({
3503
- databaseName: dbName,
3504
- content: docsData.total_rows > 0
3505
- });
3506
- }
3507
- catch (err) {
3508
- console.log('err: ', err);
3509
- results.push({ databaseName: dbName, content: false });
3510
- }
3511
- }
3512
- return results;
3513
- }
3514
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: PouchdbService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
3515
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: PouchdbService, providedIn: 'root' });
3516
- }
3517
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: PouchdbService, decorators: [{
3518
- type: Injectable,
3519
- args: [{
3520
- providedIn: 'root'
3521
- }]
3522
- }] });
3523
-
3524
3356
  /*
3525
3357
  * Public API Surface of view-toolkit
3526
3358
  */
@@ -3529,5 +3361,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImpor
3529
3361
  * Generated bundle index. Do not edit.
3530
3362
  */
3531
3363
 
3532
- export { AppVersionResetService, CardComponent, ConfigService, Couchdb, FormComponent, GridComponent, HeaderMenuComponent, LogsComponent, MobileKeycloakService, ModelComponent, NetworkLogService, NotificationService, PaginationComponent, PouchdbService, RequestService, SideMenuComponent, UtilityService, ViewToolkitModule };
3364
+ export { AppVersionResetService, CardComponent, ConfigService, Couchdb, FormComponent, GridComponent, HeaderMenuComponent, LogsComponent, MobileKeycloakService, ModelComponent, NetworkLogService, NotificationService, PaginationComponent, RequestService, SideMenuComponent, UtilityService, ViewToolkitModule };
3533
3365
  //# sourceMappingURL=yomotech-view-toolkit.mjs.map