@centia-io/sdk 0.0.40 → 0.0.41

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;
@@ -323,6 +336,12 @@ var Gc2Service = class {
323
336
 
324
337
  //#endregion
325
338
  //#region src/CodeFlow.ts
339
+ /**
340
+ * @author Martin Høgh <mh@mapcentia.com>
341
+ * @copyright 2013-2026 MapCentia ApS
342
+ * @license https://opensource.org/license/mit The MIT License
343
+ *
344
+ */
326
345
  var CodeFlow = class {
327
346
  constructor(options) {
328
347
  this.options = options;
@@ -381,6 +400,12 @@ var CodeFlow = class {
381
400
 
382
401
  //#endregion
383
402
  //#region src/PasswordFlow.ts
403
+ /**
404
+ * @author Martin Høgh <mh@mapcentia.com>
405
+ * @copyright 2013-2026 MapCentia ApS
406
+ * @license https://opensource.org/license/mit The MIT License
407
+ *
408
+ */
384
409
  var PasswordFlow = class {
385
410
  constructor(options) {
386
411
  this.options = options;
@@ -395,7 +420,8 @@ var PasswordFlow = class {
395
420
  setOptions({
396
421
  clientId: this.options.clientId,
397
422
  host: this.options.host,
398
- redirectUri: ""
423
+ redirectUri: "",
424
+ clientSecret: this.options.clientSecret
399
425
  });
400
426
  }
401
427
  signOut() {
@@ -410,6 +436,12 @@ var PasswordFlow = class {
410
436
 
411
437
  //#endregion
412
438
  //#region src/util/request-headers.ts
439
+ /**
440
+ * @author Martin Høgh <mh@mapcentia.com>
441
+ * @copyright 2013-2026 MapCentia ApS
442
+ * @license https://opensource.org/license/mit The MIT License
443
+ *
444
+ */
413
445
  const getHeaders = async (contentType = "application/json") => {
414
446
  if (!await isLogin(new Gc2Service(getOptions()))) return Promise.reject("Is not logged in");
415
447
  const { accessToken } = getTokens();
@@ -425,6 +457,12 @@ var request_headers_default = getHeaders;
425
457
 
426
458
  //#endregion
427
459
  //#region src/util/make-request.ts
460
+ /**
461
+ * @author Martin Høgh <mh@mapcentia.com>
462
+ * @copyright 2013-2026 MapCentia ApS
463
+ * @license https://opensource.org/license/mit The MIT License
464
+ *
465
+ */
428
466
  const make = async (version, resource, method, payload, contentType = "application/json") => {
429
467
  const options = getOptions();
430
468
  let request = {
@@ -433,12 +471,19 @@ const make = async (version, resource, method, payload, contentType = "applicati
433
471
  redirect: "manual"
434
472
  };
435
473
  if (payload) request.body = contentType === "application/json" ? JSON.stringify(payload) : payload;
436
- return await fetch(options.host + `/api/v${version}/${resource}`, request);
474
+ if (version !== null) return await fetch(options.host + `/api/v${version}/${resource}`, request);
475
+ else return await fetch(options.host + `/api/${resource}`, request);
437
476
  };
438
477
  var make_request_default = make;
439
478
 
440
479
  //#endregion
441
480
  //#region src/util/get-response.ts
481
+ /**
482
+ * @author Martin Høgh <mh@mapcentia.com>
483
+ * @copyright 2013-2026 MapCentia ApS
484
+ * @license https://opensource.org/license/mit The MIT License
485
+ *
486
+ */
442
487
  const get = async (response, expectedCode) => {
443
488
  let res = null;
444
489
  let bodyText = "";
@@ -458,6 +503,12 @@ var get_response_default = get;
458
503
 
459
504
  //#endregion
460
505
  //#region src/Sql.ts
506
+ /**
507
+ * @author Martin Høgh <mh@mapcentia.com>
508
+ * @copyright 2013-2026 MapCentia ApS
509
+ * @license https://opensource.org/license/mit The MIT License
510
+ *
511
+ */
461
512
  var Sql = class {
462
513
  async exec(request) {
463
514
  return await get_response_default(await make_request_default("4", `sql`, "POST", request), 200);
@@ -466,14 +517,40 @@ var Sql = class {
466
517
 
467
518
  //#endregion
468
519
  //#region src/Rpc.ts
520
+ /**
521
+ * @author Martin Høgh <mh@mapcentia.com>
522
+ * @copyright 2013-2026 MapCentia ApS
523
+ * @license https://opensource.org/license/mit The MIT License
524
+ *
525
+ */
469
526
  var Rpc = class {
470
527
  async call(request) {
471
528
  return await get_response_default(await make_request_default("4", `call`, "POST", request), 200);
472
529
  }
473
530
  };
474
531
 
532
+ //#endregion
533
+ //#region src/GraphQL.ts
534
+ /**
535
+ * @author Martin Høgh <mh@mapcentia.com>
536
+ * @copyright 2013-2026 MapCentia ApS
537
+ * @license https://opensource.org/license/mit The MIT License
538
+ *
539
+ */
540
+ var GraphQL = class {
541
+ async request(request) {
542
+ return await get_response_default(await make_request_default(null, `graphql/schema/public`, "POST", request), 200);
543
+ }
544
+ };
545
+
475
546
  //#endregion
476
547
  //#region src/Meta.ts
548
+ /**
549
+ * @author Martin Høgh <mh@mapcentia.com>
550
+ * @copyright 2013-2026 MapCentia ApS
551
+ * @license https://opensource.org/license/mit The MIT License
552
+ *
553
+ */
477
554
  var Meta = class {
478
555
  async query(rel) {
479
556
  return await get_response_default(await make_request_default("3", `meta/${rel}`, "GET", null), 200);
@@ -482,6 +559,12 @@ var Meta = class {
482
559
 
483
560
  //#endregion
484
561
  //#region src/Status.ts
562
+ /**
563
+ * @author Martin Høgh <mh@mapcentia.com>
564
+ * @copyright 2013-2026 MapCentia ApS
565
+ * @license https://opensource.org/license/mit The MIT License
566
+ *
567
+ */
485
568
  var Status = class {
486
569
  isAuth() {
487
570
  const tokens = getTokens();
@@ -494,6 +577,12 @@ var Status = class {
494
577
 
495
578
  //#endregion
496
579
  //#region src/Claims.ts
580
+ /**
581
+ * @author Martin Høgh <mh@mapcentia.com>
582
+ * @copyright 2013-2026 MapCentia ApS
583
+ * @license https://opensource.org/license/mit The MIT License
584
+ *
585
+ */
497
586
  var Claims = class {
498
587
  get() {
499
588
  const tokens = getTokens().accessToken;
@@ -503,6 +592,12 @@ var Claims = class {
503
592
 
504
593
  //#endregion
505
594
  //#region src/Users.ts
595
+ /**
596
+ * @author Martin Høgh <mh@mapcentia.com>
597
+ * @copyright 2013-2026 MapCentia ApS
598
+ * @license https://opensource.org/license/mit The MIT License
599
+ *
600
+ */
506
601
  var Users = class {
507
602
  async get(user) {
508
603
  return await get_response_default(await make_request_default("4", `users/${user}`, "GET", null), 200);
@@ -511,6 +606,12 @@ var Users = class {
511
606
 
512
607
  //#endregion
513
608
  //#region src/Ws.ts
609
+ /**
610
+ * @author Martin Høgh <mh@mapcentia.com>
611
+ * @copyright 2013-2026 MapCentia ApS
612
+ * @license https://opensource.org/license/mit The MIT License
613
+ *
614
+ */
514
615
  var Ws = class {
515
616
  constructor(options) {
516
617
  this.options = options;
@@ -547,6 +648,12 @@ var Ws = class {
547
648
 
548
649
  //#endregion
549
650
  //#region src/Stats.ts
651
+ /**
652
+ * @author Martin Høgh <mh@mapcentia.com>
653
+ * @copyright 2013-2026 MapCentia ApS
654
+ * @license https://opensource.org/license/mit The MIT License
655
+ *
656
+ */
550
657
  var Stats = class {
551
658
  async get() {
552
659
  return await get_response_default(await make_request_default("4", `stats`, "GET", null), 200);
@@ -555,6 +662,12 @@ var Stats = class {
555
662
 
556
663
  //#endregion
557
664
  //#region src/Tables.ts
665
+ /**
666
+ * @author Martin Høgh <mh@mapcentia.com>
667
+ * @copyright 2013-2026 MapCentia ApS
668
+ * @license https://opensource.org/license/mit The MIT License
669
+ *
670
+ */
558
671
  var Tables = class {
559
672
  async get(schema, table) {
560
673
  return await get_response_default(await make_request_default("4", `schemas/${encodeURIComponent(schema)}/tables/${encodeURIComponent(table)}`, "GET", null), 200);
@@ -572,6 +685,12 @@ var Tables = class {
572
685
 
573
686
  //#endregion
574
687
  //#region src/Api.ts
688
+ /**
689
+ * @author Martin Høgh <mh@mapcentia.com>
690
+ * @copyright 2013-2026 MapCentia ApS
691
+ * @license https://opensource.org/license/mit The MIT License
692
+ *
693
+ */
575
694
  function isPlainObject$1(v) {
576
695
  return typeof v === "object" && v !== null && !Array.isArray(v);
577
696
  }
@@ -633,6 +752,12 @@ function createApi() {
633
752
 
634
753
  //#endregion
635
754
  //#region src/SignUp.ts
755
+ /**
756
+ * @author Martin Høgh <mh@mapcentia.com>
757
+ * @copyright 2013-2026 MapCentia ApS
758
+ * @license https://opensource.org/license/mit The MIT License
759
+ *
760
+ */
636
761
  var SignUp = class {
637
762
  constructor(options) {
638
763
  this.options = options;
@@ -1217,35 +1342,36 @@ var TableQueryImpl = class {
1217
1342
  returning: []
1218
1343
  };
1219
1344
  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
1345
+ constructor() {
1346
+ this.returning = (cols) => {
1347
+ state.returning = cols || [];
1348
+ return this;
1349
+ };
1350
+ this.toSql = () => {
1351
+ const cols = [];
1352
+ const vals = [];
1353
+ const params = {};
1354
+ const type_hints = {};
1355
+ let p = 0;
1356
+ for (const key in state.values) {
1357
+ const value = state.values[key];
1358
+ const col = findColumn(table, key);
1359
+ p += 1;
1360
+ const paramName = `${table.name}_${key}_${p}`;
1361
+ cols.push(`"${key}"`);
1362
+ vals.push(`:${paramName}`);
1363
+ params[paramName] = value;
1364
+ addTypeHintForParam(type_hints, paramName, col, value);
1365
+ }
1366
+ const parts = [];
1367
+ parts.push(`insert into "${schema.name}"."${table.name}" (${cols.join(", ")}) values (${vals.join(", ")})`);
1368
+ if (state.returning.length) parts.push("returning " + state.returning.join(", "));
1369
+ return {
1370
+ q: parts.join(" "),
1371
+ params: Object.keys(params).length > 0 ? params : void 0,
1372
+ type_hints: Object.keys(type_hints).length ? type_hints : void 0
1373
+ };
1247
1374
  };
1248
- return state.returning.length ? req : req;
1249
1375
  }
1250
1376
  }();
1251
1377
  }
@@ -1289,56 +1415,55 @@ var TableQueryImpl = class {
1289
1415
  }
1290
1416
  return this;
1291
1417
  };
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}`);
1418
+ this.returning = (cols) => {
1419
+ state.returning = cols || [];
1420
+ return this;
1421
+ };
1422
+ this.toSql = () => {
1423
+ const params = {};
1424
+ const type_hints = {};
1425
+ let p = 0;
1426
+ const setParts = [];
1427
+ for (const key in state.values) {
1428
+ const value = state.values[key];
1429
+ const col = findColumn(table, key);
1430
+ p += 1;
1431
+ const paramName = `${table.name}_${key}_${p}`;
1432
+ setParts.push(`"${key}" = :${paramName}`);
1328
1433
  params[paramName] = value;
1329
1434
  addTypeHintForParam(type_hints, paramName, col, value);
1330
1435
  }
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
1436
+ const whereClauses = [];
1437
+ for (const key in state.where) {
1438
+ const value = state.where[key];
1439
+ const col = findColumn(table, key);
1440
+ p += 1;
1441
+ const paramName = `${table.name}_${key}_${p}`;
1442
+ if (value === null) {
1443
+ if (!col.is_nullable) throw new Error(`Column ${table.name}.${key} is not nullable; cannot compare to null`);
1444
+ whereClauses.push(`"${key}" is null`);
1445
+ } else if (Array.isArray(value) && !isArrayShapedGeomScalarValue(col, value)) {
1446
+ validateInArrayValues(col, key, value, "in");
1447
+ whereClauses.push(`"${key}" = ANY(:${paramName})`);
1448
+ params[paramName] = value;
1449
+ addTypeHintForParam(type_hints, paramName, col, value);
1450
+ } else {
1451
+ validateScalarForColumn(col, value, `column ${key}`);
1452
+ whereClauses.push(`"${key}" = :${paramName}`);
1453
+ params[paramName] = value;
1454
+ addTypeHintForParam(type_hints, paramName, col, value);
1455
+ }
1456
+ }
1457
+ const parts = [];
1458
+ parts.push(`update "${schema.name}"."${table.name}" set ${setParts.join(", ")}`);
1459
+ if (whereClauses.length) parts.push("where " + whereClauses.join(" and "));
1460
+ if (state.returning.length) parts.push("returning " + state.returning.join(", "));
1461
+ return {
1462
+ q: parts.join(" "),
1463
+ params: Object.keys(params).length > 0 ? params : void 0,
1464
+ type_hints: Object.keys(type_hints).length ? type_hints : void 0
1465
+ };
1340
1466
  };
1341
- return state.returning.length ? req : req;
1342
1467
  }
1343
1468
  }();
1344
1469
  }
@@ -1373,46 +1498,45 @@ var TableQueryImpl = class {
1373
1498
  }
1374
1499
  return this;
1375
1500
  };
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);
1501
+ this.returning = (cols) => {
1502
+ state.returning = cols || [];
1503
+ return this;
1504
+ };
1505
+ this.toSql = () => {
1506
+ const params = {};
1507
+ const type_hints = {};
1508
+ let p = 0;
1509
+ const whereClauses = [];
1510
+ for (const key in state.where) {
1511
+ const value = state.where[key];
1512
+ const col = findColumn(table, key);
1513
+ p += 1;
1514
+ const paramName = `${table.name}_${key}_${p}`;
1515
+ if (value === null) {
1516
+ if (!col.is_nullable) throw new Error(`Column ${table.name}.${key} is not nullable; cannot compare to null`);
1517
+ whereClauses.push(`"${key}" is null`);
1518
+ } else if (Array.isArray(value)) {
1519
+ validateInArrayValues(col, key, value, "in");
1520
+ whereClauses.push(`"${key}" = ANY(:${paramName})`);
1521
+ params[paramName] = value;
1522
+ addTypeHintForParam(type_hints, paramName, col, value);
1523
+ } else {
1524
+ validateScalarForColumn(col, value, `column ${key}`);
1525
+ whereClauses.push(`"${key}" = :${paramName}`);
1526
+ params[paramName] = value;
1527
+ addTypeHintForParam(type_hints, paramName, col, value);
1528
+ }
1404
1529
  }
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
1530
+ const parts = [];
1531
+ parts.push(`delete from "${schema.name}"."${table.name}"`);
1532
+ if (whereClauses.length) parts.push("where " + whereClauses.join(" and "));
1533
+ if (state.returning.length) parts.push("returning " + state.returning.join(", "));
1534
+ return {
1535
+ q: parts.join(" "),
1536
+ params: Object.keys(params).length > 0 ? params : void 0,
1537
+ type_hints: Object.keys(type_hints).length ? type_hints : void 0
1538
+ };
1414
1539
  };
1415
- return state.returning.length ? req : req;
1416
1540
  }
1417
1541
  }();
1418
1542
  }
@@ -1421,9 +1545,19 @@ function createSqlBuilder(schema) {
1421
1545
  return { table: (name) => new TableQueryImpl(schema, String(name)) };
1422
1546
  }
1423
1547
 
1548
+ //#endregion
1549
+ //#region src/index.ts
1550
+ /**
1551
+ * @author Martin Høgh <mh@mapcentia.com>
1552
+ * @copyright 2013-2026 MapCentia ApS
1553
+ * @license https://opensource.org/license/mit The MIT License
1554
+ *
1555
+ */
1556
+
1424
1557
  //#endregion
1425
1558
  exports.Claims = Claims;
1426
1559
  exports.CodeFlow = CodeFlow;
1560
+ exports.GraphQL = GraphQL;
1427
1561
  exports.Meta = Meta;
1428
1562
  exports.PasswordFlow = PasswordFlow;
1429
1563
  exports.Rpc = Rpc;