@backstage/backend-plugin-api 0.2.0 → 0.2.1-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,8 @@
4
4
  * @packageDocumentation
5
5
  */
6
6
 
7
+ /// <reference types="node" />
8
+
7
9
  import { Config } from '@backstage/config';
8
10
  import { Handler } from 'express';
9
11
  import { Logger } from 'winston';
@@ -11,11 +13,10 @@ import { PermissionAuthorizer } from '@backstage/plugin-permission-common';
11
13
  import { PermissionEvaluator } from '@backstage/plugin-permission-common';
12
14
  import { PluginCacheManager } from '@backstage/backend-common';
13
15
  import { PluginDatabaseManager } from '@backstage/backend-common';
14
- import { PluginEndpointDiscovery } from '@backstage/backend-common';
15
16
  import { PluginTaskScheduler } from '@backstage/backend-tasks';
17
+ import { Readable } from 'stream';
16
18
  import { TokenManager } from '@backstage/backend-common';
17
19
  import { TransportStreamOptions } from 'winston-transport';
18
- import { UrlReader } from '@backstage/backend-common';
19
20
 
20
21
  /** @public */
21
22
  export declare interface BackendFeature {
@@ -79,6 +80,7 @@ declare namespace coreServices {
79
80
  tokenManagerServiceRef as tokenManager,
80
81
  permissionsServiceRef as permissions,
81
82
  schedulerServiceRef as scheduler,
83
+ rootLifecycleServiceRef as rootLifecycle,
82
84
  rootLoggerServiceRef as rootLogger,
83
85
  pluginMetadataServiceRef as pluginMetadata,
84
86
  lifecycleServiceRef as lifecycle
@@ -144,13 +146,57 @@ export declare type DatabaseService = PluginDatabaseManager;
144
146
  */
145
147
  declare const databaseServiceRef: ServiceRef<PluginDatabaseManager, "plugin">;
146
148
 
147
- /** @public */
148
- export declare type DiscoveryService = PluginEndpointDiscovery;
149
+ /**
150
+ * The DiscoveryService is used to provide a mechanism for backend
151
+ * plugins to discover the endpoints for itself or other backend plugins.
152
+ *
153
+ * The purpose of the discovery API is to allow for many different deployment
154
+ * setups and routing methods through a central configuration, instead
155
+ * of letting each individual plugin manage that configuration.
156
+ *
157
+ * Implementations of the discovery API can be as simple as a URL pattern
158
+ * using the pluginId, but could also have overrides for individual plugins,
159
+ * or query a separate discovery service.
160
+ *
161
+ * @public
162
+ */
163
+ export declare type DiscoveryService = {
164
+ /**
165
+ * Returns the internal HTTP base URL for a given plugin, without a trailing slash.
166
+ *
167
+ * The returned URL should point to an internal endpoint for the plugin, with
168
+ * the shortest route possible. The URL should be used for service-to-service
169
+ * communication within a Backstage backend deployment.
170
+ *
171
+ * This method must always be called just before making a request, as opposed to
172
+ * fetching the URL when constructing an API client. That is to ensure that more
173
+ * flexible routing patterns can be supported.
174
+ *
175
+ * For example, asking for the URL for `catalog` may return something
176
+ * like `http://10.1.2.3/api/catalog`
177
+ */
178
+ getBaseUrl(pluginId: string): Promise<string>;
179
+ /**
180
+ * Returns the external HTTP base backend URL for a given plugin, without a trailing slash.
181
+ *
182
+ * The returned URL should point to an external endpoint for the plugin, such that
183
+ * it is reachable from the Backstage frontend and other external services. The returned
184
+ * URL should be usable for example as a callback / webhook URL.
185
+ *
186
+ * The returned URL should be stable and in general not change unless other static
187
+ * or external configuration is changed. Changes should not come as a surprise
188
+ * to an operator of the Backstage backend.
189
+ *
190
+ * For example, asking for the URL for `catalog` may return something
191
+ * like `https://backstage.example.com/api/catalog`
192
+ */
193
+ getExternalBaseUrl(pluginId: string): Promise<string>;
194
+ };
149
195
 
150
196
  /**
151
197
  * @public
152
198
  */
153
- declare const discoveryServiceRef: ServiceRef<PluginEndpointDiscovery, "plugin">;
199
+ declare const discoveryServiceRef: ServiceRef<DiscoveryService, "plugin">;
154
200
 
155
201
  /**
156
202
  * TODO
@@ -200,6 +246,8 @@ declare const lifecycleServiceRef: ServiceRef<LifecycleService, "plugin">;
200
246
  **/
201
247
  export declare type LifecycleServiceShutdownHook = {
202
248
  fn: () => void | Promise<void>;
249
+ /** Labels to help identify the shutdown hook */
250
+ labels?: Record<string, string>;
203
251
  };
204
252
 
205
253
  /**
@@ -248,6 +296,187 @@ export declare interface PluginMetadataService {
248
296
  */
249
297
  declare const pluginMetadataServiceRef: ServiceRef<PluginMetadataService, "plugin">;
250
298
 
299
+ /**
300
+ * An options object for {@link UrlReaderService.readTree} operations.
301
+ *
302
+ * @public
303
+ */
304
+ export declare type ReadTreeOptions = {
305
+ /**
306
+ * A filter that can be used to select which files should be included.
307
+ *
308
+ * @remarks
309
+ *
310
+ * The path passed to the filter function is the relative path from the URL
311
+ * that the file tree is fetched from, without any leading '/'.
312
+ *
313
+ * For example, given the URL https://github.com/my/repo/tree/master/my-dir, a file
314
+ * at https://github.com/my/repo/blob/master/my-dir/my-subdir/my-file.txt will
315
+ * be represented as my-subdir/my-file.txt
316
+ *
317
+ * If no filter is provided, all files are extracted.
318
+ */
319
+ filter?(path: string, info?: {
320
+ size: number;
321
+ }): boolean;
322
+ /**
323
+ * An ETag which can be provided to check whether a
324
+ * {@link UrlReaderService.readTree} response has changed from a previous execution.
325
+ *
326
+ * @remarks
327
+ *
328
+ * In the {@link UrlReaderService.readTree} response, an ETag is returned along with
329
+ * the tree blob. The ETag is a unique identifier of the tree blob, usually
330
+ * the commit SHA or ETag from the target.
331
+ *
332
+ * When an ETag is given as a request option, {@link UrlReaderService.readTree} will
333
+ * first compare the ETag against the ETag on the target branch. If they
334
+ * match, {@link UrlReaderService.readTree} will throw a
335
+ * {@link @backstage/errors#NotModifiedError} indicating that the response
336
+ * will not differ from the previous response which included this particular
337
+ * ETag. If they do not match, {@link UrlReaderService.readTree} will return the
338
+ * rest of the response along with a new ETag.
339
+ */
340
+ etag?: string;
341
+ /**
342
+ * An abort signal to pass down to the underlying request.
343
+ *
344
+ * @remarks
345
+ *
346
+ * Not all reader implementations may take this field into account.
347
+ */
348
+ signal?: AbortSignal;
349
+ };
350
+
351
+ /**
352
+ * A response object for {@link UrlReaderService.readTree} operations.
353
+ *
354
+ * @public
355
+ */
356
+ export declare type ReadTreeResponse = {
357
+ /**
358
+ * Returns an array of all the files inside the tree, and corresponding
359
+ * functions to read their content.
360
+ */
361
+ files(): Promise<ReadTreeResponseFile[]>;
362
+ /**
363
+ * Returns the tree contents as a binary archive, using a stream.
364
+ */
365
+ archive(): Promise<NodeJS.ReadableStream>;
366
+ /**
367
+ * Extracts the tree response into a directory and returns the path of the
368
+ * directory.
369
+ *
370
+ * **NOTE**: It is the responsibility of the caller to remove the directory after use.
371
+ */
372
+ dir(options?: ReadTreeResponseDirOptions): Promise<string>;
373
+ /**
374
+ * Etag returned by content provider.
375
+ *
376
+ * @remarks
377
+ *
378
+ * Can be used to compare and cache responses when doing subsequent calls.
379
+ */
380
+ etag: string;
381
+ };
382
+
383
+ /**
384
+ * Options that control {@link ReadTreeResponse.dir} execution.
385
+ *
386
+ * @public
387
+ */
388
+ export declare type ReadTreeResponseDirOptions = {
389
+ /**
390
+ * The directory to write files to.
391
+ *
392
+ * @remarks
393
+ *
394
+ * Defaults to the OS tmpdir, or `backend.workingDirectory` if set in config.
395
+ */
396
+ targetDir?: string;
397
+ };
398
+
399
+ /**
400
+ * Represents a single file in a {@link UrlReaderService.readTree} response.
401
+ *
402
+ * @public
403
+ */
404
+ export declare type ReadTreeResponseFile = {
405
+ path: string;
406
+ content(): Promise<Buffer>;
407
+ };
408
+
409
+ /**
410
+ * An options object for readUrl operations.
411
+ *
412
+ * @public
413
+ */
414
+ export declare type ReadUrlOptions = {
415
+ /**
416
+ * An ETag which can be provided to check whether a
417
+ * {@link UrlReaderService.readUrl} response has changed from a previous execution.
418
+ *
419
+ * @remarks
420
+ *
421
+ * In the {@link UrlReaderService.readUrl} response, an ETag is returned along with
422
+ * the data. The ETag is a unique identifier of the data, usually the commit
423
+ * SHA or ETag from the target.
424
+ *
425
+ * When an ETag is given in ReadUrlOptions, {@link UrlReaderService.readUrl} will
426
+ * first compare the ETag against the ETag of the target. If they match,
427
+ * {@link UrlReaderService.readUrl} will throw a
428
+ * {@link @backstage/errors#NotModifiedError} indicating that the response
429
+ * will not differ from the previous response which included this particular
430
+ * ETag. If they do not match, {@link UrlReaderService.readUrl} will return the rest
431
+ * of the response along with a new ETag.
432
+ */
433
+ etag?: string;
434
+ /**
435
+ * An abort signal to pass down to the underlying request.
436
+ *
437
+ * @remarks
438
+ *
439
+ * Not all reader implementations may take this field into account.
440
+ */
441
+ signal?: AbortSignal;
442
+ };
443
+
444
+ /**
445
+ * A response object for {@link UrlReaderService.readUrl} operations.
446
+ *
447
+ * @public
448
+ */
449
+ export declare type ReadUrlResponse = {
450
+ /**
451
+ * Returns the data that was read from the remote URL.
452
+ */
453
+ buffer(): Promise<Buffer>;
454
+ /**
455
+ * Returns the data that was read from the remote URL as a Readable stream.
456
+ *
457
+ * @remarks
458
+ *
459
+ * This method will be required in a future release.
460
+ */
461
+ stream?(): Readable;
462
+ /**
463
+ * Etag returned by content provider.
464
+ *
465
+ * @remarks
466
+ *
467
+ * Can be used to compare and cache responses when doing subsequent calls.
468
+ */
469
+ etag?: string;
470
+ };
471
+
472
+ /** @public */
473
+ export declare type RootLifecycleService = LifecycleService;
474
+
475
+ /**
476
+ * @public
477
+ */
478
+ declare const rootLifecycleServiceRef: ServiceRef<LifecycleService, "root">;
479
+
251
480
  /** @public */
252
481
  export declare type RootLoggerService = LoggerService;
253
482
 
@@ -264,6 +493,66 @@ export declare type SchedulerService = PluginTaskScheduler;
264
493
  */
265
494
  declare const schedulerServiceRef: ServiceRef<PluginTaskScheduler, "plugin">;
266
495
 
496
+ /**
497
+ * An options object for search operations.
498
+ *
499
+ * @public
500
+ */
501
+ export declare type SearchOptions = {
502
+ /**
503
+ * An etag can be provided to check whether the search response has changed from a previous execution.
504
+ *
505
+ * In the search() response, an etag is returned along with the files. The etag is a unique identifier
506
+ * of the current tree, usually the commit SHA or etag from the target.
507
+ *
508
+ * When an etag is given in SearchOptions, search will first compare the etag against the etag
509
+ * on the target branch. If they match, search will throw a NotModifiedError indicating that the search
510
+ * response will not differ from the previous response which included this particular etag. If they mismatch,
511
+ * search will return the rest of SearchResponse along with a new etag.
512
+ */
513
+ etag?: string;
514
+ /**
515
+ * An abort signal to pass down to the underlying request.
516
+ *
517
+ * @remarks
518
+ *
519
+ * Not all reader implementations may take this field into account.
520
+ */
521
+ signal?: AbortSignal;
522
+ };
523
+
524
+ /**
525
+ * The output of a search operation.
526
+ *
527
+ * @public
528
+ */
529
+ export declare type SearchResponse = {
530
+ /**
531
+ * The files that matched the search query.
532
+ */
533
+ files: SearchResponseFile[];
534
+ /**
535
+ * A unique identifier of the current remote tree, usually the commit SHA or etag from the target.
536
+ */
537
+ etag: string;
538
+ };
539
+
540
+ /**
541
+ * Represents a single file in a search response.
542
+ *
543
+ * @public
544
+ */
545
+ export declare type SearchResponseFile = {
546
+ /**
547
+ * The full URL to the file.
548
+ */
549
+ url: string;
550
+ /**
551
+ * The binary contents of the file.
552
+ */
553
+ content(): Promise<Buffer>;
554
+ };
555
+
267
556
  /** @public */
268
557
  export declare type ServiceFactory<TService = unknown> = {
269
558
  scope: 'root';
@@ -335,12 +624,29 @@ export declare type TypesToServiceRef<T> = {
335
624
  [key in keyof T]: ServiceRef<T[key]>;
336
625
  };
337
626
 
338
- /** @public */
339
- export declare type UrlReaderService = UrlReader;
627
+ /**
628
+ * A generic interface for fetching plain data from URLs.
629
+ *
630
+ * @public
631
+ */
632
+ export declare type UrlReaderService = {
633
+ /**
634
+ * Reads a single file and return its content.
635
+ */
636
+ readUrl(url: string, options?: ReadUrlOptions): Promise<ReadUrlResponse>;
637
+ /**
638
+ * Reads a full or partial file tree.
639
+ */
640
+ readTree(url: string, options?: ReadTreeOptions): Promise<ReadTreeResponse>;
641
+ /**
642
+ * Searches for a file in a tree using a glob pattern.
643
+ */
644
+ search(url: string, options?: SearchOptions): Promise<SearchResponse>;
645
+ };
340
646
 
341
647
  /**
342
648
  * @public
343
649
  */
344
- declare const urlReaderServiceRef: ServiceRef<UrlReader, "plugin">;
650
+ declare const urlReaderServiceRef: ServiceRef<UrlReaderService, "plugin">;
345
651
 
346
652
  export { }
package/dist/index.cjs.js CHANGED
@@ -76,6 +76,11 @@ const schedulerServiceRef = createServiceRef({
76
76
  id: "core.scheduler"
77
77
  });
78
78
 
79
+ const rootLifecycleServiceRef = createServiceRef({
80
+ id: "core.rootLifecycle",
81
+ scope: "root"
82
+ });
83
+
79
84
  const rootLoggerServiceRef = createServiceRef({
80
85
  id: "core.root.logger",
81
86
  scope: "root"
@@ -104,6 +109,7 @@ var coreServices = /*#__PURE__*/Object.freeze({
104
109
  tokenManager: tokenManagerServiceRef,
105
110
  permissions: permissionsServiceRef,
106
111
  scheduler: schedulerServiceRef,
112
+ rootLifecycle: rootLifecycleServiceRef,
107
113
  rootLogger: rootLoggerServiceRef,
108
114
  pluginMetadata: pluginMetadataServiceRef,
109
115
  lifecycle: lifecycleServiceRef
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/services/system/types.ts","../src/services/definitions/configServiceRef.ts","../src/services/definitions/httpRouterServiceRef.ts","../src/services/definitions/loggerServiceRef.ts","../src/services/definitions/urlReaderServiceRef.ts","../src/services/definitions/cacheServiceRef.ts","../src/services/definitions/databaseServiceRef.ts","../src/services/definitions/discoveryServiceRef.ts","../src/services/definitions/tokenManagerServiceRef.ts","../src/services/definitions/permissionsServiceRef.ts","../src/services/definitions/schedulerServiceRef.ts","../src/services/definitions/rootLoggerServiceRef.ts","../src/services/definitions/pluginMetadataServiceRef.ts","../src/services/definitions/lifecycleServiceRef.ts","../src/services/helpers/loggerToWinstonLogger.ts","../src/wiring/factories.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * TODO\n *\n * @public\n */\nexport type ServiceRef<\n TService,\n TScope extends 'root' | 'plugin' = 'root' | 'plugin',\n> = {\n id: string;\n\n /**\n * This determines the scope at which this service is available.\n *\n * Root scoped services are available to all other services but\n * may only depend on other root scoped services.\n *\n * Plugin scoped services are only available to other plugin scoped\n * services but may depend on all other services.\n */\n scope: TScope;\n\n /**\n * Utility for getting the type of the service, using `typeof serviceRef.T`.\n * Attempting to actually read this value will result in an exception.\n */\n T: TService;\n\n toString(): string;\n\n $$ref: 'service';\n};\n\n/** @public */\nexport type TypesToServiceRef<T> = { [key in keyof T]: ServiceRef<T[key]> };\n\n/** @public */\nexport type ServiceFactory<TService = unknown> =\n | {\n // This scope prop is needed in addition to the service ref, as TypeScript\n // can't properly discriminate the two factory types otherwise.\n scope: 'root';\n service: ServiceRef<TService, 'root'>;\n deps: { [key in string]: ServiceRef<unknown> };\n factory(deps: { [key in string]: unknown }): Promise<TService>;\n }\n | {\n scope: 'plugin';\n service: ServiceRef<TService, 'plugin'>;\n deps: { [key in string]: ServiceRef<unknown> };\n factory(deps: { [key in string]: unknown }): Promise<\n (deps: { [key in string]: unknown }) => Promise<TService>\n >;\n };\n\n/** @public */\nexport function createServiceRef<T>(options: {\n id: string;\n scope?: 'plugin';\n defaultFactory?: (\n service: ServiceRef<T, 'plugin'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n}): ServiceRef<T, 'plugin'>;\n/** @public */\nexport function createServiceRef<T>(options: {\n id: string;\n scope: 'root';\n defaultFactory?: (\n service: ServiceRef<T, 'root'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n}): ServiceRef<T, 'root'>;\nexport function createServiceRef<T>(options: {\n id: string;\n scope?: 'plugin' | 'root';\n defaultFactory?:\n | ((\n service: ServiceRef<T, 'plugin'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>)\n | ((\n service: ServiceRef<T, 'root'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>);\n}): ServiceRef<T> {\n const { id, scope = 'plugin', defaultFactory } = options;\n return {\n id,\n scope,\n get T(): T {\n throw new Error(`tried to read ServiceRef.T of ${this}`);\n },\n toString() {\n return `serviceRef{${options.id}}`;\n },\n $$ref: 'service', // TODO: declare\n __defaultFactory: defaultFactory,\n } as ServiceRef<T, typeof scope> & {\n __defaultFactory?: (\n service: ServiceRef<T>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n };\n}\n\n/** @ignore */\ntype ServiceRefsToInstances<\n T extends { [key in string]: ServiceRef<unknown> },\n TScope extends 'root' | 'plugin' = 'root' | 'plugin',\n> = {\n [name in {\n [key in keyof T]: T[key] extends ServiceRef<unknown, TScope> ? key : never;\n }[keyof T]]: T[name] extends ServiceRef<infer TImpl> ? TImpl : never;\n};\n\n/**\n * @public\n */\nexport function createServiceFactory<\n TService,\n TScope extends 'root' | 'plugin',\n TImpl extends TService,\n TDeps extends { [name in string]: ServiceRef<unknown> },\n TOpts extends object | undefined = undefined,\n>(config: {\n service: ServiceRef<TService, TScope>;\n deps: TDeps;\n factory(\n deps: ServiceRefsToInstances<TDeps, 'root'>,\n options: TOpts,\n ): TScope extends 'root'\n ? Promise<TImpl>\n : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;\n}): undefined extends TOpts\n ? (options?: TOpts) => ServiceFactory<TService>\n : (options: TOpts) => ServiceFactory<TService> {\n return (options?: TOpts) =>\n ({\n scope: config.service.scope,\n service: config.service,\n deps: config.deps,\n factory(deps: ServiceRefsToInstances<TDeps, 'root'>) {\n return config.factory(deps, options!);\n },\n } as ServiceFactory<TService>);\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { createServiceRef } from '../system/types';\n\n/**\n * @public\n */\nexport type ConfigService = Config;\n\n/**\n * @public\n */\nexport const configServiceRef = createServiceRef<ConfigService>({\n id: 'core.root.config',\n scope: 'root',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { Handler } from 'express';\n\n/**\n * @public\n */\nexport interface HttpRouterService {\n use(handler: Handler): void;\n}\n\n/**\n * @public\n */\nexport const httpRouterServiceRef = createServiceRef<HttpRouterService>({\n id: 'core.httpRouter',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\n\n/**\n * @public\n */\nexport type LogMeta = { [name: string]: unknown };\n\n/**\n * @public\n */\nexport interface LoggerService {\n error(message: string, meta?: Error | LogMeta): void;\n warn(message: string, meta?: Error | LogMeta): void;\n info(message: string, meta?: Error | LogMeta): void;\n debug(message: string, meta?: Error | LogMeta): void;\n\n child(meta: LogMeta): LoggerService;\n}\n\n/**\n * @public\n */\nexport const loggerServiceRef = createServiceRef<LoggerService>({\n id: 'core.logger',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { UrlReader } from '@backstage/backend-common';\n\n/** @public */\nexport type UrlReaderService = UrlReader;\n\n/**\n * @public\n */\nexport const urlReaderServiceRef = createServiceRef<UrlReaderService>({\n id: 'core.urlReader',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { PluginCacheManager } from '@backstage/backend-common';\n\n/** @public */\nexport type CacheService = PluginCacheManager;\n\n/**\n * @public\n */\nexport const cacheServiceRef = createServiceRef<CacheService>({\n id: 'core.cache',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PluginDatabaseManager } from '@backstage/backend-common';\nimport { createServiceRef } from '../system/types';\n\n/** @public */\nexport type DatabaseService = PluginDatabaseManager;\n\n/**\n * @public\n */\nexport const databaseServiceRef = createServiceRef<DatabaseService>({\n id: 'core.database',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { PluginEndpointDiscovery } from '@backstage/backend-common';\n\n/** @public */\nexport type DiscoveryService = PluginEndpointDiscovery;\n\n/**\n * @public\n */\nexport const discoveryServiceRef = createServiceRef<DiscoveryService>({\n id: 'core.discovery',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { TokenManager } from '@backstage/backend-common';\n\n/** @public */\nexport type TokenManagerService = TokenManager;\n\n/**\n * @public\n */\nexport const tokenManagerServiceRef = createServiceRef<TokenManagerService>({\n id: 'core.tokenManager',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport {\n PermissionAuthorizer,\n PermissionEvaluator,\n} from '@backstage/plugin-permission-common';\n\n/** @public */\nexport type PermissionsService = PermissionEvaluator | PermissionAuthorizer;\n\n/**\n * @public\n */\nexport const permissionsServiceRef = createServiceRef<PermissionsService>({\n id: 'core.permissions',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { PluginTaskScheduler } from '@backstage/backend-tasks';\n\n/** @public */\nexport type SchedulerService = PluginTaskScheduler;\n\n/**\n * @public\n */\nexport const schedulerServiceRef = createServiceRef<SchedulerService>({\n id: 'core.scheduler',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { LoggerService } from './loggerServiceRef';\n\n/** @public */\nexport type RootLoggerService = LoggerService;\n\n/**\n * @public\n */\nexport const rootLoggerServiceRef = createServiceRef<RootLoggerService>({\n id: 'core.root.logger',\n scope: 'root',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\n\n/**\n * @public\n */\nexport interface PluginMetadataService {\n getId(): string;\n}\n\n/**\n * @public\n */\nexport const pluginMetadataServiceRef = createServiceRef<PluginMetadataService>(\n {\n id: 'core.plugin-metadata',\n },\n);\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\n\n/**\n * @public\n **/\nexport type LifecycleServiceShutdownHook = {\n fn: () => void | Promise<void>;\n};\n\n/**\n * @public\n **/\nexport interface LifecycleService {\n /**\n * Register a function to be called when the backend is shutting down.\n */\n addShutdownHook(options: LifecycleServiceShutdownHook): void;\n}\n\n/**\n * @public\n */\nexport const lifecycleServiceRef = createServiceRef<LifecycleService>({\n id: 'core.lifecycle',\n scope: 'plugin',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerService } from '../definitions';\nimport { Logger as WinstonLogger, createLogger } from 'winston';\nimport Transport, { TransportStreamOptions } from 'winston-transport';\n\nclass BackstageLoggerTransport extends Transport {\n constructor(\n private readonly backstageLogger: LoggerService,\n opts?: TransportStreamOptions,\n ) {\n super(opts);\n }\n\n log(info: unknown, callback: VoidFunction) {\n if (typeof info !== 'object' || info === null) {\n callback();\n return;\n }\n const { level, message, ...meta } = info as { [name: string]: unknown };\n switch (level) {\n case 'error':\n this.backstageLogger.error(String(message), meta);\n break;\n case 'warn':\n this.backstageLogger.warn(String(message), meta);\n break;\n case 'info':\n this.backstageLogger.info(String(message), meta);\n break;\n case 'debug':\n this.backstageLogger.debug(String(message), meta);\n break;\n default:\n this.backstageLogger.info(String(message), meta);\n }\n callback();\n }\n}\n\n/** @public */\nexport function loggerToWinstonLogger(\n logger: LoggerService,\n opts?: TransportStreamOptions,\n): WinstonLogger {\n return createLogger({\n transports: [new BackstageLoggerTransport(logger, opts)],\n });\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n BackendRegistrationPoints,\n BackendFeature,\n ExtensionPoint,\n} from './types';\n\n/** @public */\nexport function createExtensionPoint<T>(options: {\n id: string;\n}): ExtensionPoint<T> {\n return {\n id: options.id,\n get T(): T {\n throw new Error(`tried to read ExtensionPoint.T of ${this}`);\n },\n toString() {\n return `extensionPoint{${options.id}}`;\n },\n $$ref: 'extension-point', // TODO: declare\n };\n}\n\n/** @public */\nexport interface BackendPluginConfig<TOptions> {\n id: string;\n register(reg: BackendRegistrationPoints, options: TOptions): void;\n}\n\n/** @public */\nexport function createBackendPlugin<\n TOptions extends object | undefined = undefined,\n>(config: {\n id: string;\n register(reg: BackendRegistrationPoints, options: TOptions): void;\n}): undefined extends TOptions\n ? (options?: TOptions) => BackendFeature\n : (options: TOptions) => BackendFeature {\n return (options?: TOptions) => ({\n id: config.id,\n register(register: BackendRegistrationPoints) {\n return config.register(register, options!);\n },\n });\n}\n\n/** @public */\nexport interface BackendModuleConfig<TOptions> {\n pluginId: string;\n moduleId: string;\n register(\n reg: Omit<BackendRegistrationPoints, 'registerExtensionPoint'>,\n options: TOptions,\n ): void;\n}\n\n/**\n * @public\n *\n * Creates a new backend module for a given plugin.\n *\n * The `moduleId` should be equal to the module-specific prefix of the exported name, such\n * that the full name is `moduleId + PluginId + \"Module\"`. For example, a GitHub entity\n * provider module for the `catalog` plugin might have the module ID `'githubEntityProvider'`,\n * and the full exported name would be `githubEntityProviderCatalogModule`.\n *\n * The `pluginId` should exactly match the `id` of the plugin that the module extends.\n */\nexport function createBackendModule<\n TOptions extends object | undefined = undefined,\n>(\n config: BackendModuleConfig<TOptions>,\n): undefined extends TOptions\n ? (options?: TOptions) => BackendFeature\n : (options: TOptions) => BackendFeature {\n return (options?: TOptions) => ({\n id: `${config.pluginId}.${config.moduleId}`,\n register(register: BackendRegistrationPoints) {\n // TODO: Hide registerExtensionPoint\n return config.register(register, options!);\n },\n });\n}\n"],"names":["Transport","createLogger"],"mappings":";;;;;;;;;;;AAuFO,SAAS,iBAAoB,OAUlB,EAAA;AAChB,EAAA,MAAM,EAAE,EAAA,EAAI,KAAQ,GAAA,QAAA,EAAU,gBAAmB,GAAA,OAAA,CAAA;AACjD,EAAO,OAAA;AAAA,IACL,EAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAI,CAAO,GAAA;AACT,MAAM,MAAA,IAAI,KAAM,CAAA,CAAA,8BAAA,EAAiC,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AQ,CAAA,CAAA;AAAA,KAC3C;AAAA,GACF,CAAA,CAAA;AACF,CAAA;AAwBO,SAAS,oBAGd,MAGwC,EAAA;AACxC,EAAA,OAAO,CAAC,OAAwB,MAAA;AAAA,IAC9B,EAAI,EAAA,CAAA,EAAG,MAAO,CAAA,QAAA,CAAA,CAAA,EAAY,MAAO,CAAA,QAAA,CAAA,CAAA;AAAA,IACjC,SAAS,QAAqC,EAAA;AAE5C,MAAO,OAAA,MAAA,CAAO,QAAS,CAAA,QAAA,EAAU,OAAQ,CAAA,CAAA;AAAA,KAC3C;AAAA,GACF,CAAA,CAAA;AACF;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/services/system/types.ts","../src/services/definitions/configServiceRef.ts","../src/services/definitions/httpRouterServiceRef.ts","../src/services/definitions/loggerServiceRef.ts","../src/services/definitions/urlReaderServiceRef.ts","../src/services/definitions/cacheServiceRef.ts","../src/services/definitions/databaseServiceRef.ts","../src/services/definitions/discoveryServiceRef.ts","../src/services/definitions/tokenManagerServiceRef.ts","../src/services/definitions/permissionsServiceRef.ts","../src/services/definitions/schedulerServiceRef.ts","../src/services/definitions/rootLifecycleServiceRef.ts","../src/services/definitions/rootLoggerServiceRef.ts","../src/services/definitions/pluginMetadataServiceRef.ts","../src/services/definitions/lifecycleServiceRef.ts","../src/services/helpers/loggerToWinstonLogger.ts","../src/wiring/factories.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * TODO\n *\n * @public\n */\nexport type ServiceRef<\n TService,\n TScope extends 'root' | 'plugin' = 'root' | 'plugin',\n> = {\n id: string;\n\n /**\n * This determines the scope at which this service is available.\n *\n * Root scoped services are available to all other services but\n * may only depend on other root scoped services.\n *\n * Plugin scoped services are only available to other plugin scoped\n * services but may depend on all other services.\n */\n scope: TScope;\n\n /**\n * Utility for getting the type of the service, using `typeof serviceRef.T`.\n * Attempting to actually read this value will result in an exception.\n */\n T: TService;\n\n toString(): string;\n\n $$ref: 'service';\n};\n\n/** @public */\nexport type TypesToServiceRef<T> = { [key in keyof T]: ServiceRef<T[key]> };\n\n/** @public */\nexport type ServiceFactory<TService = unknown> =\n | {\n // This scope prop is needed in addition to the service ref, as TypeScript\n // can't properly discriminate the two factory types otherwise.\n scope: 'root';\n service: ServiceRef<TService, 'root'>;\n deps: { [key in string]: ServiceRef<unknown> };\n factory(deps: { [key in string]: unknown }): Promise<TService>;\n }\n | {\n scope: 'plugin';\n service: ServiceRef<TService, 'plugin'>;\n deps: { [key in string]: ServiceRef<unknown> };\n factory(deps: { [key in string]: unknown }): Promise<\n (deps: { [key in string]: unknown }) => Promise<TService>\n >;\n };\n\n/** @public */\nexport function createServiceRef<T>(options: {\n id: string;\n scope?: 'plugin';\n defaultFactory?: (\n service: ServiceRef<T, 'plugin'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n}): ServiceRef<T, 'plugin'>;\n/** @public */\nexport function createServiceRef<T>(options: {\n id: string;\n scope: 'root';\n defaultFactory?: (\n service: ServiceRef<T, 'root'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n}): ServiceRef<T, 'root'>;\nexport function createServiceRef<T>(options: {\n id: string;\n scope?: 'plugin' | 'root';\n defaultFactory?:\n | ((\n service: ServiceRef<T, 'plugin'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>)\n | ((\n service: ServiceRef<T, 'root'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>);\n}): ServiceRef<T> {\n const { id, scope = 'plugin', defaultFactory } = options;\n return {\n id,\n scope,\n get T(): T {\n throw new Error(`tried to read ServiceRef.T of ${this}`);\n },\n toString() {\n return `serviceRef{${options.id}}`;\n },\n $$ref: 'service', // TODO: declare\n __defaultFactory: defaultFactory,\n } as ServiceRef<T, typeof scope> & {\n __defaultFactory?: (\n service: ServiceRef<T>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n };\n}\n\n/** @ignore */\ntype ServiceRefsToInstances<\n T extends { [key in string]: ServiceRef<unknown> },\n TScope extends 'root' | 'plugin' = 'root' | 'plugin',\n> = {\n [name in {\n [key in keyof T]: T[key] extends ServiceRef<unknown, TScope> ? key : never;\n }[keyof T]]: T[name] extends ServiceRef<infer TImpl> ? TImpl : never;\n};\n\n/**\n * @public\n */\nexport function createServiceFactory<\n TService,\n TScope extends 'root' | 'plugin',\n TImpl extends TService,\n TDeps extends { [name in string]: ServiceRef<unknown> },\n TOpts extends object | undefined = undefined,\n>(config: {\n service: ServiceRef<TService, TScope>;\n deps: TDeps;\n factory(\n deps: ServiceRefsToInstances<TDeps, 'root'>,\n options: TOpts,\n ): TScope extends 'root'\n ? Promise<TImpl>\n : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;\n}): undefined extends TOpts\n ? (options?: TOpts) => ServiceFactory<TService>\n : (options: TOpts) => ServiceFactory<TService> {\n return (options?: TOpts) =>\n ({\n scope: config.service.scope,\n service: config.service,\n deps: config.deps,\n factory(deps: ServiceRefsToInstances<TDeps, 'root'>) {\n return config.factory(deps, options!);\n },\n } as ServiceFactory<TService>);\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { createServiceRef } from '../system/types';\n\n/**\n * @public\n */\nexport type ConfigService = Config;\n\n/**\n * @public\n */\nexport const configServiceRef = createServiceRef<ConfigService>({\n id: 'core.root.config',\n scope: 'root',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { Handler } from 'express';\n\n/**\n * @public\n */\nexport interface HttpRouterService {\n use(handler: Handler): void;\n}\n\n/**\n * @public\n */\nexport const httpRouterServiceRef = createServiceRef<HttpRouterService>({\n id: 'core.httpRouter',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\n\n/**\n * @public\n */\nexport type LogMeta = { [name: string]: unknown };\n\n/**\n * @public\n */\nexport interface LoggerService {\n error(message: string, meta?: Error | LogMeta): void;\n warn(message: string, meta?: Error | LogMeta): void;\n info(message: string, meta?: Error | LogMeta): void;\n debug(message: string, meta?: Error | LogMeta): void;\n\n child(meta: LogMeta): LoggerService;\n}\n\n/**\n * @public\n */\nexport const loggerServiceRef = createServiceRef<LoggerService>({\n id: 'core.logger',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { Readable } from 'stream';\n\n/**\n * A generic interface for fetching plain data from URLs.\n *\n * @public\n */\nexport type UrlReaderService = {\n /**\n * Reads a single file and return its content.\n */\n readUrl(url: string, options?: ReadUrlOptions): Promise<ReadUrlResponse>;\n\n /**\n * Reads a full or partial file tree.\n */\n readTree(url: string, options?: ReadTreeOptions): Promise<ReadTreeResponse>;\n\n /**\n * Searches for a file in a tree using a glob pattern.\n */\n search(url: string, options?: SearchOptions): Promise<SearchResponse>;\n};\n\n/**\n * An options object for readUrl operations.\n *\n * @public\n */\nexport type ReadUrlOptions = {\n /**\n * An ETag which can be provided to check whether a\n * {@link UrlReaderService.readUrl} response has changed from a previous execution.\n *\n * @remarks\n *\n * In the {@link UrlReaderService.readUrl} response, an ETag is returned along with\n * the data. The ETag is a unique identifier of the data, usually the commit\n * SHA or ETag from the target.\n *\n * When an ETag is given in ReadUrlOptions, {@link UrlReaderService.readUrl} will\n * first compare the ETag against the ETag of the target. If they match,\n * {@link UrlReaderService.readUrl} will throw a\n * {@link @backstage/errors#NotModifiedError} indicating that the response\n * will not differ from the previous response which included this particular\n * ETag. If they do not match, {@link UrlReaderService.readUrl} will return the rest\n * of the response along with a new ETag.\n */\n etag?: string;\n\n /**\n * An abort signal to pass down to the underlying request.\n *\n * @remarks\n *\n * Not all reader implementations may take this field into account.\n */\n signal?: AbortSignal;\n};\n\n/**\n * A response object for {@link UrlReaderService.readUrl} operations.\n *\n * @public\n */\nexport type ReadUrlResponse = {\n /**\n * Returns the data that was read from the remote URL.\n */\n buffer(): Promise<Buffer>;\n\n /**\n * Returns the data that was read from the remote URL as a Readable stream.\n *\n * @remarks\n *\n * This method will be required in a future release.\n */\n stream?(): Readable;\n\n /**\n * Etag returned by content provider.\n *\n * @remarks\n *\n * Can be used to compare and cache responses when doing subsequent calls.\n */\n etag?: string;\n};\n\n/**\n * An options object for {@link UrlReaderService.readTree} operations.\n *\n * @public\n */\nexport type ReadTreeOptions = {\n /**\n * A filter that can be used to select which files should be included.\n *\n * @remarks\n *\n * The path passed to the filter function is the relative path from the URL\n * that the file tree is fetched from, without any leading '/'.\n *\n * For example, given the URL https://github.com/my/repo/tree/master/my-dir, a file\n * at https://github.com/my/repo/blob/master/my-dir/my-subdir/my-file.txt will\n * be represented as my-subdir/my-file.txt\n *\n * If no filter is provided, all files are extracted.\n */\n filter?(path: string, info?: { size: number }): boolean;\n\n /**\n * An ETag which can be provided to check whether a\n * {@link UrlReaderService.readTree} response has changed from a previous execution.\n *\n * @remarks\n *\n * In the {@link UrlReaderService.readTree} response, an ETag is returned along with\n * the tree blob. The ETag is a unique identifier of the tree blob, usually\n * the commit SHA or ETag from the target.\n *\n * When an ETag is given as a request option, {@link UrlReaderService.readTree} will\n * first compare the ETag against the ETag on the target branch. If they\n * match, {@link UrlReaderService.readTree} will throw a\n * {@link @backstage/errors#NotModifiedError} indicating that the response\n * will not differ from the previous response which included this particular\n * ETag. If they do not match, {@link UrlReaderService.readTree} will return the\n * rest of the response along with a new ETag.\n */\n etag?: string;\n\n /**\n * An abort signal to pass down to the underlying request.\n *\n * @remarks\n *\n * Not all reader implementations may take this field into account.\n */\n signal?: AbortSignal;\n};\n\n/**\n * Options that control {@link ReadTreeResponse.dir} execution.\n *\n * @public\n */\nexport type ReadTreeResponseDirOptions = {\n /**\n * The directory to write files to.\n *\n * @remarks\n *\n * Defaults to the OS tmpdir, or `backend.workingDirectory` if set in config.\n */\n targetDir?: string;\n};\n\n/**\n * A response object for {@link UrlReaderService.readTree} operations.\n *\n * @public\n */\nexport type ReadTreeResponse = {\n /**\n * Returns an array of all the files inside the tree, and corresponding\n * functions to read their content.\n */\n files(): Promise<ReadTreeResponseFile[]>;\n\n /**\n * Returns the tree contents as a binary archive, using a stream.\n */\n archive(): Promise<NodeJS.ReadableStream>;\n\n /**\n * Extracts the tree response into a directory and returns the path of the\n * directory.\n *\n * **NOTE**: It is the responsibility of the caller to remove the directory after use.\n */\n dir(options?: ReadTreeResponseDirOptions): Promise<string>;\n\n /**\n * Etag returned by content provider.\n *\n * @remarks\n *\n * Can be used to compare and cache responses when doing subsequent calls.\n */\n etag: string;\n};\n\n/**\n * Represents a single file in a {@link UrlReaderService.readTree} response.\n *\n * @public\n */\nexport type ReadTreeResponseFile = {\n path: string;\n content(): Promise<Buffer>;\n};\n\n/**\n * An options object for search operations.\n *\n * @public\n */\nexport type SearchOptions = {\n /**\n * An etag can be provided to check whether the search response has changed from a previous execution.\n *\n * In the search() response, an etag is returned along with the files. The etag is a unique identifier\n * of the current tree, usually the commit SHA or etag from the target.\n *\n * When an etag is given in SearchOptions, search will first compare the etag against the etag\n * on the target branch. If they match, search will throw a NotModifiedError indicating that the search\n * response will not differ from the previous response which included this particular etag. If they mismatch,\n * search will return the rest of SearchResponse along with a new etag.\n */\n etag?: string;\n\n /**\n * An abort signal to pass down to the underlying request.\n *\n * @remarks\n *\n * Not all reader implementations may take this field into account.\n */\n signal?: AbortSignal;\n};\n\n/**\n * The output of a search operation.\n *\n * @public\n */\nexport type SearchResponse = {\n /**\n * The files that matched the search query.\n */\n files: SearchResponseFile[];\n\n /**\n * A unique identifier of the current remote tree, usually the commit SHA or etag from the target.\n */\n etag: string;\n};\n\n/**\n * Represents a single file in a search response.\n *\n * @public\n */\nexport type SearchResponseFile = {\n /**\n * The full URL to the file.\n */\n url: string;\n\n /**\n * The binary contents of the file.\n */\n content(): Promise<Buffer>;\n};\n\n/**\n * @public\n */\nexport const urlReaderServiceRef = createServiceRef<UrlReaderService>({\n id: 'core.urlReader',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { PluginCacheManager } from '@backstage/backend-common';\n\n/** @public */\nexport type CacheService = PluginCacheManager;\n\n/**\n * @public\n */\nexport const cacheServiceRef = createServiceRef<CacheService>({\n id: 'core.cache',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PluginDatabaseManager } from '@backstage/backend-common';\nimport { createServiceRef } from '../system/types';\n\n/** @public */\nexport type DatabaseService = PluginDatabaseManager;\n\n/**\n * @public\n */\nexport const databaseServiceRef = createServiceRef<DatabaseService>({\n id: 'core.database',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\n\n/**\n * The DiscoveryService is used to provide a mechanism for backend\n * plugins to discover the endpoints for itself or other backend plugins.\n *\n * The purpose of the discovery API is to allow for many different deployment\n * setups and routing methods through a central configuration, instead\n * of letting each individual plugin manage that configuration.\n *\n * Implementations of the discovery API can be as simple as a URL pattern\n * using the pluginId, but could also have overrides for individual plugins,\n * or query a separate discovery service.\n *\n * @public\n */\nexport type DiscoveryService = {\n /**\n * Returns the internal HTTP base URL for a given plugin, without a trailing slash.\n *\n * The returned URL should point to an internal endpoint for the plugin, with\n * the shortest route possible. The URL should be used for service-to-service\n * communication within a Backstage backend deployment.\n *\n * This method must always be called just before making a request, as opposed to\n * fetching the URL when constructing an API client. That is to ensure that more\n * flexible routing patterns can be supported.\n *\n * For example, asking for the URL for `catalog` may return something\n * like `http://10.1.2.3/api/catalog`\n */\n getBaseUrl(pluginId: string): Promise<string>;\n\n /**\n * Returns the external HTTP base backend URL for a given plugin, without a trailing slash.\n *\n * The returned URL should point to an external endpoint for the plugin, such that\n * it is reachable from the Backstage frontend and other external services. The returned\n * URL should be usable for example as a callback / webhook URL.\n *\n * The returned URL should be stable and in general not change unless other static\n * or external configuration is changed. Changes should not come as a surprise\n * to an operator of the Backstage backend.\n *\n * For example, asking for the URL for `catalog` may return something\n * like `https://backstage.example.com/api/catalog`\n */\n getExternalBaseUrl(pluginId: string): Promise<string>;\n};\n\n/**\n * @public\n */\nexport const discoveryServiceRef = createServiceRef<DiscoveryService>({\n id: 'core.discovery',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { TokenManager } from '@backstage/backend-common';\n\n/** @public */\nexport type TokenManagerService = TokenManager;\n\n/**\n * @public\n */\nexport const tokenManagerServiceRef = createServiceRef<TokenManagerService>({\n id: 'core.tokenManager',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport {\n PermissionAuthorizer,\n PermissionEvaluator,\n} from '@backstage/plugin-permission-common';\n\n/** @public */\nexport type PermissionsService = PermissionEvaluator | PermissionAuthorizer;\n\n/**\n * @public\n */\nexport const permissionsServiceRef = createServiceRef<PermissionsService>({\n id: 'core.permissions',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { PluginTaskScheduler } from '@backstage/backend-tasks';\n\n/** @public */\nexport type SchedulerService = PluginTaskScheduler;\n\n/**\n * @public\n */\nexport const schedulerServiceRef = createServiceRef<SchedulerService>({\n id: 'core.scheduler',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { LifecycleService } from './lifecycleServiceRef';\n\n/** @public */\nexport type RootLifecycleService = LifecycleService;\n\n/**\n * @public\n */\nexport const rootLifecycleServiceRef = createServiceRef<RootLifecycleService>({\n id: 'core.rootLifecycle',\n scope: 'root',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\nimport { LoggerService } from './loggerServiceRef';\n\n/** @public */\nexport type RootLoggerService = LoggerService;\n\n/**\n * @public\n */\nexport const rootLoggerServiceRef = createServiceRef<RootLoggerService>({\n id: 'core.root.logger',\n scope: 'root',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\n\n/**\n * @public\n */\nexport interface PluginMetadataService {\n getId(): string;\n}\n\n/**\n * @public\n */\nexport const pluginMetadataServiceRef = createServiceRef<PluginMetadataService>(\n {\n id: 'core.plugin-metadata',\n },\n);\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system/types';\n\n/**\n * @public\n **/\nexport type LifecycleServiceShutdownHook = {\n fn: () => void | Promise<void>;\n\n /** Labels to help identify the shutdown hook */\n labels?: Record<string, string>;\n};\n\n/**\n * @public\n **/\nexport interface LifecycleService {\n /**\n * Register a function to be called when the backend is shutting down.\n */\n addShutdownHook(options: LifecycleServiceShutdownHook): void;\n}\n\n/**\n * @public\n */\nexport const lifecycleServiceRef = createServiceRef<LifecycleService>({\n id: 'core.lifecycle',\n scope: 'plugin',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerService } from '../definitions';\nimport { Logger as WinstonLogger, createLogger } from 'winston';\nimport Transport, { TransportStreamOptions } from 'winston-transport';\n\nclass BackstageLoggerTransport extends Transport {\n constructor(\n private readonly backstageLogger: LoggerService,\n opts?: TransportStreamOptions,\n ) {\n super(opts);\n }\n\n log(info: unknown, callback: VoidFunction) {\n if (typeof info !== 'object' || info === null) {\n callback();\n return;\n }\n const { level, message, ...meta } = info as { [name: string]: unknown };\n switch (level) {\n case 'error':\n this.backstageLogger.error(String(message), meta);\n break;\n case 'warn':\n this.backstageLogger.warn(String(message), meta);\n break;\n case 'info':\n this.backstageLogger.info(String(message), meta);\n break;\n case 'debug':\n this.backstageLogger.debug(String(message), meta);\n break;\n default:\n this.backstageLogger.info(String(message), meta);\n }\n callback();\n }\n}\n\n/** @public */\nexport function loggerToWinstonLogger(\n logger: LoggerService,\n opts?: TransportStreamOptions,\n): WinstonLogger {\n return createLogger({\n transports: [new BackstageLoggerTransport(logger, opts)],\n });\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n BackendRegistrationPoints,\n BackendFeature,\n ExtensionPoint,\n} from './types';\n\n/** @public */\nexport function createExtensionPoint<T>(options: {\n id: string;\n}): ExtensionPoint<T> {\n return {\n id: options.id,\n get T(): T {\n throw new Error(`tried to read ExtensionPoint.T of ${this}`);\n },\n toString() {\n return `extensionPoint{${options.id}}`;\n },\n $$ref: 'extension-point', // TODO: declare\n };\n}\n\n/** @public */\nexport interface BackendPluginConfig<TOptions> {\n id: string;\n register(reg: BackendRegistrationPoints, options: TOptions): void;\n}\n\n/** @public */\nexport function createBackendPlugin<\n TOptions extends object | undefined = undefined,\n>(config: {\n id: string;\n register(reg: BackendRegistrationPoints, options: TOptions): void;\n}): undefined extends TOptions\n ? (options?: TOptions) => BackendFeature\n : (options: TOptions) => BackendFeature {\n return (options?: TOptions) => ({\n id: config.id,\n register(register: BackendRegistrationPoints) {\n return config.register(register, options!);\n },\n });\n}\n\n/** @public */\nexport interface BackendModuleConfig<TOptions> {\n pluginId: string;\n moduleId: string;\n register(\n reg: Omit<BackendRegistrationPoints, 'registerExtensionPoint'>,\n options: TOptions,\n ): void;\n}\n\n/**\n * @public\n *\n * Creates a new backend module for a given plugin.\n *\n * The `moduleId` should be equal to the module-specific prefix of the exported name, such\n * that the full name is `moduleId + PluginId + \"Module\"`. For example, a GitHub entity\n * provider module for the `catalog` plugin might have the module ID `'githubEntityProvider'`,\n * and the full exported name would be `githubEntityProviderCatalogModule`.\n *\n * The `pluginId` should exactly match the `id` of the plugin that the module extends.\n */\nexport function createBackendModule<\n TOptions extends object | undefined = undefined,\n>(\n config: BackendModuleConfig<TOptions>,\n): undefined extends TOptions\n ? (options?: TOptions) => BackendFeature\n : (options: TOptions) => BackendFeature {\n return (options?: TOptions) => ({\n id: `${config.pluginId}.${config.moduleId}`,\n register(register: BackendRegistrationPoints) {\n // TODO: Hide registerExtensionPoint\n return config.register(register, options!);\n },\n });\n}\n"],"names":["Transport","createLogger"],"mappings":";;;;;;;;;;;AAuFO,SAAS,iBAAoB,OAUlB,EAAA;AAChB,EAAA,MAAM,EAAE,EAAA,EAAI,KAAQ,GAAA,QAAA,EAAU,gBAAmB,GAAA,OAAA,CAAA;AACjD,EAAO,OAAA;AAAA,IACL,EAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAI,CAAO,GAAA;AACT,MAAM,MAAA,IAAI,KAAM,CAAA,CAAA,8BAAA,EAAiC,IAAM,CAAA,CAAA,CAAA,CAAA;AAAA,KACzD;AAAA,IACA,QAAW,GAAA;AACT,MAAA,OAAO,cAAc,OAAQ,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA;AAAA,KAC/B;AAAA,IACA,KAAO,EAAA,SAAA;AAAA,IACP,gBAAkB,EAAA,cAAA;AAAA,GACpB,CAAA;AAKF,CAAA;AAeO,SAAS,qBAMd,MAW+C,EAAA;AAC/C,EAAA,OAAO,CAAC,OACL,MAAA;AAAA,IACC,KAAA,EAAO,OAAO,OAAQ,CAAA,KAAA;AAAA,IACtB,SAAS,MAAO,CAAA,OAAA;AAAA,IAChB,MAAM,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