@centia-io/sdk 0.0.43 → 0.0.44

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.
@@ -80,6 +80,12 @@ function getStorage() {
80
80
 
81
81
  //#endregion
82
82
  //#region src/util/utils.ts
83
+ /**
84
+ * @author Martin Høgh <mh@mapcentia.com>
85
+ * @copyright 2013-2026 MapCentia ApS
86
+ * @license https://opensource.org/license/mit The MIT License
87
+ *
88
+ */
83
89
  const generatePkceChallenge = async () => {
84
90
  const generateRandomString = () => {
85
91
  const array = new Uint32Array(28);
@@ -161,7 +167,8 @@ const setOptions = (options) => {
161
167
  getStorage().setItem("gc2_options", JSON.stringify({
162
168
  "clientId": options.clientId,
163
169
  "host": options.host,
164
- "redirectUri": options.redirectUri
170
+ "redirectUri": options.redirectUri,
171
+ "clientSecret": options.clientSecret || null
165
172
  }));
166
173
  };
167
174
  const getOptions = () => {
@@ -188,6 +195,12 @@ const clearNonce = () => {
188
195
 
189
196
  //#endregion
190
197
  //#region src/services/gc2.services.ts
198
+ /**
199
+ * @author Martin Høgh <mh@mapcentia.com>
200
+ * @copyright 2013-2026 MapCentia ApS
201
+ * @license https://opensource.org/license/mit The MIT License
202
+ *
203
+ */
191
204
  var Gc2Service = class {
192
205
  constructor(options) {
193
206
  this.options = options;
@@ -298,6 +311,7 @@ var Gc2Service = class {
298
311
  const path = `${this.host}/api/v4/oauth`;
299
312
  return this.request(this.buildUrl(path), "POST", {
300
313
  client_id: this.options.clientId,
314
+ client_secret: this.options.clientSecret,
301
315
  grant_type: "password",
302
316
  username,
303
317
  password,
@@ -323,6 +337,12 @@ var Gc2Service = class {
323
337
 
324
338
  //#endregion
325
339
  //#region src/CodeFlow.ts
340
+ /**
341
+ * @author Martin Høgh <mh@mapcentia.com>
342
+ * @copyright 2013-2026 MapCentia ApS
343
+ * @license https://opensource.org/license/mit The MIT License
344
+ *
345
+ */
326
346
  var CodeFlow = class {
327
347
  constructor(options) {
328
348
  this.options = options;
@@ -381,6 +401,12 @@ var CodeFlow = class {
381
401
 
382
402
  //#endregion
383
403
  //#region src/PasswordFlow.ts
404
+ /**
405
+ * @author Martin Høgh <mh@mapcentia.com>
406
+ * @copyright 2013-2026 MapCentia ApS
407
+ * @license https://opensource.org/license/mit The MIT License
408
+ *
409
+ */
384
410
  var PasswordFlow = class {
385
411
  constructor(options) {
386
412
  this.options = options;
@@ -395,7 +421,8 @@ var PasswordFlow = class {
395
421
  setOptions({
396
422
  clientId: this.options.clientId,
397
423
  host: this.options.host,
398
- redirectUri: ""
424
+ redirectUri: "",
425
+ clientSecret: this.options.clientSecret
399
426
  });
400
427
  }
401
428
  signOut() {
@@ -410,6 +437,12 @@ var PasswordFlow = class {
410
437
 
411
438
  //#endregion
412
439
  //#region src/util/request-headers.ts
440
+ /**
441
+ * @author Martin Høgh <mh@mapcentia.com>
442
+ * @copyright 2013-2026 MapCentia ApS
443
+ * @license https://opensource.org/license/mit The MIT License
444
+ *
445
+ */
413
446
  const getHeaders = async (contentType = "application/json") => {
414
447
  if (!await isLogin(new Gc2Service(getOptions()))) return Promise.reject("Is not logged in");
415
448
  const { accessToken } = getTokens();
@@ -425,6 +458,12 @@ var request_headers_default = getHeaders;
425
458
 
426
459
  //#endregion
427
460
  //#region src/util/make-request.ts
461
+ /**
462
+ * @author Martin Høgh <mh@mapcentia.com>
463
+ * @copyright 2013-2026 MapCentia ApS
464
+ * @license https://opensource.org/license/mit The MIT License
465
+ *
466
+ */
428
467
  const make = async (version, resource, method, payload, contentType = "application/json") => {
429
468
  const options = getOptions();
430
469
  let request = {
@@ -433,12 +472,19 @@ const make = async (version, resource, method, payload, contentType = "applicati
433
472
  redirect: "manual"
434
473
  };
435
474
  if (payload) request.body = contentType === "application/json" ? JSON.stringify(payload) : payload;
436
- return await fetch(options.host + `/api/v${version}/${resource}`, request);
475
+ if (version !== null) return await fetch(options.host + `/api/v${version}/${resource}`, request);
476
+ else return await fetch(options.host + `/api/${resource}`, request);
437
477
  };
438
478
  var make_request_default = make;
439
479
 
440
480
  //#endregion
441
481
  //#region src/util/get-response.ts
482
+ /**
483
+ * @author Martin Høgh <mh@mapcentia.com>
484
+ * @copyright 2013-2026 MapCentia ApS
485
+ * @license https://opensource.org/license/mit The MIT License
486
+ *
487
+ */
442
488
  const get = async (response, expectedCode) => {
443
489
  let res = null;
444
490
  let bodyText = "";
@@ -458,6 +504,12 @@ var get_response_default = get;
458
504
 
459
505
  //#endregion
460
506
  //#region src/Sql.ts
507
+ /**
508
+ * @author Martin Høgh <mh@mapcentia.com>
509
+ * @copyright 2013-2026 MapCentia ApS
510
+ * @license https://opensource.org/license/mit The MIT License
511
+ *
512
+ */
461
513
  var Sql = class {
462
514
  async exec(request) {
463
515
  return await get_response_default(await make_request_default("4", `sql`, "POST", request), 200);
@@ -466,14 +518,43 @@ var Sql = class {
466
518
 
467
519
  //#endregion
468
520
  //#region src/Rpc.ts
521
+ /**
522
+ * @author Martin Høgh <mh@mapcentia.com>
523
+ * @copyright 2013-2026 MapCentia ApS
524
+ * @license https://opensource.org/license/mit The MIT License
525
+ *
526
+ */
469
527
  var Rpc = class {
470
528
  async call(request) {
471
529
  return await get_response_default(await make_request_default("4", `call`, "POST", request), 200);
472
530
  }
473
531
  };
474
532
 
533
+ //#endregion
534
+ //#region src/Gql.ts
535
+ /**
536
+ * @author Martin Høgh <mh@mapcentia.com>
537
+ * @copyright 2013-2026 MapCentia ApS
538
+ * @license https://opensource.org/license/mit The MIT License
539
+ *
540
+ */
541
+ var Gql = class {
542
+ constructor(schema) {
543
+ this.schema = schema;
544
+ }
545
+ async request(request) {
546
+ return await get_response_default(await make_request_default(null, `graphql/schema/${this.schema}`, "POST", request), 200);
547
+ }
548
+ };
549
+
475
550
  //#endregion
476
551
  //#region src/Meta.ts
552
+ /**
553
+ * @author Martin Høgh <mh@mapcentia.com>
554
+ * @copyright 2013-2026 MapCentia ApS
555
+ * @license https://opensource.org/license/mit The MIT License
556
+ *
557
+ */
477
558
  var Meta = class {
478
559
  async query(rel) {
479
560
  return await get_response_default(await make_request_default("3", `meta/${rel}`, "GET", null), 200);
@@ -482,6 +563,12 @@ var Meta = class {
482
563
 
483
564
  //#endregion
484
565
  //#region src/Status.ts
566
+ /**
567
+ * @author Martin Høgh <mh@mapcentia.com>
568
+ * @copyright 2013-2026 MapCentia ApS
569
+ * @license https://opensource.org/license/mit The MIT License
570
+ *
571
+ */
485
572
  var Status = class {
486
573
  isAuth() {
487
574
  const tokens = getTokens();
@@ -494,6 +581,12 @@ var Status = class {
494
581
 
495
582
  //#endregion
496
583
  //#region src/Claims.ts
584
+ /**
585
+ * @author Martin Høgh <mh@mapcentia.com>
586
+ * @copyright 2013-2026 MapCentia ApS
587
+ * @license https://opensource.org/license/mit The MIT License
588
+ *
589
+ */
497
590
  var Claims = class {
498
591
  get() {
499
592
  const tokens = getTokens().accessToken;
@@ -503,6 +596,12 @@ var Claims = class {
503
596
 
504
597
  //#endregion
505
598
  //#region src/Users.ts
599
+ /**
600
+ * @author Martin Høgh <mh@mapcentia.com>
601
+ * @copyright 2013-2026 MapCentia ApS
602
+ * @license https://opensource.org/license/mit The MIT License
603
+ *
604
+ */
506
605
  var Users = class {
507
606
  async get(user) {
508
607
  return await get_response_default(await make_request_default("4", `users/${user}`, "GET", null), 200);
@@ -511,6 +610,12 @@ var Users = class {
511
610
 
512
611
  //#endregion
513
612
  //#region src/Ws.ts
613
+ /**
614
+ * @author Martin Høgh <mh@mapcentia.com>
615
+ * @copyright 2013-2026 MapCentia ApS
616
+ * @license https://opensource.org/license/mit The MIT License
617
+ *
618
+ */
514
619
  var Ws = class {
515
620
  constructor(options) {
516
621
  this.options = options;
@@ -547,6 +652,12 @@ var Ws = class {
547
652
 
548
653
  //#endregion
549
654
  //#region src/Stats.ts
655
+ /**
656
+ * @author Martin Høgh <mh@mapcentia.com>
657
+ * @copyright 2013-2026 MapCentia ApS
658
+ * @license https://opensource.org/license/mit The MIT License
659
+ *
660
+ */
550
661
  var Stats = class {
551
662
  async get() {
552
663
  return await get_response_default(await make_request_default("4", `stats`, "GET", null), 200);
@@ -555,6 +666,12 @@ var Stats = class {
555
666
 
556
667
  //#endregion
557
668
  //#region src/Tables.ts
669
+ /**
670
+ * @author Martin Høgh <mh@mapcentia.com>
671
+ * @copyright 2013-2026 MapCentia ApS
672
+ * @license https://opensource.org/license/mit The MIT License
673
+ *
674
+ */
558
675
  var Tables = class {
559
676
  async get(schema, table) {
560
677
  return await get_response_default(await make_request_default("4", `schemas/${encodeURIComponent(schema)}/tables/${encodeURIComponent(table)}`, "GET", null), 200);
@@ -572,6 +689,12 @@ var Tables = class {
572
689
 
573
690
  //#endregion
574
691
  //#region src/Api.ts
692
+ /**
693
+ * @author Martin Høgh <mh@mapcentia.com>
694
+ * @copyright 2013-2026 MapCentia ApS
695
+ * @license https://opensource.org/license/mit The MIT License
696
+ *
697
+ */
575
698
  function isPlainObject$1(v) {
576
699
  return typeof v === "object" && v !== null && !Array.isArray(v);
577
700
  }
@@ -633,6 +756,12 @@ function createApi() {
633
756
 
634
757
  //#endregion
635
758
  //#region src/SignUp.ts
759
+ /**
760
+ * @author Martin Høgh <mh@mapcentia.com>
761
+ * @copyright 2013-2026 MapCentia ApS
762
+ * @license https://opensource.org/license/mit The MIT License
763
+ *
764
+ */
636
765
  var SignUp = class {
637
766
  constructor(options) {
638
767
  this.options = options;
@@ -1217,35 +1346,36 @@ var TableQueryImpl = class {
1217
1346
  returning: []
1218
1347
  };
1219
1348
  return new class {
1220
- returning(cols) {
1221
- state.returning = cols || [];
1222
- return this;
1223
- }
1224
- toSql() {
1225
- const colsArr = [];
1226
- const vals = [];
1227
- const params = {};
1228
- const type_hints = {};
1229
- let p = 0;
1230
- for (const key in state.values) {
1231
- const value = state.values[key];
1232
- const col = findColumn(table, key);
1233
- p += 1;
1234
- const paramName = `${table.name}_${key}_${p}`;
1235
- colsArr.push(`"${key}"`);
1236
- vals.push(`:${paramName}`);
1237
- params[paramName] = value;
1238
- addTypeHintForParam(type_hints, paramName, col, value);
1239
- }
1240
- const parts = [];
1241
- parts.push(`insert into "${schema.name}"."${table.name}" (${colsArr.join(", ")}) values (${vals.join(", ")})`);
1242
- if (state.returning.length) parts.push("returning " + state.returning.join(", "));
1243
- const req = {
1244
- q: parts.join(" "),
1245
- params: Object.keys(params).length > 0 ? params : void 0,
1246
- type_hints: Object.keys(type_hints).length ? type_hints : void 0
1349
+ constructor() {
1350
+ this.returning = (cols) => {
1351
+ state.returning = cols || [];
1352
+ return this;
1353
+ };
1354
+ this.toSql = () => {
1355
+ const cols = [];
1356
+ const vals = [];
1357
+ const params = {};
1358
+ const type_hints = {};
1359
+ let p = 0;
1360
+ for (const key in state.values) {
1361
+ const value = state.values[key];
1362
+ const col = findColumn(table, key);
1363
+ p += 1;
1364
+ const paramName = `${table.name}_${key}_${p}`;
1365
+ cols.push(`"${key}"`);
1366
+ vals.push(`:${paramName}`);
1367
+ params[paramName] = value;
1368
+ addTypeHintForParam(type_hints, paramName, col, value);
1369
+ }
1370
+ const parts = [];
1371
+ parts.push(`insert into "${schema.name}"."${table.name}" (${cols.join(", ")}) values (${vals.join(", ")})`);
1372
+ if (state.returning.length) parts.push("returning " + state.returning.join(", "));
1373
+ return {
1374
+ q: parts.join(" "),
1375
+ params: Object.keys(params).length > 0 ? params : void 0,
1376
+ type_hints: Object.keys(type_hints).length ? type_hints : void 0
1377
+ };
1247
1378
  };
1248
- return state.returning.length ? req : req;
1249
1379
  }
1250
1380
  }();
1251
1381
  }
@@ -1289,56 +1419,55 @@ var TableQueryImpl = class {
1289
1419
  }
1290
1420
  return this;
1291
1421
  };
1292
- }
1293
- returning(cols) {
1294
- state.returning = cols || [];
1295
- return this;
1296
- }
1297
- toSql() {
1298
- const params = {};
1299
- const type_hints = {};
1300
- let p = 0;
1301
- const setParts = [];
1302
- for (const key in state.values) {
1303
- const value = state.values[key];
1304
- const col = findColumn(table, key);
1305
- p += 1;
1306
- const paramName = `${table.name}_${key}_${p}`;
1307
- setParts.push(`"${key}" = :${paramName}`);
1308
- params[paramName] = value;
1309
- addTypeHintForParam(type_hints, paramName, col, value);
1310
- }
1311
- const whereClauses = [];
1312
- for (const key in state.where) {
1313
- const value = state.where[key];
1314
- const col = findColumn(table, key);
1315
- p += 1;
1316
- const paramName = `${table.name}_${key}_${p}`;
1317
- if (value === null) {
1318
- if (!col.is_nullable) throw new Error(`Column ${table.name}.${key} is not nullable; cannot compare to null`);
1319
- whereClauses.push(`"${key}" is null`);
1320
- } else if (Array.isArray(value) && !isArrayShapedGeomScalarValue(col, value)) {
1321
- validateInArrayValues(col, key, value, "in");
1322
- whereClauses.push(`"${key}" = ANY(:${paramName})`);
1323
- params[paramName] = value;
1324
- addTypeHintForParam(type_hints, paramName, col, value);
1325
- } else {
1326
- validateScalarForColumn(col, value, `column ${key}`);
1327
- whereClauses.push(`"${key}" = :${paramName}`);
1422
+ this.returning = (cols) => {
1423
+ state.returning = cols || [];
1424
+ return this;
1425
+ };
1426
+ this.toSql = () => {
1427
+ const params = {};
1428
+ const type_hints = {};
1429
+ let p = 0;
1430
+ const setParts = [];
1431
+ for (const key in state.values) {
1432
+ const value = state.values[key];
1433
+ const col = findColumn(table, key);
1434
+ p += 1;
1435
+ const paramName = `${table.name}_${key}_${p}`;
1436
+ setParts.push(`"${key}" = :${paramName}`);
1328
1437
  params[paramName] = value;
1329
1438
  addTypeHintForParam(type_hints, paramName, col, value);
1330
1439
  }
1331
- }
1332
- const parts = [];
1333
- parts.push(`update "${schema.name}"."${table.name}" set ${setParts.join(", ")}`);
1334
- if (whereClauses.length) parts.push("where " + whereClauses.join(" and "));
1335
- if (state.returning.length) parts.push("returning " + state.returning.join(", "));
1336
- const req = {
1337
- q: parts.join(" "),
1338
- params: Object.keys(params).length > 0 ? params : void 0,
1339
- type_hints: Object.keys(type_hints).length ? type_hints : void 0
1440
+ const whereClauses = [];
1441
+ for (const key in state.where) {
1442
+ const value = state.where[key];
1443
+ const col = findColumn(table, key);
1444
+ p += 1;
1445
+ const paramName = `${table.name}_${key}_${p}`;
1446
+ if (value === null) {
1447
+ if (!col.is_nullable) throw new Error(`Column ${table.name}.${key} is not nullable; cannot compare to null`);
1448
+ whereClauses.push(`"${key}" is null`);
1449
+ } else if (Array.isArray(value) && !isArrayShapedGeomScalarValue(col, value)) {
1450
+ validateInArrayValues(col, key, value, "in");
1451
+ whereClauses.push(`"${key}" = ANY(:${paramName})`);
1452
+ params[paramName] = value;
1453
+ addTypeHintForParam(type_hints, paramName, col, value);
1454
+ } else {
1455
+ validateScalarForColumn(col, value, `column ${key}`);
1456
+ whereClauses.push(`"${key}" = :${paramName}`);
1457
+ params[paramName] = value;
1458
+ addTypeHintForParam(type_hints, paramName, col, value);
1459
+ }
1460
+ }
1461
+ const parts = [];
1462
+ parts.push(`update "${schema.name}"."${table.name}" set ${setParts.join(", ")}`);
1463
+ if (whereClauses.length) parts.push("where " + whereClauses.join(" and "));
1464
+ if (state.returning.length) parts.push("returning " + state.returning.join(", "));
1465
+ return {
1466
+ q: parts.join(" "),
1467
+ params: Object.keys(params).length > 0 ? params : void 0,
1468
+ type_hints: Object.keys(type_hints).length ? type_hints : void 0
1469
+ };
1340
1470
  };
1341
- return state.returning.length ? req : req;
1342
1471
  }
1343
1472
  }();
1344
1473
  }
@@ -1373,46 +1502,45 @@ var TableQueryImpl = class {
1373
1502
  }
1374
1503
  return this;
1375
1504
  };
1376
- }
1377
- returning(cols) {
1378
- state.returning = cols || [];
1379
- return this;
1380
- }
1381
- toSql() {
1382
- const params = {};
1383
- const type_hints = {};
1384
- let p = 0;
1385
- const whereClauses = [];
1386
- for (const key in state.where) {
1387
- const value = state.where[key];
1388
- const col = findColumn(table, key);
1389
- p += 1;
1390
- const paramName = `${table.name}_${key}_${p}`;
1391
- if (value === null) {
1392
- if (!col.is_nullable) throw new Error(`Column ${table.name}.${key} is not nullable; cannot compare to null`);
1393
- whereClauses.push(`"${key}" is null`);
1394
- } else if (Array.isArray(value)) {
1395
- validateInArrayValues(col, key, value, "in");
1396
- whereClauses.push(`"${key}" = ANY(:${paramName})`);
1397
- params[paramName] = value;
1398
- addTypeHintForParam(type_hints, paramName, col, value);
1399
- } else {
1400
- validateScalarForColumn(col, value, `column ${key}`);
1401
- whereClauses.push(`"${key}" = :${paramName}`);
1402
- params[paramName] = value;
1403
- addTypeHintForParam(type_hints, paramName, col, value);
1505
+ this.returning = (cols) => {
1506
+ state.returning = cols || [];
1507
+ return this;
1508
+ };
1509
+ this.toSql = () => {
1510
+ const params = {};
1511
+ const type_hints = {};
1512
+ let p = 0;
1513
+ const whereClauses = [];
1514
+ for (const key in state.where) {
1515
+ const value = state.where[key];
1516
+ const col = findColumn(table, key);
1517
+ p += 1;
1518
+ const paramName = `${table.name}_${key}_${p}`;
1519
+ if (value === null) {
1520
+ if (!col.is_nullable) throw new Error(`Column ${table.name}.${key} is not nullable; cannot compare to null`);
1521
+ whereClauses.push(`"${key}" is null`);
1522
+ } else if (Array.isArray(value)) {
1523
+ validateInArrayValues(col, key, value, "in");
1524
+ whereClauses.push(`"${key}" = ANY(:${paramName})`);
1525
+ params[paramName] = value;
1526
+ addTypeHintForParam(type_hints, paramName, col, value);
1527
+ } else {
1528
+ validateScalarForColumn(col, value, `column ${key}`);
1529
+ whereClauses.push(`"${key}" = :${paramName}`);
1530
+ params[paramName] = value;
1531
+ addTypeHintForParam(type_hints, paramName, col, value);
1532
+ }
1404
1533
  }
1405
- }
1406
- const parts = [];
1407
- parts.push(`delete from "${schema.name}"."${table.name}"`);
1408
- if (whereClauses.length) parts.push("where " + whereClauses.join(" and "));
1409
- if (state.returning.length) parts.push("returning " + state.returning.join(", "));
1410
- const req = {
1411
- q: parts.join(" "),
1412
- params: Object.keys(params).length > 0 ? params : void 0,
1413
- type_hints: Object.keys(type_hints).length ? type_hints : void 0
1534
+ const parts = [];
1535
+ parts.push(`delete from "${schema.name}"."${table.name}"`);
1536
+ if (whereClauses.length) parts.push("where " + whereClauses.join(" and "));
1537
+ if (state.returning.length) parts.push("returning " + state.returning.join(", "));
1538
+ return {
1539
+ q: parts.join(" "),
1540
+ params: Object.keys(params).length > 0 ? params : void 0,
1541
+ type_hints: Object.keys(type_hints).length ? type_hints : void 0
1542
+ };
1414
1543
  };
1415
- return state.returning.length ? req : req;
1416
1544
  }
1417
1545
  }();
1418
1546
  }
@@ -1421,9 +1549,19 @@ function createSqlBuilder(schema) {
1421
1549
  return { table: (name) => new TableQueryImpl(schema, String(name)) };
1422
1550
  }
1423
1551
 
1552
+ //#endregion
1553
+ //#region src/index.ts
1554
+ /**
1555
+ * @author Martin Høgh <mh@mapcentia.com>
1556
+ * @copyright 2013-2026 MapCentia ApS
1557
+ * @license https://opensource.org/license/mit The MIT License
1558
+ *
1559
+ */
1560
+
1424
1561
  //#endregion
1425
1562
  exports.Claims = Claims;
1426
1563
  exports.CodeFlow = CodeFlow;
1564
+ exports.Gql = Gql;
1427
1565
  exports.Meta = Meta;
1428
1566
  exports.PasswordFlow = PasswordFlow;
1429
1567
  exports.Rpc = Rpc;