New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Amp subscriptions: Read service config from page #13611
Amp subscriptions: Read service config from page #13611
Conversation
prateekbh
commented
Feb 22, 2018
- Reads service config from page
- Waits for service config before initializing
- checks for authorization Url in service config
…mp-subscriptions-sconfig
…kbh/amphtml into amp-subscriptions-sconfig
@dvoytenko Looks like renaming changes did not got committed in the last PR, so they are here in this one |
examples/amp-subscriptions.amp.html
Outdated
{ | ||
"services": [ | ||
{ | ||
"serviceId":"amp.local.subscription", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove serviceId
here and just default to "local".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
examples/amp-subscriptions.amp.html
Outdated
"authorizationUrl": "/subscription/2/entitlements" | ||
}, | ||
{ | ||
"serviceId":"google.subscription" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"subscribe.google.com"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/** @private @const {!Array<!SubscriptionPlatform>} */ | ||
this.subscriptionPlatforms_ = []; | ||
|
||
/** @private {?EntitlementStore} */ | ||
this.entitlementStore_ = null; | ||
|
||
/** @const @private {!Element} */ | ||
this.configElement_ = dev().assertElement(configElement); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use user().assertElement
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
]); | ||
|
||
return configPromises.then(promiseValues => { | ||
const serviceConfig = user().assert(promiseValues[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to add typing for serviceConfig
and pageConfig
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like a /** typedef / or a just /* {!PageConfig} ? and /* JsonObject<string, string> */
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** @type {!PageConfig} */
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
* @private | ||
*/ | ||
initializeSubscriptionPlatforms_(serviceConfig, pageConfig) { | ||
if (serviceConfig['authorizationUrl']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be that if ((serviceConfig['serviceId'] || 'local') == 'local') {...}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
@@ -51,12 +51,13 @@ export class LocalSubscriptionPlatform { | |||
* @return {!Promise<!Entitlements>} | |||
*/ | |||
getEntitlements() { | |||
user().assert(this.serviceConfig_['paywallUrl'], | |||
'Service config does not have paywall Url'); | |||
const authUrl = user().assert(this.serviceConfig_['authorizationUrl'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's best to initialize all authorizationUrl
in the constructor and also call assertHttpsUrl
on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return this.xhr_ | ||
.fetchJson(this.serviceConfig_['paywallUrl']) | ||
.fetchJson(authUrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make sure all CORS stuff is added here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there something like a util for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the fetchJson
API. I believe it's something like this:
fetchJson(url, {
credentials: 'include',
})
But please double-check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I guess!
return this.xhr_ | ||
.fetchJson(this.serviceConfig_['paywallUrl']) | ||
.fetchJson(this.authorizationUrl_,{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space between "," and "{"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return this.xhr_ | ||
.fetchJson(this.serviceConfig_['paywallUrl']) | ||
.fetchJson(this.authorizationUrl_,{ | ||
mode: 'cors', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for mode
here. Found this: https://github.com/ampproject/amphtml/blob/master/extensions/amp-access/0.1/amp-access-client.js#L126
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
.fetchJson(this.serviceConfig_['paywallUrl']) | ||
.fetchJson(this.authorizationUrl_,{ | ||
mode: 'cors', | ||
credentials: 'include', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this needs a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
* fix animating circle fixed position * adding null resolve if no entitlements enables reader * adding tests * adding tests for entitlements store * lint fixes * sending page config to subscription platform * fixing comments * changing promise resolution of firstPositive * reading serviceConfig * fixing existing tests * adding test for service config * fixed nits * fixing conflicts * fixing comments * fixing cors and types * adding more test