@conduit-client/service-provisioner 2.0.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.
package/LICENSE.txt ADDED
@@ -0,0 +1,27 @@
1
+ *Attorney/Client Privileged + Confidential*
2
+
3
+ Terms of Use for Public Code (Non-OSS)
4
+
5
+ *NOTE:* Before publishing code under this license/these Terms of Use, please review https://salesforce.quip.com/WFfvAMKB18AL and confirm that you’ve completed all prerequisites described therein. *These Terms of Use may not be used or modified without input from IP and Product Legal.*
6
+
7
+ *Terms of Use*
8
+
9
+ Copyright 2022 Salesforce, Inc. All rights reserved.
10
+
11
+ These Terms of Use govern the download, installation, and/or use of this software provided by Salesforce, Inc. (“Salesforce”) (the “Software”), were last updated on April 15, 2022, ** and constitute a legally binding agreement between you and Salesforce. If you do not agree to these Terms of Use, do not install or use the Software.
12
+
13
+ Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the Software and derivative works subject to these Terms. These Terms shall be included in all copies or substantial portions of the Software.
14
+
15
+ Subject to the limited rights expressly granted hereunder, Salesforce reserves all rights, title, and interest in and to all intellectual property subsisting in the Software. No rights are granted to you hereunder other than as expressly set forth herein. Users residing in countries on the United States Office of Foreign Assets Control sanction list, or which are otherwise subject to a US export embargo, may not use the Software.
16
+
17
+ Implementation of the Software may require development work, for which you are responsible. The Software may contain bugs, errors and incompatibilities and is made available on an AS IS basis without support, updates, or service level commitments.
18
+
19
+ Salesforce reserves the right at any time to modify, suspend, or discontinue, the Software (or any part thereof) with or without notice. You agree that Salesforce shall not be liable to you or to any third party for any modification, suspension, or discontinuance.
20
+
21
+ You agree to defend Salesforce against any claim, demand, suit or proceeding made or brought against Salesforce by a third party arising out of or accruing from (a) your use of the Software, and (b) any application you develop with the Software that infringes any copyright, trademark, trade secret, trade dress, patent, or other intellectual property right of any person or defames any person or violates their rights of publicity or privacy (each a “Claim Against Salesforce”), and will indemnify Salesforce from any damages, attorney fees, and costs finally awarded against Salesforce as a result of, or for any amounts paid by Salesforce under a settlement approved by you in writing of, a Claim Against Salesforce, provided Salesforce (x) promptly gives you written notice of the Claim Against Salesforce, (y) gives you sole control of the defense and settlement of the Claim Against Salesforce (except that you may not settle any Claim Against Salesforce unless it unconditionally releases Salesforce of all liability), and (z) gives you all reasonable assistance, at your expense.
22
+
23
+ WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA, OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
24
+
25
+ These Terms of Use shall be governed exclusively by the internal laws of the State of California, without regard to its conflicts of laws rules. Each party hereby consents to the exclusive jurisdiction of the state and federal courts located in San Francisco County, California to adjudicate any dispute arising out of or relating to these Terms of Use and the download, installation, and/or use of the Software. Except as expressly stated herein, these Terms of Use constitute the entire agreement between the parties, and supersede all prior and contemporaneous agreements, proposals, or representations, written or oral, concerning their subject matter. No modification, amendment, or waiver of any provision of these Terms of Use shall be effective unless it is by an update to these Terms of Use that Salesforce makes available, or is in writing and signed by the party against whom the modification, amendment, or waiver is to be asserted.
26
+
27
+ _*Data Privacy*_: Salesforce may collect, process, and store device, system, and other information related to your use of the Software. This information includes, but is not limited to, IP address, user metrics, and other data (“Usage Data”). Salesforce may use Usage Data for analytics, product development, and marketing purposes. You acknowledge that files generated in conjunction with the Software may contain sensitive or confidential data, and you are solely responsible for anonymizing and protecting such data.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ This software is provided as-is with no support provided.
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
File without changes
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,78 @@
1
+ import { type ServiceDescriptor } from '@conduit-client/utils';
2
+ /**
3
+ * When a service instance is registered it can have additional tags associated with it.
4
+ * Service consumers can use these tags to discriminate among otherwise equivalent
5
+ * instances of the service.
6
+ */
7
+ export type PublishedService = ServiceDescriptor<unknown> & {
8
+ tags?: Record<string, string>;
9
+ };
10
+ /**
11
+ * A request for a required single service.
12
+ */
13
+ export type ServiceRequest<D extends ServiceDescriptor<unknown>> = Omit<D, 'service'> & {
14
+ tags?: Record<string, string>;
15
+ };
16
+ /**
17
+ * A request for an optional single service.
18
+ */
19
+ export type OptionalServiceRequest<D extends ServiceDescriptor<unknown>> = ServiceRequest<D> & {
20
+ optional: true;
21
+ };
22
+ /**
23
+ * A request for a set of services.
24
+ */
25
+ export type ServicesRequest<D extends ServiceDescriptor<unknown>, Name extends string = D['type']> = Record<Name, ServiceRequest<D> | OptionalServiceRequest<D>>;
26
+ /**
27
+ * Utility type to extract the service implementation type from a ServiceRequest.
28
+ */
29
+ export type RequestedService<R extends ServiceRequest<any>> = R extends OptionalServiceRequest<ServiceDescriptor<infer S>> ? S | undefined : R extends ServiceRequest<ServiceDescriptor<infer S>> ? S : never;
30
+ /**
31
+ * A map of services that matches a given ServicesRequest.
32
+ */
33
+ export type RequestedServices<R extends ServicesRequest<any>> = {
34
+ [k in keyof R]: RequestedService<R[k]>;
35
+ };
36
+ /**
37
+ * Attempts to resolve a set of requested services against a set of published services.
38
+ * Returns a map of the requested services if the published services satisfy the request;
39
+ * undefined if published services are missing one or more of the requested services.
40
+ *
41
+ * Note that this function is exported ONLY for use by runtime environments that need to
42
+ * override the default getServices() implementation below. Service consumers should only
43
+ * use the default export to request the services they need.
44
+ *
45
+ * @param published published services
46
+ * @param requested requested services
47
+ * @returns service map if published satisfies requests; undefined if not
48
+ */
49
+ export declare function resolve<R extends ServicesRequest<ServiceDescriptor<unknown>>>(published: PublishedService[], requested: R): RequestedServices<R> | undefined;
50
+ /**
51
+ * Requests a given set of services from the runtime environment.
52
+ *
53
+ * The default implementation of this function guarantees that the return
54
+ * PromiseLike will be resolved synchronously. That is, one of the functions
55
+ * supplied to its .then() will be invoked before .then() returns. Overrides
56
+ * of this function SHOULD preserve this behavior whenever possible, as
57
+ * some service consumer initialization patterns cannot support asynchronous
58
+ * initialization of services.
59
+ *
60
+ * @param request requested services
61
+ * @returns PromiseLike for the requested services; rejects if the requested
62
+ * services are not available
63
+ */
64
+ export default function getServices<R extends ServicesRequest<any>>(request: R, timeout?: number): PromiseLike<RequestedServices<R>>;
65
+ /**
66
+ * Sets the services that will be used to satisfy calls to getServices().
67
+ * Any previously registered services are replaced with the services provided.
68
+ * Note overwriting services should be done with great care as previous callers
69
+ * of getServices() will not be aware of the new services.
70
+ *
71
+ * The default implementation provided by this module only supports a single
72
+ * set of active services. Runtime environments that require multiple sets of
73
+ * active services will need to override this module with their own
74
+ * implementation.
75
+
76
+ * @param services services to be used to satisfy future getServices() requests
77
+ */
78
+ export declare function setServices(services: PublishedService[]): void;
@@ -0,0 +1,66 @@
1
+ /*!
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+ import { racesync, satisfies, resolvedPromiseLike } from "@conduit-client/utils";
7
+ function resolve(published, requested) {
8
+ const result = {};
9
+ for (const [name, request] of Object.entries(requested)) {
10
+ const matchingService = published.find(
11
+ (s) => (
12
+ // service types must match
13
+ s.type === request.type && // version of the service must satisfy the requested version
14
+ satisfies(s.version, request.version) && // no tags requested, or the service matches every requested tag value
15
+ (request.tags === void 0 || Object.keys(request.tags).every((tag) => {
16
+ var _a;
17
+ return ((_a = s.tags) == null ? void 0 : _a[tag]) === request.tags[tag];
18
+ }))
19
+ )
20
+ );
21
+ if (matchingService) {
22
+ result[name] = matchingService.service;
23
+ } else if (!("optional" in request && request.optional)) {
24
+ return;
25
+ }
26
+ }
27
+ return result;
28
+ }
29
+ let servicesAvailable;
30
+ let waitForServices = new Promise(
31
+ (resolve2) => servicesAvailable = resolve2
32
+ );
33
+ function getServices(request, timeout = 3e4) {
34
+ const servicesPromise = waitForServices.then((services) => {
35
+ const result = resolve(services, request);
36
+ if (result) {
37
+ return result;
38
+ }
39
+ throw new Error("no matches found for one or more requested services");
40
+ });
41
+ let timeoutId;
42
+ let timeoutPromise = new Promise((_, reject) => {
43
+ timeoutId = setTimeout(() => reject(new Error("OneStore services unavailable")), timeout);
44
+ });
45
+ return racesync([servicesPromise, timeoutPromise]).then(
46
+ (value) => {
47
+ clearTimeout(timeoutId);
48
+ return value;
49
+ },
50
+ (reason) => {
51
+ clearTimeout(timeoutId);
52
+ console.error(reason);
53
+ throw reason;
54
+ }
55
+ );
56
+ }
57
+ function setServices(services) {
58
+ waitForServices = resolvedPromiseLike(services);
59
+ servicesAvailable(services);
60
+ }
61
+ export {
62
+ getServices as default,
63
+ resolve,
64
+ setServices
65
+ };
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/v1/index.ts"],"sourcesContent":["import {\n resolvedPromiseLike,\n racesync,\n satisfies,\n type ServiceDescriptor,\n} from '@conduit-client/utils';\n\n/**\n * When a service instance is registered it can have additional tags associated with it.\n * Service consumers can use these tags to discriminate among otherwise equivalent\n * instances of the service.\n */\nexport type PublishedService = ServiceDescriptor<unknown> & {\n tags?: Record<string, string>;\n};\n\n/**\n * A request for a required single service.\n */\nexport type ServiceRequest<D extends ServiceDescriptor<unknown>> = Omit<D, 'service'> & {\n tags?: Record<string, string>;\n};\n\n/**\n * A request for an optional single service.\n */\nexport type OptionalServiceRequest<D extends ServiceDescriptor<unknown>> = ServiceRequest<D> & {\n optional: true;\n};\n\n/**\n * A request for a set of services.\n */\nexport type ServicesRequest<\n D extends ServiceDescriptor<unknown>,\n Name extends string = D['type'],\n> = Record<Name, ServiceRequest<D> | OptionalServiceRequest<D>>;\n\n/**\n * Utility type to extract the service implementation type from a ServiceRequest.\n */\nexport type RequestedService<R extends ServiceRequest<any>> =\n R extends OptionalServiceRequest<ServiceDescriptor<infer S>>\n ? S | undefined\n : R extends ServiceRequest<ServiceDescriptor<infer S>>\n ? S\n : never;\n\n/**\n * A map of services that matches a given ServicesRequest.\n */\nexport type RequestedServices<R extends ServicesRequest<any>> = {\n [k in keyof R]: RequestedService<R[k]>;\n};\n\n/**\n * Attempts to resolve a set of requested services against a set of published services.\n * Returns a map of the requested services if the published services satisfy the request;\n * undefined if published services are missing one or more of the requested services.\n *\n * Note that this function is exported ONLY for use by runtime environments that need to\n * override the default getServices() implementation below. Service consumers should only\n * use the default export to request the services they need.\n *\n * @param published published services\n * @param requested requested services\n * @returns service map if published satisfies requests; undefined if not\n */\nexport function resolve<R extends ServicesRequest<ServiceDescriptor<unknown>>>(\n published: PublishedService[],\n requested: R\n): RequestedServices<R> | undefined {\n const result: RequestedServices<R> = {} as any;\n\n for (const [name, request] of Object.entries(requested)) {\n const matchingService = published.find(\n (s) =>\n // service types must match\n s.type === request.type &&\n // version of the service must satisfy the requested version\n satisfies(s.version, request.version) &&\n // no tags requested, or the service matches every requested tag value\n (request.tags === undefined ||\n Object.keys(request.tags).every((tag) => s.tags?.[tag] === request.tags![tag]))\n );\n\n if (matchingService) {\n (result as any)[name] = matchingService.service;\n } else if (!('optional' in request && request.optional)) {\n return;\n }\n }\n\n return result;\n}\n\n/**\n * Most-recently set of published services.\n */\nlet servicesAvailable: (services: PublishedService[]) => void;\nlet waitForServices: PromiseLike<PublishedService[]> = new Promise<PublishedService[]>(\n (resolve) => (servicesAvailable = resolve)\n);\n\n/**\n * Requests a given set of services from the runtime environment.\n *\n * The default implementation of this function guarantees that the return\n * PromiseLike will be resolved synchronously. That is, one of the functions\n * supplied to its .then() will be invoked before .then() returns. Overrides\n * of this function SHOULD preserve this behavior whenever possible, as\n * some service consumer initialization patterns cannot support asynchronous\n * initialization of services.\n *\n * @param request requested services\n * @returns PromiseLike for the requested services; rejects if the requested\n * services are not available\n */\nexport default function getServices<R extends ServicesRequest<any>>(\n request: R,\n timeout: number = 30000\n): PromiseLike<RequestedServices<R>> {\n const servicesPromise = waitForServices.then((services) => {\n // try to resolve the requested services against our services\n const result = resolve(services, request);\n\n // resolve/reject based on whether we have all the requested services\n if (result) {\n return result;\n }\n\n throw new Error('no matches found for one or more requested services');\n });\n\n let timeoutId: ReturnType<typeof setTimeout>;\n let timeoutPromise = new Promise<never>((_, reject) => {\n timeoutId = setTimeout(() => reject(new Error('OneStore services unavailable')), timeout);\n });\n\n return racesync([servicesPromise, timeoutPromise]).then(\n (value) => {\n clearTimeout(timeoutId);\n return value;\n },\n (reason) => {\n clearTimeout(timeoutId);\n // eslint-disable-next-line\n console.error(reason);\n throw reason;\n }\n );\n}\n\n/**\n * Sets the services that will be used to satisfy calls to getServices().\n * Any previously registered services are replaced with the services provided.\n * Note overwriting services should be done with great care as previous callers\n * of getServices() will not be aware of the new services.\n * \n * The default implementation provided by this module only supports a single\n * set of active services. Runtime environments that require multiple sets of\n * active services will need to override this module with their own\n * implementation.\n \n * @param services services to be used to satisfy future getServices() requests\n */\nexport function setServices(services: PublishedService[]) {\n waitForServices = resolvedPromiseLike(services);\n servicesAvailable(services);\n}\n"],"names":["resolve"],"mappings":";;;;;;AAoEO,SAAS,QACZ,WACA,WACgC;AAChC,QAAM,SAA+B,CAAA;AAErC,aAAW,CAAC,MAAM,OAAO,KAAK,OAAO,QAAQ,SAAS,GAAG;AACrD,UAAM,kBAAkB,UAA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service-provisioner",
3
+ "version": "2.0.0",
4
+ "private": false,
5
+ "description": "Luvio Service Provisioner",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/salesforce-experience-platform-emu/luvio-next.git",
10
+ "directory": "packages/@conduit-client/service-provisioner"
11
+ },
12
+ "license": "SEE LICENSE IN LICENSE.txt",
13
+ "exports": {
14
+ "./v1": {
15
+ "import": "./dist/v1/index.js",
16
+ "types": "./dist/types/v1/index.d.ts",
17
+ "require": "./dist/v1/index.js"
18
+ }
19
+ },
20
+ "main": "./dist/main/index.js",
21
+ "module": "./dist/main/index.js",
22
+ "types": "./dist/main/index.d.ts",
23
+ "files": [
24
+ "dist/"
25
+ ],
26
+ "scripts": {
27
+ "build": "vite build && tsc --build --emitDeclarationOnly",
28
+ "clean": "rm -rf dist",
29
+ "test": "vitest run",
30
+ "test:size": "size-limit",
31
+ "watch": "npm run build --watch"
32
+ },
33
+ "dependencies": {
34
+ "@conduit-client/utils": "2.0.0"
35
+ },
36
+ "volta": {
37
+ "extends": "../../../package.json"
38
+ },
39
+ "size-limit": [
40
+ {
41
+ "path": "./dist/v1/index.js",
42
+ "limit": "720 B"
43
+ }
44
+ ]
45
+ }