diff --git a/package.json b/package.json index dfa69b7..ca4d01c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "solid-rest", - "version": "1.2.7", + "version": "1.2.8", "author": "Jeff Zucker", "license": "MIT", "description": "treat any storage as a mini Solid server", diff --git a/src/createServerlessPod.js b/src/createServerlessPod.js new file mode 100644 index 0000000..aa0e94b --- /dev/null +++ b/src/createServerlessPod.js @@ -0,0 +1,97 @@ + +module.exports.profile_content = `@prefix : <#>. +@prefix jef: . +@prefix ldp: . +@prefix inbox: <../inbox/>. +@prefix pro: <./>. +@prefix ter: . +@prefix foaf: . +@prefix pim: . +@prefix n2: . +@prefix n3: . +@prefix vcard: . +@prefix sch: . +@prefix n1: . + +pro:card a foaf:PersonalProfileDocument; foaf:maker :me; foaf:primaryTopic :me. + +:me + a sch:Person, foaf:Person; + vcard:fn "Local Solid User"; + vcard:role "software developer"; + n1:trustedApp + [ + n1:mode n1:Append, n1:Control, n1:Read, n1:Write; + n1:origin + ]; + ldp:inbox inbox:; + pim:preferencesFile <../settings/prefs.ttl>; + pim:storage jef:; + ter:account jef:; + ter:privateTypeIndex <../settings/privateTypeIndex.ttl>; + ter:publicTypeIndex <../settings/publicTypeIndex.ttl>; + foaf:name "Local Solid User". +`; + +module.exports.prefs_content = `@prefix : <#>. +@prefix solid: . +@prefix sp: . +@prefix dct: . +@prefix c: <../profile/card#>. +@prefix mee: . + +<> a sp:ConfigurationFile; dct:title "Preferences file". + +c:me + a solid:Developer, solid:PowerUser; + solid:privateTypeIndex ; + solid:publicTypeIndex . +`; + +module.exports.public_content = `@prefix : <#>. +@prefix solid: . +@prefix terms: . +@prefix ter: . +@prefix bookm: . + +<> a solid:ListedDocument, solid:TypeIndex; terms:references :Bookmark. + +:Bookmark + a ter:TypeRegistration; + ter:forClass bookm:Bookmark; + ter:instance <../bookmarks.ttl>. +`; +module.exports.private_content = ` +@prefix solid: . +<> + a solid:TypeIndex ; + a solid:UnlistedDocument. +`; + +module.exports.acl_content = `@prefix acl: . +@prefix foaf: . + +# The homepage is readable by the public +<#public> + a acl:Authorization; + acl:agentClass foaf:Agent; + acl:accessTo <./>; + acl:mode acl:Read. + +# The owner has full access to every resource in their pod. +# Other agents have no access rights, +# unless specifically authorized in other .acl resources. +<#owner> + a acl:Authorization; + acl:agent <./profile/card#me>; + # Set the access to the root storage folder itself + acl:accessTo <./>; + # All resources will inherit this authorization, by default + acl:default <./>; + # The owner has all of the access modes allowed + acl:mode + acl:Read, acl:Write, acl:Control. +`; + +/* ENDS */ + diff --git a/src/rest.js b/src/rest.js index 40ad69d..af54995 100644 --- a/src/rest.js +++ b/src/rest.js @@ -6,6 +6,7 @@ const crossFetch = require('cross-fetch') const { v1: uuidv1 } = require('uuid') const contentTypeLookup = require('mime-types').contentType const RestPatch = require('./rest-patch') +const pod = require('./createServerlessPod.js') const linkExt = ['.acl', '.meta'] const linksExt = linkExt.concat('.meta.acl') @@ -13,7 +14,6 @@ let patch; class SolidRest { -//constructor( handlers,auth,sessionId ) { constructor( options ) { let handlers; if(typeof options === "object"){ @@ -85,6 +85,30 @@ addFetch( auth,sessionId ) { return auth } + async createServerlessPod( base ){ + console.log(`Creating pod at <${base}>`); + base = base.replace(/\/$/,''); + await this.makeResource( base,"/.acl", pod.acl_content ); + await this.makeResource( base,"/profile/card", pod.profile_content ); + await this.makeResource( base,"/settings/prefs.ttl", pod.prefs_content ); + await this.makeResource(base,"/settings/privateTypeIndex.ttl",pod.private_content ); + await this.makeResource( base,"/settings/publicTypeIndex.ttl", pod.public_content ); + await this.makeResource( base,"/private/.meta", "" ); + await this.makeResource( base,"/.well-known/.meta", "" ); + await this.makeResource( base,"/public/.meta", "" ); + await this.makeResource( base,"/inbox/.meta", "" ); + } + async makeResource( base, path, content ){ + let url = base + path + console.log ( " creating " + path ) + await this.fetch( url, { + method:"PUT", + body:content, + headers:{"content-type":"text/turtle"} + }) + } + + storage(options){ const prefix = (typeof options==="string") ? options : options.rest_prefix if(!this.storageHandlers[prefix]) throw "Did not recognize prefix "+prefix