Skip to content
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

Merged
merged 23 commits into from Feb 23, 2018
Merged

Amp subscriptions: Read service config from page #13611

merged 23 commits into from Feb 23, 2018

Conversation

prateekbh
Copy link
Member

  • Reads service config from page
  • Waits for service config before initializing
  • checks for authorization Url in service config

@prateekbh
Copy link
Member Author

@dvoytenko Looks like renaming changes did not got committed in the last PR, so they are here in this one

{
"services": [
{
"serviceId":"amp.local.subscription",
Copy link
Contributor

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".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"authorizationUrl": "/subscription/2/entitlements"
},
{
"serviceId":"google.subscription"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"subscribe.google.com"

Copy link
Member Author

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);
Copy link
Contributor

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

Copy link
Member Author

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]);
Copy link
Contributor

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.

Copy link
Member Author

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> */

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** @type {!PageConfig} */

Copy link
Member Author

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']) {
Copy link
Contributor

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') {...}

Copy link
Member Author

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'],
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Member Author

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_,{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space between "," and "{"

Copy link
Member Author

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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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',
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dvoytenko dvoytenko merged commit dfe14d5 into ampproject:master Feb 23, 2018
@prateekbh prateekbh deleted the amp-subscriptions-serviceconfig branch February 23, 2018 19:15
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants