backend-manager 5.0.103 → 5.0.104
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.
- package/package.json +1 -1
- package/src/manager/routes/forms/delete.js +0 -37
- package/src/manager/routes/forms/get.js +0 -46
- package/src/manager/routes/forms/post.js +0 -45
- package/src/manager/routes/forms/public/get.js +0 -37
- package/src/manager/routes/forms/put.js +0 -52
- package/src/manager/schemas/forms/delete.js +0 -6
- package/src/manager/schemas/forms/get.js +0 -6
- package/src/manager/schemas/forms/post.js +0 -9
- package/src/manager/schemas/forms/public/get.js +0 -6
- package/src/manager/schemas/forms/put.js +0 -10
package/package.json
CHANGED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DELETE /forms - Delete a form
|
|
3
|
-
* Requires authentication and ownership.
|
|
4
|
-
*/
|
|
5
|
-
module.exports = async ({ assistant, user, settings, analytics, libraries }) => {
|
|
6
|
-
const { admin } = libraries;
|
|
7
|
-
|
|
8
|
-
// Require authentication
|
|
9
|
-
if (!user.authenticated) {
|
|
10
|
-
return assistant.respond('Authentication required', { code: 401 });
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (!settings.id) {
|
|
14
|
-
return assistant.respond('Missing required parameter: id', { code: 400 });
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const uid = user.auth.uid;
|
|
18
|
-
const formRef = admin.firestore().doc(`forms/${settings.id}`);
|
|
19
|
-
const doc = await formRef.get();
|
|
20
|
-
|
|
21
|
-
if (!doc.exists) {
|
|
22
|
-
return assistant.respond('Form not found', { code: 404 });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Ownership check
|
|
26
|
-
if (doc.data().owner !== uid) {
|
|
27
|
-
return assistant.respond('Not authorized to delete this form', { code: 403 });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
await formRef.delete();
|
|
31
|
-
|
|
32
|
-
assistant.log(`Deleted form ${settings.id} for user ${uid}`);
|
|
33
|
-
|
|
34
|
-
analytics.event('forms', { action: 'delete' });
|
|
35
|
-
|
|
36
|
-
return assistant.respond({ data: { deleted: true } });
|
|
37
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GET /forms - Get a single form or list all forms for the authenticated user
|
|
3
|
-
* Requires authentication.
|
|
4
|
-
* - With ?id=xxx: returns a single form (with ownership check)
|
|
5
|
-
* - Without id: returns all forms owned by the user
|
|
6
|
-
*/
|
|
7
|
-
module.exports = async ({ assistant, user, settings, analytics, libraries }) => {
|
|
8
|
-
const { admin } = libraries;
|
|
9
|
-
|
|
10
|
-
// Require authentication
|
|
11
|
-
if (!user.authenticated) {
|
|
12
|
-
return assistant.respond('Authentication required', { code: 401 });
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const uid = user.auth.uid;
|
|
16
|
-
|
|
17
|
-
// Single form
|
|
18
|
-
if (settings.id) {
|
|
19
|
-
const doc = await admin.firestore().doc(`forms/${settings.id}`).get();
|
|
20
|
-
|
|
21
|
-
if (!doc.exists) {
|
|
22
|
-
return assistant.respond('Form not found', { code: 404 });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (doc.data().owner !== uid) {
|
|
26
|
-
return assistant.respond('Not authorized to view this form', { code: 403 });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
analytics.event('forms', { action: 'get' });
|
|
30
|
-
|
|
31
|
-
return assistant.respond({ data: { form: doc.data() } });
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// List all forms
|
|
35
|
-
const snapshot = await admin.firestore()
|
|
36
|
-
.collection('forms')
|
|
37
|
-
.where('owner', '==', uid)
|
|
38
|
-
.orderBy('created.timestampUNIX', 'desc')
|
|
39
|
-
.get();
|
|
40
|
-
|
|
41
|
-
const forms = snapshot.docs.map(doc => doc.data());
|
|
42
|
-
|
|
43
|
-
analytics.event('forms', { action: 'list' });
|
|
44
|
-
|
|
45
|
-
return assistant.respond({ data: { forms } });
|
|
46
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* POST /forms - Create a new form
|
|
3
|
-
* Requires authentication. Creates a Firestore doc in the `forms` collection.
|
|
4
|
-
*/
|
|
5
|
-
module.exports = async ({ assistant, Manager, user, settings, analytics, libraries }) => {
|
|
6
|
-
const { admin } = libraries;
|
|
7
|
-
|
|
8
|
-
// Require authentication
|
|
9
|
-
if (!user.authenticated) {
|
|
10
|
-
return assistant.respond('Authentication required', { code: 401 });
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const uid = user.auth.uid;
|
|
14
|
-
const now = new Date().toISOString();
|
|
15
|
-
const nowUnix = Date.now();
|
|
16
|
-
|
|
17
|
-
// Generate a new document reference
|
|
18
|
-
const docRef = admin.firestore().collection('forms').doc();
|
|
19
|
-
|
|
20
|
-
const form = {
|
|
21
|
-
id: docRef.id,
|
|
22
|
-
owner: uid,
|
|
23
|
-
name: settings.name || 'Untitled Form',
|
|
24
|
-
description: settings.description || '',
|
|
25
|
-
settings: settings.settings || {},
|
|
26
|
-
pages: settings.pages || [],
|
|
27
|
-
created: {
|
|
28
|
-
timestamp: now,
|
|
29
|
-
timestampUNIX: nowUnix,
|
|
30
|
-
},
|
|
31
|
-
edited: {
|
|
32
|
-
timestamp: now,
|
|
33
|
-
timestampUNIX: nowUnix,
|
|
34
|
-
},
|
|
35
|
-
metadata: Manager.Metadata().set({ tag: 'forms/post' }),
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
await docRef.set(form);
|
|
39
|
-
|
|
40
|
-
assistant.log(`Created form ${docRef.id} for user ${uid}`);
|
|
41
|
-
|
|
42
|
-
analytics.event('forms', { action: 'create' });
|
|
43
|
-
|
|
44
|
-
return assistant.respond({ data: { id: docRef.id, form } });
|
|
45
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GET /forms/public - Get a public form by ID
|
|
3
|
-
* No authentication required. Only returns forms with settings.public = true.
|
|
4
|
-
*/
|
|
5
|
-
module.exports = async ({ assistant, settings, analytics, libraries }) => {
|
|
6
|
-
const { admin } = libraries;
|
|
7
|
-
|
|
8
|
-
if (!settings.id) {
|
|
9
|
-
return assistant.respond('Missing required parameter: id', { code: 400 });
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const doc = await admin.firestore().doc(`forms/${settings.id}`).get();
|
|
13
|
-
|
|
14
|
-
if (!doc.exists) {
|
|
15
|
-
return assistant.respond('Form not found', { code: 404 });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const form = doc.data();
|
|
19
|
-
|
|
20
|
-
// Only allow access to public forms
|
|
21
|
-
if (!form.settings?.public) {
|
|
22
|
-
return assistant.respond('Form not found', { code: 404 });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Strip sensitive fields
|
|
26
|
-
const publicForm = {
|
|
27
|
-
id: form.id,
|
|
28
|
-
name: form.name,
|
|
29
|
-
description: form.description,
|
|
30
|
-
settings: form.settings,
|
|
31
|
-
pages: form.pages,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
analytics.event('forms/public', { action: 'get' });
|
|
35
|
-
|
|
36
|
-
return assistant.respond({ payload: publicForm });
|
|
37
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PUT /forms - Update an existing form
|
|
3
|
-
* Requires authentication and ownership.
|
|
4
|
-
*/
|
|
5
|
-
module.exports = async ({ assistant, Manager, user, settings, analytics, libraries }) => {
|
|
6
|
-
const { admin } = libraries;
|
|
7
|
-
|
|
8
|
-
// Require authentication
|
|
9
|
-
if (!user.authenticated) {
|
|
10
|
-
return assistant.respond('Authentication required', { code: 401 });
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (!settings.id) {
|
|
14
|
-
return assistant.respond('Missing required parameter: id', { code: 400 });
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const uid = user.auth.uid;
|
|
18
|
-
const formRef = admin.firestore().doc(`forms/${settings.id}`);
|
|
19
|
-
const doc = await formRef.get();
|
|
20
|
-
|
|
21
|
-
if (!doc.exists) {
|
|
22
|
-
return assistant.respond('Form not found', { code: 404 });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Ownership check
|
|
26
|
-
if (doc.data().owner !== uid) {
|
|
27
|
-
return assistant.respond('Not authorized to edit this form', { code: 403 });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const now = new Date().toISOString();
|
|
31
|
-
const nowUnix = Date.now();
|
|
32
|
-
|
|
33
|
-
const updates = {
|
|
34
|
-
name: settings.name,
|
|
35
|
-
description: settings.description,
|
|
36
|
-
settings: settings.settings,
|
|
37
|
-
pages: settings.pages,
|
|
38
|
-
edited: {
|
|
39
|
-
timestamp: now,
|
|
40
|
-
timestampUNIX: nowUnix,
|
|
41
|
-
},
|
|
42
|
-
metadata: Manager.Metadata().set({ tag: 'forms/put' }),
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
await formRef.update(updates);
|
|
46
|
-
|
|
47
|
-
assistant.log(`Updated form ${settings.id} for user ${uid}`);
|
|
48
|
-
|
|
49
|
-
analytics.event('forms', { action: 'update' });
|
|
50
|
-
|
|
51
|
-
return assistant.respond({ data: { id: settings.id } });
|
|
52
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema for POST /forms (create)
|
|
3
|
-
*/
|
|
4
|
-
module.exports = () => ({
|
|
5
|
-
name: { types: ['string'], default: 'Untitled Form' },
|
|
6
|
-
description: { types: ['string'], default: '' },
|
|
7
|
-
settings: { types: ['object'], default: {} },
|
|
8
|
-
pages: { types: ['array'], default: [] },
|
|
9
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema for PUT /forms (update)
|
|
3
|
-
*/
|
|
4
|
-
module.exports = () => ({
|
|
5
|
-
id: { types: ['string'], default: undefined, required: true },
|
|
6
|
-
name: { types: ['string'], default: undefined },
|
|
7
|
-
description: { types: ['string'], default: undefined },
|
|
8
|
-
settings: { types: ['object'], default: undefined },
|
|
9
|
-
pages: { types: ['array'], default: undefined },
|
|
10
|
-
});
|