@kinevolution/appwrite-functions-shared-utils 0.1.61 → 0.1.62

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.
@@ -170,39 +170,46 @@ export interface MatchRequestsToCandidatesDataType {
170
170
  }
171
171
  export type MatchRequestsToCandidatesResponse = Response<MatchRequestsToCandidatesDataType>;
172
172
  export interface SendNotificationsInput {
173
- messageId: string;
174
- title: string;
175
- body: string;
176
- user: string;
177
- data: any;
178
- scheduledAt: Date;
173
+ notifications: {
174
+ messageId: string;
175
+ title: string;
176
+ body: string;
177
+ user: string;
178
+ data: any;
179
+ scheduledAt: Date;
180
+ }[];
179
181
  }
180
182
  export declare const SendNotificationsConfig: {
181
183
  method: "POST";
182
184
  fields: [{
183
- readonly key: "messageId";
184
- readonly type: "string";
185
- readonly required: true;
186
- }, {
187
- readonly key: "title";
188
- readonly type: "string";
189
- readonly required: true;
190
- }, {
191
- readonly key: "body";
192
- readonly type: "string";
193
- readonly required: true;
194
- }, {
195
- readonly key: "user";
196
- readonly type: "string";
197
- readonly required: true;
198
- }, {
199
- readonly key: "data";
200
- readonly type: "object";
201
- readonly required: true;
202
- }, {
203
- readonly key: "scheduledAt";
204
- readonly type: "string";
185
+ readonly key: "notifications";
186
+ readonly type: "array";
205
187
  readonly required: true;
188
+ readonly items: [{
189
+ readonly key: "messageId";
190
+ readonly type: "string";
191
+ readonly required: true;
192
+ }, {
193
+ readonly key: "title";
194
+ readonly type: "string";
195
+ readonly required: true;
196
+ }, {
197
+ readonly key: "body";
198
+ readonly type: "string";
199
+ readonly required: true;
200
+ }, {
201
+ readonly key: "user";
202
+ readonly type: "string";
203
+ readonly required: true;
204
+ }, {
205
+ readonly key: "data";
206
+ readonly type: "object";
207
+ readonly required: true;
208
+ }, {
209
+ readonly key: "scheduledAt";
210
+ readonly type: "string";
211
+ readonly required: true;
212
+ }];
206
213
  }];
207
214
  };
208
215
  export interface SendNotificationsDataType {
@@ -39,11 +39,18 @@ export const MatchRequestsToCandidatesConfig = {
39
39
  export const SendNotificationsConfig = {
40
40
  method: 'POST',
41
41
  fields: [
42
- { key: 'messageId', type: 'string', required: true },
43
- { key: 'title', type: 'string', required: true },
44
- { key: 'body', type: 'string', required: true },
45
- { key: 'user', type: 'string', required: true },
46
- { key: 'data', type: 'object', required: true },
47
- { key: 'scheduledAt', type: 'string', required: true },
42
+ {
43
+ key: 'notifications',
44
+ type: 'array',
45
+ required: true,
46
+ items: [
47
+ { key: 'messageId', type: 'string', required: true },
48
+ { key: 'title', type: 'string', required: true },
49
+ { key: 'body', type: 'string', required: true },
50
+ { key: 'user', type: 'string', required: true },
51
+ { key: 'data', type: 'object', required: true },
52
+ { key: 'scheduledAt', type: 'string', required: true },
53
+ ],
54
+ },
48
55
  ],
49
56
  };
package/dist/utils.d.ts CHANGED
@@ -58,8 +58,8 @@ type FieldDefinition = {
58
58
  } | {
59
59
  key: string;
60
60
  type: 'array';
61
- required: false;
62
- default: any[];
61
+ required: true;
62
+ items: FieldDefinition[];
63
63
  };
64
64
  interface ValidationResult<T> {
65
65
  valid: boolean;
package/dist/utils.js CHANGED
@@ -114,7 +114,27 @@ function validateRequestBody(bodyJson, fields) {
114
114
  errors.push(`Field "${field.key}" must be of type ${field.type}, received: ${typeof value}`);
115
115
  continue;
116
116
  }
117
- validatedData[field.key] = value;
117
+ // Additional validation for array items, if a schema is provided
118
+ if (field.type === 'array' && 'items' in field && Array.isArray(value)) {
119
+ const sanitizedItems = [];
120
+ for (let index = 0; index < value.length; index++) {
121
+ const element = value[index];
122
+ if (!element || typeof element !== 'object' || Array.isArray(element)) {
123
+ errors.push(`Element at index ${index} of "${field.key}" must be a non-null object`);
124
+ continue;
125
+ }
126
+ const itemValidation = validateRequestBody(element, field.items);
127
+ if (!itemValidation.valid) {
128
+ errors.push(`Invalid element at index ${index} for field "${field.key}": ${itemValidation.error}`);
129
+ continue;
130
+ }
131
+ sanitizedItems.push(itemValidation.data);
132
+ }
133
+ validatedData[field.key] = sanitizedItems;
134
+ }
135
+ else {
136
+ validatedData[field.key] = value;
137
+ }
118
138
  }
119
139
  // If errors were found
120
140
  if (errors.length > 0) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.61",
6
+ "version": "0.1.62",
7
7
  "license": "ISC",
8
8
  "author": "Nicolas Forêt <nicolas4@gmail.com>",
9
9
  "description": "Shared utilities for Appwrite functions",
@@ -34,9 +34,9 @@
34
34
  "gulp": "5.0.1",
35
35
  "gulp-replace": "1.1.4",
36
36
  "minimist": "1.2.8",
37
- "typescript": "5.9.3"
37
+ "typescript": "6.0.2"
38
38
  },
39
39
  "dependencies": {
40
- "appwrite": "23.0.0"
40
+ "appwrite": "24.1.1"
41
41
  }
42
42
  }