-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
cid-impl.js
741 lines (676 loc) · 21.6 KB
/
cid-impl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
/**
* @fileoverview Provides per AMP document source origin and use case
* persistent client identifiers for use in analytics and similar use
* cases.
*
* For details, see https://goo.gl/Mwaacs
*/
import {tryResolve} from '#core/data-structures/promise';
import {isIframed} from '#core/dom';
import {rethrowAsync} from '#core/error';
import {parseJson, tryParseJson} from '#core/types/object/json';
import {base64UrlEncodeFromBytes} from '#core/types/string/base64';
import {getCryptoRandomBytesArray} from '#core/types/string/bytes';
import {Services} from '#service';
import {dev, user, userAssert} from '#utils/log';
import {CacheCidApi} from './cache-cid-api';
import {GoogleCidApi, TokenStatus_Enum} from './cid-api';
import {ViewerCidApi} from './viewer-cid-api';
import {getCookie, setCookie} from '../cookies';
import {
getServiceForDoc,
registerServiceBuilderForDoc,
} from '../service-helpers';
import {getSourceOrigin, isProxyOrigin, parseUrlDeprecated} from '../url';
const ONE_DAY_MILLIS = 24 * 3600 * 1000;
/**
* We ignore base cids that are older than (roughly) one year.
*/
export const BASE_CID_MAX_AGE_MILLIS = 365 * ONE_DAY_MILLIS;
const SCOPE_NAME_VALIDATOR = /^[a-zA-Z0-9-_.]+$/;
const CID_OPTOUT_STORAGE_KEY = 'amp-cid-optout';
const CID_OPTOUT_VIEWER_MESSAGE = 'cidOptOut';
const CID_BACKUP_STORAGE_KEY = 'amp-cid:';
/**
* Tag for debug logging.
* @const @private {string}
*/
const TAG_ = 'CID';
/**
* The name of the Google CID API as it appears in the meta tag to opt-in.
* @const @private {string}
*/
const GOOGLE_CID_API_META_NAME = 'amp-google-client-id-api';
/**
* The mapping from analytics providers to CID scopes.
* @const @private {{[key: string]: string}}
*/
const CID_API_SCOPE_ALLOWLIST = {
'googleanalytics': 'AMP_ECID_GOOGLE',
};
/**
* The mapping from analytics providers to their CID API service keys.
* @const @private {{[key: string]: string}}
*/
const API_KEYS = {
'googleanalytics': 'AIzaSyA65lEHUEizIsNtlbNo-l2K18dT680nsaM',
};
/**
* A base cid string value and the time it was last read / stored.
* @typedef {{time: time, cid: string}}
*/
let BaseCidInfoDef;
/**
* The "get CID" parameters.
* - createCookieIfNotPresent: Whether CID is allowed to create a cookie when.
* Default value is `false`.
* - cookieName: Name of the cookie to be used if defined for non-proxy case.
* - disableBackup: Whether CID should not be backed up in Storage.
* Default value is `false`.
* @typedef {{
* scope: string,
* createCookieIfNotPresent: (boolean|undefined),
* cookieName: (string|undefined),
* disableBackup: (boolean|undefined),
* }}
*/
let GetCidDef;
/**
* @interface
*/
export class CidDef {
/**
* @param {!GetCidDef} unusedGetCidStruct an object provides CID scope name for
* proxy case and cookie name for non-proxy case.
* @param {!Promise} unusedConsent Promise for when the user has given consent
* (if deemed necessary by the publisher) for use of the client
* identifier.
* @param {!Promise=} opt_persistenceConsent Dedicated promise for when
* it is OK to persist a new tracking identifier. This could be
* supplied ONLY by the code that supplies the actual consent
* cookie.
* If this is given, the consent param should be a resolved promise
* because this call should be only made in order to get consent.
* The consent promise passed to other calls should then itself
* depend on the opt_persistenceConsent promise (and the actual
* consent, of course).
* @return {!Promise<?string>} A client identifier that should be used
* within the current source origin and externalCidScope. Might be
* null if user has opted out of cid or no identifier was found
* or it could be made.
* This promise may take a long time to resolve if consent isn't
* given.
*/
get(unusedGetCidStruct, unusedConsent, opt_persistenceConsent) {}
/**
* User will be opted out of Cid issuance for all scopes.
* When opted-out Cid service will reject all `get` requests.
*
* @return {!Promise}
*/
optOut() {}
}
/**
* @implements {CidDef}
*/
class Cid {
/** @param {!./ampdoc-impl.AmpDoc} ampdoc */
constructor(ampdoc) {
/** @const */
this.ampdoc = ampdoc;
/**
* Cached base cid once read from storage to avoid repeated
* reads.
* @private {?Promise<string>}
* @restricted
*/
this.baseCid_ = null;
/**
* Cache to store external cids. Scope is used as the key and cookie value
* is the value.
* @private {!{[key: string]: !Promise<string>}}
* @restricted
*/
this.externalCidCache_ = Object.create(null);
/**
* @private @const {!CacheCidApi}
*/
this.cacheCidApi_ = new CacheCidApi(ampdoc);
/**
* @private {!ViewerCidApi}
*/
this.viewerCidApi_ = new ViewerCidApi(ampdoc);
this.cidApi_ = new GoogleCidApi(ampdoc);
/** @private {?{[key: string]: string}} */
this.apiKeyMap_ = null;
}
/** @override */
get(getCidStruct, consent, opt_persistenceConsent) {
userAssert(
SCOPE_NAME_VALIDATOR.test(getCidStruct.scope) &&
SCOPE_NAME_VALIDATOR.test(getCidStruct.cookieName),
'The CID scope and cookie name must only use the characters ' +
'[a-zA-Z0-9-_.]+\nInstead found: %s',
getCidStruct.scope
);
return consent
.then(() => {
return this.ampdoc.whenFirstVisible();
})
.then(() => {
// Check if user has globally opted out of CID, we do this after
// consent check since user can optout during consent process.
return isOptedOutOfCid(this.ampdoc);
})
.then((optedOut) => {
if (optedOut) {
return '';
}
const cidPromise = this.getExternalCid_(
getCidStruct,
opt_persistenceConsent || consent
);
// Getting the CID might involve an HTTP request. We timeout after 10s.
return Services.timerFor(this.ampdoc.win)
.timeoutPromise(
10000,
cidPromise,
`Getting cid for "${getCidStruct.scope}" timed out`
)
.catch((error) => {
rethrowAsync(error);
});
});
}
/** @override */
optOut() {
return optOutOfCid(this.ampdoc);
}
/**
* Returns the "external cid". This is a cid for a specific purpose
* (Say Analytics provider X). It is unique per user, userAssert, that purpose
* and the AMP origin site.
* @param {!GetCidDef} getCidStruct
* @param {!Promise} persistenceConsent
* @return {!Promise<?string>}
*/
getExternalCid_(getCidStruct, persistenceConsent) {
const {scope} = getCidStruct;
/** @const {!Location} */
const url = parseUrlDeprecated(this.ampdoc.win.location.href);
if (!isProxyOrigin(url)) {
const apiKey = this.isScopeOptedIn_(scope);
if (apiKey) {
return this.cidApi_.getScopedCid(apiKey, scope).then((scopedCid) => {
if (scopedCid == TokenStatus_Enum.OPT_OUT) {
return null;
}
if (scopedCid) {
const cookieName = getCidStruct.cookieName || scope;
setCidCookie(this.ampdoc.win, cookieName, scopedCid);
return scopedCid;
}
return getOrCreateCookie(this, getCidStruct, persistenceConsent);
});
}
return getOrCreateCookie(this, getCidStruct, persistenceConsent);
}
return this.viewerCidApi_.isSupported().then((supported) => {
if (supported) {
const apiKey = this.isScopeOptedIn_(scope);
return this.viewerCidApi_.getScopedCid(apiKey, scope);
}
if (this.cacheCidApi_.isSupported() && this.isScopeOptedIn_(scope)) {
return this.cacheCidApi_.getScopedCid(scope).then((scopedCid) => {
if (scopedCid) {
return scopedCid;
}
return this.scopeBaseCid_(persistenceConsent, scope, url);
});
}
return this.scopeBaseCid_(persistenceConsent, scope, url);
});
}
/**
*
* @param {!Promise} persistenceConsent
* @param {*} scope
* @param {!Location} url
* @return {*}
*/
scopeBaseCid_(persistenceConsent, scope, url) {
return getBaseCid(this, persistenceConsent).then((baseCid) => {
return Services.cryptoFor(this.ampdoc.win).sha384Base64(
baseCid + getProxySourceOrigin(url) + scope
);
});
}
/**
* Checks if the page has opted in CID API for the given scope.
* Returns the API key that should be used, or null if page hasn't opted in.
*
* @param {string} scope
* @return {string|undefined}
*/
isScopeOptedIn_(scope) {
if (!this.apiKeyMap_) {
this.apiKeyMap_ = this.getOptedInScopes_();
}
return this.apiKeyMap_[scope];
}
/**
* Reads meta tags for opted in scopes. Meta tags will have the form
* <meta name="provider-api-name" content="provider-name">
* @return {!{[key: string]: string}}
*/
getOptedInScopes_() {
const apiKeyMap = {};
const optInMeta = this.ampdoc.getMetaByName(GOOGLE_CID_API_META_NAME);
if (optInMeta) {
optInMeta.split(',').forEach((item) => {
item = item.trim();
if (item.indexOf('=') > 0) {
const pair = item.split('=');
const scope = pair[0].trim();
apiKeyMap[scope] = pair[1].trim();
} else {
const clientName = item;
const scope = CID_API_SCOPE_ALLOWLIST[clientName];
if (scope) {
apiKeyMap[scope] = API_KEYS[clientName];
} else {
user().warn(
TAG_,
`Unsupported client for Google CID API: ${clientName}.` +
`Please remove or correct meta[name="${GOOGLE_CID_API_META_NAME}"]`
);
}
}
});
}
return apiKeyMap;
}
}
/**
* User will be opted out of Cid issuance for all scopes.
* When opted-out Cid service will reject all `get` requests.
*
* @param {!./ampdoc-impl.AmpDoc} ampdoc
* @return {!Promise}
* @visibleForTesting
*/
export function optOutOfCid(ampdoc) {
// Tell the viewer that user has opted out.
Services.viewerForDoc(ampdoc)./*OK*/ sendMessage(
CID_OPTOUT_VIEWER_MESSAGE,
{}
);
// Store the optout bit in storage
return Services.storageForDoc(ampdoc).then((storage) => {
return storage.set(CID_OPTOUT_STORAGE_KEY, true);
});
}
/**
* Whether user has opted out of Cid issuance for all scopes.
*
* @param {!./ampdoc-impl.AmpDoc} ampdoc
* @return {!Promise<boolean>}
* @visibleForTesting
*/
export function isOptedOutOfCid(ampdoc) {
return Services.storageForDoc(ampdoc)
.then((storage) => {
return storage.get(CID_OPTOUT_STORAGE_KEY).then((val) => !!val);
})
.catch(() => {
// If we fail to read the flag, assume not opted out.
return false;
});
}
/**
* Sets a new CID cookie for expire 1 year from now.
* @param {!Window} win
* @param {string} scope
* @param {string} cookie
*/
function setCidCookie(win, scope, cookie) {
const expiration = Date.now() + BASE_CID_MAX_AGE_MILLIS;
setCookie(win, scope, cookie, expiration, {
highestAvailableDomain: true,
});
}
/**
* Sets a new CID backup in Storage
* @param {!./ampdoc-impl.AmpDoc} ampdoc
* @param {string} cookieName
* @param {string} cookie
*/
function setCidBackup(ampdoc, cookieName, cookie) {
Services.storageForDoc(ampdoc).then((storage) => {
const isViewerStorage = storage.isViewerStorage();
if (!isViewerStorage) {
const key = getStorageKey(cookieName);
storage.setNonBoolean(key, cookie);
}
});
}
/**
* @param {string} cookieName
* @return {string}
*/
function getStorageKey(cookieName) {
return CID_BACKUP_STORAGE_KEY + cookieName;
}
/**
* Maybe gets the CID from cookie or, if allowed, gets backup CID
* from Storage.
* @param {!Cid} cid
* @param {!GetCidDef} getCidStruct
* @return {!Promise<?string>}
*/
function maybeGetCidFromCookieOrBackup(cid, getCidStruct) {
const {ampdoc} = cid;
const {win} = ampdoc;
const {disableBackup, scope} = getCidStruct;
const cookieName = getCidStruct.cookieName || scope;
const existingCookie = getCookie(win, cookieName);
if (existingCookie) {
return Promise.resolve(existingCookie);
}
if (!disableBackup) {
return Services.storageForDoc(ampdoc)
.then((storage) => {
const key = getStorageKey(cookieName);
return storage.get(key, BASE_CID_MAX_AGE_MILLIS);
})
.then((backupCid) => {
if (!backupCid || typeof backupCid != 'string') {
return null;
}
return backupCid;
});
}
return Promise.resolve(null);
}
/**
* If cookie exists it's returned immediately. Otherwise, if instructed, the
* new cookie is created.
* @param {!Cid} cid
* @param {!GetCidDef} getCidStruct
* @param {!Promise} persistenceConsent
* @return {!Promise<?string>}
*/
function getOrCreateCookie(cid, getCidStruct, persistenceConsent) {
const {ampdoc} = cid;
const {win} = ampdoc;
const {disableBackup, scope} = getCidStruct;
const cookieName = getCidStruct.cookieName || scope;
return maybeGetCidFromCookieOrBackup(cid, getCidStruct).then(
(existingCookie) => {
if (!existingCookie && !getCidStruct.createCookieIfNotPresent) {
return /** @type {!Promise<?string>} */ (Promise.resolve(null));
}
if (existingCookie) {
// If we created the cookie, update it's expiration time.
if (/^amp-/.test(existingCookie)) {
setCidCookie(win, cookieName, existingCookie);
if (!disableBackup) {
setCidBackup(ampdoc, cookieName, existingCookie);
}
}
return /** @type {!Promise<?string>} */ (
Promise.resolve(existingCookie)
);
}
if (cid.externalCidCache_[scope]) {
return /** @type {!Promise<?string>} */ (cid.externalCidCache_[scope]);
}
const newCookiePromise = getRandomString64(win)
// Create new cookie, always prefixed with "amp-", so that we can see from
// the value whether we created it.
.then((randomStr) => 'amp-' + randomStr);
// Store it as a cookie based on the persistence consent.
Promise.all([newCookiePromise, persistenceConsent]).then((results) => {
// The initial CID generation is inherently racy. First one that gets
// consent wins.
const newCookie = results[0];
const relookup = getCookie(win, cookieName);
if (!relookup) {
setCidCookie(win, cookieName, newCookie);
if (!disableBackup) {
setCidBackup(ampdoc, cookieName, newCookie);
}
}
});
return (cid.externalCidCache_[scope] = newCookiePromise);
}
);
}
/**
* Returns the source origin of an AMP document for documents served
* on a proxy origin. Throws an error if the doc is not on a proxy origin.
* @param {!Location} url URL of an AMP document.
* @return {string} The source origin of the URL.
* @visibleForTesting BUT if this is needed elsewhere it could be
* factored into its own package.
*/
export function getProxySourceOrigin(url) {
userAssert(isProxyOrigin(url), 'Expected proxy origin %s', url.origin);
return getSourceOrigin(url);
}
/**
* Returns the base cid for the current user(). This string must not
* be exposed to users without hashing with the current source origin
* and the externalCidScope.
* On a proxy this value is the same for a user across all source
* origins.
* @param {!Cid} cid
* @param {!Promise} persistenceConsent
* @return {!Promise<string>}
*/
function getBaseCid(cid, persistenceConsent) {
if (cid.baseCid_) {
return cid.baseCid_;
}
const {win} = cid.ampdoc;
return (cid.baseCid_ = read(cid.ampdoc).then((stored) => {
let needsToStore = false;
let baseCid;
// See if we have a stored base cid and whether it is still valid
// in terms of expiration.
if (stored && !isExpired(stored)) {
baseCid = Promise.resolve(stored.cid);
if (shouldUpdateStoredTime(stored)) {
needsToStore = true;
}
} else {
// We need to make a new one.
baseCid = Services.cryptoFor(win).sha384Base64(getEntropy(win));
needsToStore = true;
}
if (needsToStore) {
baseCid.then((baseCid) => {
store(cid.ampdoc, persistenceConsent, baseCid);
});
}
return baseCid;
}));
}
/**
* Stores a new cidString in localStorage. Adds the current time to the
* stored value.
* @param {!./ampdoc-impl.AmpDoc} ampdoc
* @param {!Promise} persistenceConsent
* @param {string} cidString Actual cid string to store.
*/
function store(ampdoc, persistenceConsent, cidString) {
const {win} = ampdoc;
if (isIframed(win)) {
// If we are being embedded, try to save the base cid to the viewer.
viewerBaseCid(ampdoc, createCidData(cidString));
} else {
// To use local storage, we need user's consent.
persistenceConsent.then(() => {
try {
win.localStorage.setItem('amp-cid', createCidData(cidString));
} catch (ignore) {
// Setting localStorage may fail. In practice we don't expect that to
// happen a lot (since we don't go anywhere near the quota, but
// in particular in Safari private browsing mode it always fails.
// In that case we just don't store anything, which is just fine.
}
});
}
}
/**
* Get/set the Base CID from/to the viewer.
* @param {!./ampdoc-impl.AmpDoc} ampdoc
* @param {string=} opt_data Stringified JSON object {cid, time}.
* @return {!Promise<string|undefined>}
*/
export function viewerBaseCid(ampdoc, opt_data) {
const viewer = Services.viewerForDoc(ampdoc);
return viewer.isTrustedViewer().then((trusted) => {
if (!trusted) {
return undefined;
}
// TODO(lannka, #11060): clean up when all Viewers get migrated
dev().expectedError('CID', 'Viewer does not provide cap=cid');
return viewer.sendMessageAwaitResponse('cid', opt_data).then((data) => {
// For backward compatibility: #4029
if (data && !tryParseJson(data)) {
// TODO(lannka, #11060): clean up when all Viewers get migrated
dev().expectedError('CID', 'invalid cid format');
return JSON.stringify({
'time': Date.now(), // CID returned from old API is always fresh
'cid': data,
});
}
return data;
});
});
}
/**
* Creates a JSON object that contains the given CID and the current time as
* a timestamp.
* @param {string} cidString
* @return {string}
*/
function createCidData(cidString) {
return JSON.stringify({
'time': Date.now(),
'cid': cidString,
});
}
/**
* Gets the persisted CID data as a promise. It tries to read from
* localStorage first then from viewer if it is in embedded mode.
* Returns null if none was found.
* @param {!./ampdoc-impl.AmpDoc} ampdoc
* @return {!Promise<?BaseCidInfoDef>}
*/
function read(ampdoc) {
const {win} = ampdoc;
let data;
try {
data = win.localStorage.getItem('amp-cid');
} catch (ignore) {
// If reading from localStorage fails, we assume it is empty.
}
let dataPromise = Promise.resolve(data);
if (!data && isIframed(win)) {
// If we are being embedded, try to get the base cid from the viewer.
dataPromise = viewerBaseCid(ampdoc);
}
return dataPromise.then((data) => {
if (!data) {
return null;
}
const item = parseJson(data);
return {
time: item['time'],
cid: item['cid'],
};
});
}
/**
* Whether the retrieved cid object is expired and should be ignored.
* @param {!BaseCidInfoDef} storedCidInfo
* @return {boolean}
*/
function isExpired(storedCidInfo) {
const createdTime = storedCidInfo.time;
const now = Date.now();
return createdTime + BASE_CID_MAX_AGE_MILLIS < now;
}
/**
* Whether we should write a new timestamp to the stored cid value.
* We say yes if it is older than 1 day, so we only do this max once
* per day to avoid writing to localStorage all the time.
* @param {!BaseCidInfoDef} storedCidInfo
* @return {boolean}
*/
function shouldUpdateStoredTime(storedCidInfo) {
const createdTime = storedCidInfo.time;
const now = Date.now();
return createdTime + ONE_DAY_MILLIS < now;
}
/**
* Returns an array with a total of 128 of random values based on the
* `win.crypto.getRandomValues` API. If that is not available concatenates
* a string of other values that might be hard to guess including
* `Math.random` and the current time.
* @param {!Window} win
* @return {!Uint8Array|string} Entropy.
*/
function getEntropy(win) {
// Use win.crypto.getRandomValues to get 128 bits of random value
const uint8array = getCryptoRandomBytesArray(win, 16); // 128 bit
if (uint8array) {
return uint8array;
}
// Support for legacy browsers.
return String(
win.location.href +
Date.now() +
win.Math.random() +
win.screen.width +
win.screen.height
);
}
/**
* Produces an external CID for use in a cookie.
* @param {!Window} win
* @return {!Promise<string>} The cid
*/
export function getRandomString64(win) {
const entropy = getEntropy(win);
if (typeof entropy == 'string') {
return Services.cryptoFor(win).sha384Base64(entropy);
} else {
// If our entropy is a pure random number, we can just directly turn it
// into base 64
const cast = /** @type {!Uint8Array} */ (entropy);
return tryResolve(() =>
base64UrlEncodeFromBytes(cast)
// Remove trailing padding
.replace(/\.+$/, '')
);
}
}
/**
* @param {!./ampdoc-impl.AmpDoc} ampdoc
* @return {*} TODO(#23582): Specify return type
*/
export function installCidService(ampdoc) {
return registerServiceBuilderForDoc(ampdoc, 'cid', Cid);
}
/**
* @param {!./ampdoc-impl.AmpDoc} ampdoc
* @return {!Cid}
* @private visible for testing
*/
export function cidServiceForDocForTesting(ampdoc) {
registerServiceBuilderForDoc(ampdoc, 'cid', Cid);
return getServiceForDoc(ampdoc, 'cid');
}