-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
200 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = context => { | ||
|
||
class CustomerDataRequest extends context.db.Model { | ||
|
||
static get collection() { | ||
return 'customerDataRequests_temp_1'; | ||
} | ||
|
||
static get idProperty() { | ||
return 'id'; | ||
} | ||
|
||
static get properties() { | ||
|
||
return [ | ||
'id', | ||
'request', | ||
'created' | ||
]; | ||
} | ||
} | ||
|
||
CustomerDataRequest.createSettersAndGetters(); | ||
|
||
return CustomerDataRequest; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = context => { | ||
|
||
class CustomerRedactRequest extends context.db.Model { | ||
|
||
static get collection() { | ||
return 'customerRedactsRequests_temp_1'; | ||
} | ||
|
||
static get idProperty() { | ||
return 'id'; | ||
} | ||
|
||
static get properties() { | ||
|
||
return [ | ||
'id', | ||
'request', | ||
'created' | ||
]; | ||
} | ||
} | ||
|
||
CustomerRedactRequest.createSettersAndGetters(); | ||
|
||
return CustomerRedactRequest; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module.exports = context => { | ||
|
||
class ShopRedactRequest extends context.db.Model { | ||
|
||
static get collection() { | ||
return 'shopRedactRequests_temp_1'; | ||
} | ||
|
||
static get idProperty() { | ||
return 'id'; | ||
} | ||
|
||
static get properties() { | ||
|
||
return [ | ||
'id', | ||
'request', | ||
'created' | ||
]; | ||
} | ||
} | ||
|
||
ShopRedactRequest.createSettersAndGetters(); | ||
|
||
return ShopRedactRequest; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
"version": "0.1.0", | ||
"author": "Jimoh Damilola <[email protected]>", | ||
"dependencies": { | ||
"crypto": "1.0.1", | ||
"shopify-api-node": "3.12.1", | ||
"shopify-token": "4.0.0" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,22 @@ | ||
const path = require('path'); | ||
module.exports = async function(context) { | ||
|
||
module.exports = function(context) { | ||
const lock = await context.lock('shopify-plugin-init'); | ||
|
||
context.http.router.register({ | ||
method: 'POST', | ||
path: '/customers/data_request', | ||
options: { | ||
handler: (request, h) => { | ||
return {} | ||
}, | ||
auth: false | ||
} | ||
}); | ||
let secret; | ||
try { | ||
secret = await context.service.stateGet('secret'); | ||
if (!secret) { | ||
|
||
context.http.router.register({ | ||
method: 'POST', | ||
path: '/customers/redact', | ||
options: { | ||
handler: (request, h) => { | ||
return {} | ||
}, | ||
auth: false | ||
} | ||
}); | ||
await require('./CustomerDataRequest')(context).createIndex({ status: 1 }); | ||
await require('./CustomerRedactRequest')(context).createIndex({ status: 1 }); | ||
await require('./ShopRedactRequest')(context).createIndex({ status: 1 }); | ||
|
||
context.http.router.register({ | ||
method: 'POST', | ||
path: '/shop/redact', | ||
options: { | ||
handler: (request, h) => { | ||
return {} | ||
}, | ||
auth: false | ||
secret = require('crypto').randomBytes(128).toString('base64'); | ||
await context.service.stateSet('secret', secret); | ||
} | ||
}); | ||
} finally { | ||
lock.unlock(); | ||
} | ||
|
||
require('./routes')(context); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
module.exports = function(context) { | ||
|
||
const CustomerDataRequest = require('./CustomerDataRequest')(context); | ||
const CustomerRedactRequest = require('./CustomerRedactRequest')(context); | ||
const ShopRedactRequest = require('./ShopRedactRequest')(context); | ||
|
||
context.http.router.register({ | ||
method: 'POST', | ||
path: '/customers/data_request', | ||
options: { | ||
handler: (req) => { | ||
|
||
const { payload } = req; | ||
|
||
return new CustomerDataRequest().populate({ | ||
request: payload, | ||
created: new Date(), | ||
}).save(); | ||
}, | ||
auth: false | ||
} | ||
}); | ||
|
||
context.http.router.register({ | ||
method: 'POST', | ||
path: '/customers/redact', | ||
options: { | ||
handler: (req) => { | ||
|
||
const { payload } = req; | ||
|
||
return new CustomerRedactRequest().populate({ | ||
request: payload, | ||
created: new Date(), | ||
}).save(); | ||
}, | ||
auth: false | ||
} | ||
}); | ||
|
||
context.http.router.register({ | ||
method: 'POST', | ||
path: '/shop/redact', | ||
options: { | ||
handler: (req) => { | ||
|
||
const { payload } = req; | ||
|
||
return new ShopRedactRequest().populate({ | ||
request: payload, | ||
created: new Date(), | ||
}).save(); | ||
}, | ||
auth: false | ||
} | ||
}); | ||
|
||
context.http.router.register({ | ||
method: 'GET', | ||
path: '/customers/data_request', | ||
options: { | ||
handler: (request, h) => { | ||
return CustomerDataRequest.find() || []; | ||
}, | ||
auth: false | ||
} | ||
}); | ||
|
||
context.http.router.register({ | ||
method: 'GET', | ||
path: '/customers/redact', | ||
options: { | ||
handler: () => { | ||
return CustomerRedactRequest.find() || []; | ||
}, | ||
auth: false | ||
} | ||
}); | ||
|
||
context.http.router.register({ | ||
method: 'GET', | ||
path: '/shop/redact', | ||
options: { | ||
handler: () => { | ||
return ShopRedactRequest.find() || []; | ||
}, | ||
auth: false | ||
} | ||
}); | ||
|
||
context.http.router.register({ | ||
method: 'GET', | ||
path: '/', | ||
options: { | ||
handler: (request, h) => { | ||
return { | ||
version: '1.0', | ||
published: new Date().toISOString() | ||
}; | ||
}, | ||
auth: false | ||
} | ||
}); | ||
}; |