Skip to content

Commit

Permalink
Shopify: mandatory webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
vtalas committed Mar 15, 2024
1 parent 9ee718d commit cedfc43
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 31 deletions.
26 changes: 26 additions & 0 deletions src/appmixer/shopify/CustomerDataRequest.js
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;
};
26 changes: 26 additions & 0 deletions src/appmixer/shopify/CustomerRedactRequest.js
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;
};
27 changes: 27 additions & 0 deletions src/appmixer/shopify/ShopRedactRequest.js
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;
};

1 change: 1 addition & 0 deletions src/appmixer/shopify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
47 changes: 16 additions & 31 deletions src/appmixer/shopify/plugin.js
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);
};
104 changes: 104 additions & 0 deletions src/appmixer/shopify/routes.js
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(),

Check failure on line 17 in src/appmixer/shopify/routes.js

View workflow job for this annotation

GitHub Actions / build

Unexpected trailing comma
}).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(),

Check failure on line 34 in src/appmixer/shopify/routes.js

View workflow job for this annotation

GitHub Actions / build

Unexpected trailing comma
}).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(),

Check failure on line 51 in src/appmixer/shopify/routes.js

View workflow job for this annotation

GitHub Actions / build

Unexpected trailing comma
}).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
}
});
};

0 comments on commit cedfc43

Please sign in to comment.