Skip to content

Commit

Permalink
add createServerLessPod
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-zucker committed Nov 24, 2020
1 parent 3bf1383 commit 8b52917
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
97 changes: 97 additions & 0 deletions src/createServerlessPod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

module.exports.profile_content = `@prefix : <#>.
@prefix jef: </>.
@prefix ldp: <http://www.w3.org/ns/ldp#>.
@prefix inbox: <../inbox/>.
@prefix pro: <./>.
@prefix ter: <http://www.w3.org/ns/solid/terms#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix pim: <http://www.w3.org/ns/pim/space#>.
@prefix n2: <http://>.
@prefix n3: <https://>.
@prefix vcard: <http://www.w3.org/2006/vcard/ns#>.
@prefix sch: <http://schema.org/>.
@prefix n1: <http://www.w3.org/ns/auth/acl#>.
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 <http://example.org>
];
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: <http://www.w3.org/ns/solid/terms#>.
@prefix sp: <http://www.w3.org/ns/pim/space#>.
@prefix dct: <http://purl.org/dc/terms/>.
@prefix c: <../profile/card#>.
@prefix mee: <http://www.w3.org/ns/pim/meeting#>.
<> a sp:ConfigurationFile; dct:title "Preferences file".
c:me
a solid:Developer, solid:PowerUser;
solid:privateTypeIndex <privateTypeIndex.ttl>;
solid:publicTypeIndex <publicTypeIndex.ttl>.
`;

module.exports.public_content = `@prefix : <#>.
@prefix solid: <https://www.w3.org/ns/solid/terms#>.
@prefix terms: <http://purl.org/dc/terms/>.
@prefix ter: <http://www.w3.org/ns/solid/terms#>.
@prefix bookm: <http://www.w3.org/2002/01/bookmark#>.
<> 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: <https://www.w3.org/ns/solid/terms#>.
<>
a solid:TypeIndex ;
a solid:UnlistedDocument.
`;

module.exports.acl_content = `@prefix acl: <http://www.w3.org/ns/auth/acl#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
# 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 */

26 changes: 25 additions & 1 deletion src/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ 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')
let patch;

class SolidRest {

//constructor( handlers,auth,sessionId ) {
constructor( options ) {
let handlers;
if(typeof options === "object"){
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8b52917

Please sign in to comment.