@kinevolution/appwrite-functions-shared-utils 0.1.60 → 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.
@@ -169,3 +169,49 @@ export declare const MatchRequestsToCandidatesConfig: {
169
169
  export interface MatchRequestsToCandidatesDataType {
170
170
  }
171
171
  export type MatchRequestsToCandidatesResponse = Response<MatchRequestsToCandidatesDataType>;
172
+ export interface SendNotificationsInput {
173
+ notifications: {
174
+ messageId: string;
175
+ title: string;
176
+ body: string;
177
+ user: string;
178
+ data: any;
179
+ scheduledAt: Date;
180
+ }[];
181
+ }
182
+ export declare const SendNotificationsConfig: {
183
+ method: "POST";
184
+ fields: [{
185
+ readonly key: "notifications";
186
+ readonly type: "array";
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
+ }];
213
+ }];
214
+ };
215
+ export interface SendNotificationsDataType {
216
+ }
217
+ export type SendNotificationsResponse = Response<SendNotificationsDataType>;
@@ -36,3 +36,21 @@ export const MatchRequestsToCandidatesConfig = {
36
36
  method: 'POST',
37
37
  fields: [],
38
38
  };
39
+ export const SendNotificationsConfig = {
40
+ method: 'POST',
41
+ fields: [
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
+ },
55
+ ],
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.60",
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
  }