@unito/integration-api 4.6.1 → 4.7.0

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.
@@ -56,16 +56,20 @@
56
56
  },
57
57
  "readOnly": {
58
58
  "type": "boolean",
59
- "deprecated": true
59
+ "deprecated": true,
60
+ "default": false
60
61
  },
61
62
  "canSetOnCreate": {
62
- "type": "boolean"
63
+ "type": "boolean",
64
+ "default": true
63
65
  },
64
66
  "canSetOnUpdate": {
65
- "type": "boolean"
67
+ "type": "boolean",
68
+ "default": true
66
69
  },
67
70
  "isArray": {
68
- "type": "boolean"
71
+ "type": "boolean",
72
+ "default": false
69
73
  },
70
74
  "nullable": {
71
75
  "type": "boolean",
@@ -11,19 +11,24 @@
11
11
  "maxLength": 100
12
12
  },
13
13
  "canReadItem": {
14
- "type": "boolean"
14
+ "type": "boolean",
15
+ "default": true
15
16
  },
16
17
  "canCreateItem": {
17
- "type": "boolean"
18
+ "type": "boolean",
19
+ "default": true
18
20
  },
19
21
  "canUpdateItem": {
20
- "type": "boolean"
22
+ "type": "boolean",
23
+ "default": true
21
24
  },
22
25
  "canDeleteItem": {
23
- "type": "boolean"
26
+ "type": "boolean",
27
+ "default": false
24
28
  },
25
29
  "canAddFields": {
26
- "type": "boolean"
30
+ "type": "boolean",
31
+ "default": false
27
32
  },
28
33
  "fields": {
29
34
  "type": "array",
@@ -7,19 +7,20 @@
7
7
  {
8
8
  "$ref": "https://unito.io/integration_api/webhookParsedItem.schema.json"
9
9
  },
10
- {
11
- "type": "array",
12
- "items": {
13
- "$ref": "https://unito.io/integration_api/webhookParsedItem.schema.json"
14
- }
15
- },
16
10
  {
17
11
  "$ref": "https://unito.io/integration_api/webhookItem.schema.json"
18
12
  },
19
13
  {
20
14
  "type": "array",
21
15
  "items": {
22
- "$ref": "https://unito.io/integration_api/webhookItem.schema.json"
16
+ "anyOf": [
17
+ {
18
+ "$ref": "https://unito.io/integration_api/webhookParsedItem.schema.json"
19
+ },
20
+ {
21
+ "$ref": "https://unito.io/integration_api/webhookItem.schema.json"
22
+ }
23
+ ]
23
24
  }
24
25
  }
25
26
  ]
@@ -84,6 +84,25 @@ const StatusCodes = {
84
84
  TOO_MANY_REQUESTS: 429,
85
85
  INTERNAL_SERVER_ERROR: 500,
86
86
  };
87
+ /**
88
+ * Default values of properties of a relation schema.
89
+ */
90
+ const RelationSchemaDefaultValues = {
91
+ CAN_READ_ITEM: true,
92
+ CAN_CREATE_ITEM: true,
93
+ CAN_UPDATE_ITEM: true,
94
+ CAN_DELETE_ITEM: false,
95
+ CAN_ADD_FIELDS: false,
96
+ };
97
+ /**
98
+ * Default values of properties of a field schema.
99
+ */
100
+ const FieldSchemaDefaultValues = {
101
+ CAN_SET_ON_CREATE: true,
102
+ CAN_SET_ON_UPDATE: true,
103
+ IS_ARRAY: false,
104
+ NULLABLE: false,
105
+ };
87
106
 
88
107
  /**
89
108
  * Checks if the input is a record<unknown, unknown>
@@ -780,8 +799,10 @@ function matchesFilter(item, filter) {
780
799
  return item[filter.property] === filter.value;
781
800
  }
782
801
 
802
+ exports.FieldSchemaDefaultValues = FieldSchemaDefaultValues;
783
803
  exports.FieldValueTypes = FieldValueTypes;
784
804
  exports.OperatorTypes = OperatorTypes;
805
+ exports.RelationSchemaDefaultValues = RelationSchemaDefaultValues;
785
806
  exports.RelationSemantics = RelationSemantics;
786
807
  exports.Semantics = Semantics;
787
808
  exports.StatusCodes = StatusCodes;
@@ -1,4 +1,4 @@
1
- import * as Api from './index.js';
1
+ import * as Api from './types.js';
2
2
  /**
3
3
  * JSONPath parser that returns a relation that is guaranteed to have its schema populated.
4
4
  */
@@ -1,4 +1,4 @@
1
- import * as Api from './index.js';
1
+ import * as Guards from './guards.js';
2
2
  /**
3
3
  * JSONPath parser that returns a relation that is guaranteed to have its schema populated.
4
4
  */
@@ -15,15 +15,15 @@ export function findRelationByJSONPath(item, query) {
15
15
  current = previousSchema;
16
16
  }
17
17
  const result = applyToken(current, token);
18
- if (Api.isObject(result) && Api.isRelationSchema(result['schema'])) {
18
+ if (Guards.isObject(result) && Guards.isRelationSchema(result['schema'])) {
19
19
  schemas.push(result['schema']);
20
20
  }
21
21
  current = result;
22
22
  }
23
- if (Api.isRelation(current)) {
23
+ if (Guards.isRelation(current)) {
24
24
  return current;
25
25
  }
26
- if (Api.isReferenceRelation(current) || Api.isRelationSummary(current)) {
26
+ if (Guards.isReferenceRelation(current) || Guards.isRelationSummary(current)) {
27
27
  const latestSchema = schemas[schemas.length - 1];
28
28
  if (latestSchema === undefined) {
29
29
  throw new Error(`No schema found for relation ${current.label}`);
@@ -125,7 +125,7 @@ function applyToken(current, token) {
125
125
  * Apply property access
126
126
  */
127
127
  function applyProperty(current, property) {
128
- if (!Api.isObject(current) || !(property in current)) {
128
+ if (!Guards.isObject(current) || !(property in current)) {
129
129
  return undefined;
130
130
  }
131
131
  return current[property];
@@ -149,7 +149,7 @@ function applyFilter(current, filter) {
149
149
  return undefined;
150
150
  }
151
151
  for (const item of current) {
152
- if (Api.isObject(item) && matchesFilter(item, filter)) {
152
+ if (Guards.isObject(item) && matchesFilter(item, filter)) {
153
153
  return item;
154
154
  }
155
155
  }
@@ -94,10 +94,12 @@ interface AbstractFieldSchema {
94
94
  * Whether the field returns an array. Defaults to false.
95
95
  * An array is a non-paginated list of same-type values.
96
96
  * For pagination, use a relation instead.
97
+ * Defaults to false.
97
98
  */
98
99
  isArray?: boolean;
99
100
  /**
100
- * Whether the field can be empty. Default to true.
101
+ * Whether the field can be empty.
102
+ * Defaults to true.
101
103
  */
102
104
  nullable?: boolean;
103
105
  }
@@ -594,5 +596,24 @@ export interface WebhookItem {
594
596
  /**
595
597
  * A WebhookParseResponsePayload describes the shape of the response on the "parse webhook" endpoint.
596
598
  */
597
- export type WebhookParseResponsePayload = WebhookParsedItem | WebhookParsedItem[] | WebhookItem | WebhookItem[];
599
+ export type WebhookParseResponsePayload = WebhookParsedItem | WebhookItem | (WebhookParsedItem | WebhookItem)[];
600
+ /**
601
+ * Default values of properties of a relation schema.
602
+ */
603
+ export declare const RelationSchemaDefaultValues: {
604
+ readonly CAN_READ_ITEM: true;
605
+ readonly CAN_CREATE_ITEM: true;
606
+ readonly CAN_UPDATE_ITEM: true;
607
+ readonly CAN_DELETE_ITEM: false;
608
+ readonly CAN_ADD_FIELDS: false;
609
+ };
610
+ /**
611
+ * Default values of properties of a field schema.
612
+ */
613
+ export declare const FieldSchemaDefaultValues: {
614
+ readonly CAN_SET_ON_CREATE: true;
615
+ readonly CAN_SET_ON_UPDATE: true;
616
+ readonly IS_ARRAY: false;
617
+ readonly NULLABLE: false;
618
+ };
598
619
  export {};
package/dist/src/types.js CHANGED
@@ -82,3 +82,22 @@ export const StatusCodes = {
82
82
  TOO_MANY_REQUESTS: 429,
83
83
  INTERNAL_SERVER_ERROR: 500,
84
84
  };
85
+ /**
86
+ * Default values of properties of a relation schema.
87
+ */
88
+ export const RelationSchemaDefaultValues = {
89
+ CAN_READ_ITEM: true,
90
+ CAN_CREATE_ITEM: true,
91
+ CAN_UPDATE_ITEM: true,
92
+ CAN_DELETE_ITEM: false,
93
+ CAN_ADD_FIELDS: false,
94
+ };
95
+ /**
96
+ * Default values of properties of a field schema.
97
+ */
98
+ export const FieldSchemaDefaultValues = {
99
+ CAN_SET_ON_CREATE: true,
100
+ CAN_SET_ON_UPDATE: true,
101
+ IS_ARRAY: false,
102
+ NULLABLE: false,
103
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-api",
3
- "version": "4.6.1",
3
+ "version": "4.7.0",
4
4
  "description": "The Unito Integration API",
5
5
  "type": "module",
6
6
  "types": "./dist/src/index.d.ts",