|
| 1 | +const request_examples = [ |
| 2 | + { |
| 3 | + name: 'entity storage app read', |
| 4 | + fetch: async (args) => { |
| 5 | + return await fetch(`${window.api_origin}/drivers/call`, { |
| 6 | + headers: { |
| 7 | + "Content-Type": "application/json", |
| 8 | + "Authorization": `Bearer ${puter.authToken}`, |
| 9 | + }, |
| 10 | + body: JSON.stringify({ |
| 11 | + interface: 'puter-apps', |
| 12 | + method: 'read', |
| 13 | + args, |
| 14 | + }), |
| 15 | + method: "POST", |
| 16 | + }); |
| 17 | + }, |
| 18 | + out: async (resp) => { |
| 19 | + const data = await resp.json(); |
| 20 | + if ( ! data.success ) return data; |
| 21 | + return data.result; |
| 22 | + }, |
| 23 | + exec: async function exec (...a) { |
| 24 | + const resp = await this.fetch(...a); |
| 25 | + return await this.out(resp); |
| 26 | + }, |
| 27 | + }, |
| 28 | + { |
| 29 | + name: 'entity storage app select all', |
| 30 | + fetch: async () => { |
| 31 | + return await fetch(`${window.api_origin}/drivers/call`, { |
| 32 | + headers: { |
| 33 | + "Content-Type": "application/json", |
| 34 | + "Authorization": `Bearer ${puter.authToken}`, |
| 35 | + }, |
| 36 | + body: JSON.stringify({ |
| 37 | + interface: 'puter-apps', |
| 38 | + method: 'select', |
| 39 | + args: { predicate: [] }, |
| 40 | + }), |
| 41 | + method: "POST", |
| 42 | + }); |
| 43 | + }, |
| 44 | + out: async (resp) => { |
| 45 | + const data = await resp.json(); |
| 46 | + if ( ! data.success ) return data; |
| 47 | + return data.result; |
| 48 | + }, |
| 49 | + exec: async function exec (...a) { |
| 50 | + const resp = await this.fetch(...a); |
| 51 | + return await this.out(resp); |
| 52 | + }, |
| 53 | + }, |
| 54 | + { |
| 55 | + name: 'grant permission from a user to a user', |
| 56 | + fetch: async (user, perm) => { |
| 57 | + return await fetch(`${window.api_origin}/auth/grant-user-user`, { |
| 58 | + "headers": { |
| 59 | + "Content-Type": "application/json", |
| 60 | + "Authorization": `Bearer ${puter.authToken}`, |
| 61 | + }, |
| 62 | + "body": JSON.stringify({ |
| 63 | + target_username: user, |
| 64 | + permission: perm, |
| 65 | + }), |
| 66 | + "method": "POST", |
| 67 | + }); |
| 68 | + }, |
| 69 | + out: async (resp) => { |
| 70 | + const data = await resp.json(); |
| 71 | + return data; |
| 72 | + }, |
| 73 | + exec: async function exec (...a) { |
| 74 | + const resp = await this.fetch(...a); |
| 75 | + return await this.out(resp); |
| 76 | + }, |
| 77 | + } |
| 78 | +]; |
| 79 | + |
| 80 | +globalThis.reqex = request_examples; |
| 81 | + |
| 82 | +globalThis.service_script(api => { |
| 83 | + api.on_ready(() => { |
| 84 | + }); |
| 85 | +}); |
0 commit comments