@conduit-client/command-sse 5.67.0-dev1

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 @@
1
+ export declare function generateNetworkResponse(result: any): Promise<any>;
@@ -0,0 +1,6 @@
1
+ import { type ServiceDescriptor } from '@conduit-client/utils';
2
+ import { SSECommand } from './sse-command';
3
+ export { type SSEMessage } from './sse-command';
4
+ export { SSECommand } from './sse-command';
5
+ export type SSECommandServiceDescriptor = ServiceDescriptor<typeof SSECommand, 'SSECommandBaseClass', '1.0'>;
6
+ export declare function buildServiceDescriptor(): SSECommandServiceDescriptor;
@@ -0,0 +1,30 @@
1
+ import { StreamingCommand } from '@conduit-client/command-streaming/v1';
2
+ import type { NamedFetchService } from '@conduit-client/service-fetch-network/v1';
3
+ export type SSEMessage = {
4
+ event: string;
5
+ data: string;
6
+ id: string;
7
+ retry?: number;
8
+ };
9
+ /**
10
+ * An implementation of StreamingCommand that handles SSE (Server-Sent Event) streams.
11
+ */
12
+ export declare abstract class SSECommand<StreamedData = SSEMessage, ExtraServices extends object = object> extends StreamingCommand<StreamedData, ExtraServices> {
13
+ protected services: NamedFetchService & ExtraServices;
14
+ constructor(services: NamedFetchService & ExtraServices);
15
+ /**
16
+ * Decodes the bytes returned by fetch into the correct shape.
17
+ *
18
+ * @param byteStream ReadableStream<Uint8Array> returned by fetch
19
+ * @returns ReadableStream<StreamedData> that will be the result of the Command
20
+ */
21
+ decodeByteStream(byteStream: ReadableStream<Uint8Array>): ReadableStream<StreamedData>;
22
+ abstract decodeSSEStream(sseStream: ReadableStream<SSEMessage>): ReadableStream<StreamedData>;
23
+ }
24
+ /**
25
+ * A TransformStream that parses server-sent event (SSE) data according to the SSE spec:
26
+ * https://html.spec.whatwg.org/multipage/server-sent-events.html
27
+ */
28
+ export declare class SSEParsingStream extends TransformStream<string, SSEMessage> {
29
+ constructor();
30
+ }
@@ -0,0 +1,88 @@
1
+ /*!
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+ import { StreamingCommand } from "@conduit-client/command-streaming/v1";
7
+ class SSECommand extends StreamingCommand {
8
+ constructor(services) {
9
+ super(services);
10
+ this.services = services;
11
+ }
12
+ /**
13
+ * Decodes the bytes returned by fetch into the correct shape.
14
+ *
15
+ * @param byteStream ReadableStream<Uint8Array> returned by fetch
16
+ * @returns ReadableStream<StreamedData> that will be the result of the Command
17
+ */
18
+ decodeByteStream(byteStream) {
19
+ return this.decodeSSEStream(
20
+ byteStream.pipeThrough(new TextDecoderStream()).pipeThrough(new SSEParsingStream())
21
+ );
22
+ }
23
+ }
24
+ const sseRegex = /^(?<field>[^:]*?)(: ?(?<value>.*?))?(?:\r\n?|\n)/;
25
+ class SSEParsingStream extends TransformStream {
26
+ constructor() {
27
+ let ignoreLeadingLF = false, partialLine = "", data = "", event = "", id = "", retry;
28
+ super({
29
+ transform(chunk, controller) {
30
+ if (ignoreLeadingLF && chunk.startsWith("\n")) {
31
+ chunk = chunk.slice(1);
32
+ }
33
+ ignoreLeadingLF = chunk.endsWith("\r");
34
+ let text = partialLine + chunk;
35
+ let match;
36
+ while (match = text.match(sseRegex)) {
37
+ text = text.slice(match[0].length);
38
+ if (match.groups.field === "" && match.groups.value === void 0) {
39
+ if (data === "") {
40
+ event = "";
41
+ continue;
42
+ }
43
+ if (data.endsWith("\n")) {
44
+ data = data.slice(0, -1);
45
+ }
46
+ const sseMessage = {
47
+ data,
48
+ id,
49
+ // default event value is "message"
50
+ event: event || "message"
51
+ };
52
+ if (retry !== void 0) {
53
+ sseMessage.retry = retry;
54
+ }
55
+ controller.enqueue(sseMessage);
56
+ data = event = "";
57
+ } else if (match.groups.field === "data") {
58
+ data += (match.groups.value || "") + "\n";
59
+ } else if (match.groups.field === "event") {
60
+ event = match.groups.value || "";
61
+ } else if (match.groups.field === "id") {
62
+ const idValue = match.groups.value || "";
63
+ if (!idValue.includes("\0")) {
64
+ id = idValue;
65
+ }
66
+ } else if (match.groups.field === "retry") {
67
+ if (/^\d+$/.exec(match.groups.value)) {
68
+ retry = parseInt(match.groups.value);
69
+ }
70
+ } else ;
71
+ }
72
+ partialLine = text;
73
+ }
74
+ });
75
+ }
76
+ }
77
+ function buildServiceDescriptor() {
78
+ return {
79
+ type: "SSECommandBaseClass",
80
+ version: "1.0",
81
+ service: SSECommand
82
+ };
83
+ }
84
+ export {
85
+ SSECommand,
86
+ buildServiceDescriptor
87
+ };
88
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/v1/sse-command.ts","../../src/v1/index.ts"],"sourcesContent":["import { StreamingCommand } from '@conduit-client/command-streaming/v1';\nimport type { NamedFetchService } from '@conduit-client/service-fetch-network/v1';\n\nexport type SSEMessage = {\n event: string;\n data: string;\n id: string;\n retry?: number;\n};\n\n/**\n * An implementation of StreamingCommand that handles SSE (Server-Sent Event) streams.\n */\nexport abstract class SSECommand<\n StreamedData = SSEMessage,\n ExtraServices extends object = object,\n> extends StreamingCommand<StreamedData, ExtraServices> {\n constructor(protected services: NamedFetchService & ExtraServices) {\n super(services);\n }\n\n /**\n * Decodes the bytes returned by fetch into the correct shape.\n *\n * @param byteStream ReadableStream<Uint8Array> returned by fetch\n * @returns ReadableStream<StreamedData> that will be the result of the Command\n */\n decodeByteStream(byteStream: ReadableStream<Uint8Array>): ReadableStream<StreamedData> {\n return this.decodeSSEStream(\n byteStream\n // eslint-disable-next-line no-undef\n .pipeThrough(new TextDecoderStream())\n .pipeThrough(new SSEParsingStream())\n );\n }\n\n abstract decodeSSEStream(sseStream: ReadableStream<SSEMessage>): ReadableStream<StreamedData>;\n}\n\nconst sseRegex = /^(?<field>[^:]*?)(: ?(?<value>.*?))?(?:\\r\\n?|\\n)/;\n// +-------v------++--------v--------++-----v----+\n// | | |\n// | | CRLF | CR | LF\n// | |\n// | \": value\", or \": comment\" if no field name (optional)\n// |\n// field name (optional); can be entire line if no \":\"\n\n/**\n * A TransformStream that parses server-sent event (SSE) data according to the SSE spec:\n * https://html.spec.whatwg.org/multipage/server-sent-events.html\n */\nexport class SSEParsingStream extends TransformStream<string, SSEMessage> {\n constructor() {\n let ignoreLeadingLF = false,\n partialLine: string = '',\n data: string = '',\n event: string = '',\n id: string = '',\n retry: number | undefined;\n\n super({\n transform(chunk, controller) {\n // account for case where chunk boundary splits \\r\\n\n if (ignoreLeadingLF && chunk.startsWith('\\n')) {\n // eslint-disable-next-line no-param-reassign\n chunk = chunk.slice(1);\n }\n ignoreLeadingLF = chunk.endsWith('\\r');\n\n // prepend partial last line from previous chunk\n let text = partialLine + chunk;\n\n let match: RegExpMatchArray | null;\n while ((match = text.match(sseRegex))) {\n text = text.slice(match[0].length);\n\n // blank linke, end of text/event-stream message\n if (match.groups!.field === '' && match.groups!.value === undefined) {\n // drop messages with no data\n if (data === '') {\n event = '';\n continue;\n }\n\n // strip trailing \\n from data\n if (data.endsWith('\\n')) {\n data = data.slice(0, -1);\n }\n\n const sseMessage: SSEMessage = {\n data,\n id,\n // default event value is \"message\"\n event: event || 'message',\n };\n\n if (retry !== undefined) {\n sseMessage.retry = retry;\n }\n\n controller.enqueue(sseMessage);\n\n // clear data & event for next message; id and retry persist until changed\n data = event = '';\n }\n\n // data: line\n else if (match.groups!.field === 'data') {\n data += (match.groups!.value || '') + '\\n';\n }\n\n // event: line\n else if (match.groups!.field === 'event') {\n event = match.groups!.value || '';\n }\n\n // id: line\n else if (match.groups!.field === 'id') {\n const idValue = match.groups!.value || '';\n if (!idValue.includes('\\u0000')) {\n id = idValue;\n }\n }\n\n // retry: line\n else if (match.groups!.field === 'retry') {\n // ignore bogus values\n if (/^\\d+$/.exec(match.groups!.value)) {\n retry = parseInt(match.groups!.value);\n }\n }\n\n // comment or unrecognized field, ignore\n else {\n // do nothing\n }\n }\n\n // save partial line for next chunk\n partialLine = text;\n },\n });\n }\n}\n","import { type ServiceDescriptor } from '@conduit-client/utils';\nimport { SSECommand } from './sse-command';\nexport { type SSEMessage } from './sse-command';\n\nexport { SSECommand } from './sse-command';\n\nexport type SSECommandServiceDescriptor = ServiceDescriptor<\n typeof SSECommand,\n 'SSECommandBaseClass',\n '1.0'\n>;\n\nexport function buildServiceDescriptor(): SSECommandServiceDescriptor {\n return {\n type: 'SSECommandBaseClass',\n version: '1.0',\n service: SSECommand,\n };\n}\n"],"names":[],"mappings":";;;;;;AAaO,MAAe,mBAGZ,iBAA8C;AAAA,EACpD,YAAsB,UAA6C;AAC/D,UAAM,QAAQ;AADI,SAAA,WAAA;AAAA,EAEtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,iBAAiB,YAAsE;AACnF,WAAO,KAAK;AAAA,MACR,WAEK,YAAY,IAAI,kBAAA,CAAmB,EACnC,YAAY,IAAI,iBAAA,CAAkB;AAAA,IAAA;AAAA,EAE/C;AAGJ;AAEA,MAAM,WAAW;AAaV,MAAM,yBAAyB,gBAAoC;AAAA,EACtE,cAAc;AACV,QAAI,kBAAkB,OAClB,cAAsB,IACtB,OAAe,IACf,QAAgB,IAChB,KAAa,IACb;AAEJ,UAAM;AAAA,MACF,UAAU,OAAO,YAAY;AAEzB,YAAI,mBAAmB,MAAM,WAAW,IAAI,GAAG;AAE3C,kBAAQ,MAAM,MAAM,CAAC;AAAA,QACzB;AACA,0BAAkB,MAAM,SAAS,IAAI;AAGrC,YAAI,OAAO,cAAc;AAEzB,YAAI;AACJ,eAAQ,QAAQ,KAAK,MAAM,QAAQ,GAAI;AACnC,iBAAO,KAAK,MAAM,MAAM,CAAC,EAAE,MAAM;AAGjC,cAAI,MAAM,OAAQ,UAAU,MAAM,MAAM,OAAQ,UAAU,QAAW;AAEjE,gBAAI,SAAS,IAAI;AACb,sBAAQ;AACR;AAAA,YACJ;AAGA,gBAAI,KAAK,SAAS,IAAI,GAAG;AACrB,qBAAO,KAAK,MAAM,GAAG,EAAE;AAAA,YAC3B;AAEA,kBAAM,aAAyB;AAAA,cAC3B;AAAA,cACA;AAAA;AAAA,cAEA,OAAO,SAAS;AAAA,YAAA;AAGpB,gBAAI,UAAU,QAAW;AACrB,yBAAW,QAAQ;AAAA,YACvB;AAEA,uBAAW,QAAQ,UAAU;AAG7B,mBAAO,QAAQ;AAAA,UACnB,WAGS,MAAM,OAAQ,UAAU,QAAQ;AACrC,qBAAS,MAAM,OAAQ,SAAS,MAAM;AAAA,UAC1C,WAGS,MAAM,OAAQ,UAAU,SAAS;AACtC,oBAAQ,MAAM,OAAQ,SAAS;AAAA,UACnC,WAGS,MAAM,OAAQ,UAAU,MAAM;AACnC,kBAAM,UAAU,MAAM,OAAQ,SAAS;AACvC,gBAAI,CAAC,QAAQ,SAAS,IAAQ,GAAG;AAC7B,mBAAK;AAAA,YACT;AAAA,UACJ,WAGS,MAAM,OAAQ,UAAU,SAAS;AAEtC,gBAAI,QAAQ,KAAK,MAAM,OAAQ,KAAK,GAAG;AACnC,sBAAQ,SAAS,MAAM,OAAQ,KAAK;AAAA,YACxC;AAAA,UACJ,MAGK;AAAA,QAGT;AAGA,sBAAc;AAAA,MAClB;AAAA,IAAA,CACH;AAAA,EACL;AACJ;ACpIO,SAAS,yBAAsD;AAClE,SAAO;AAAA,IACH,MAAM;AAAA,IACN,SAAS;AAAA,IACT,SAAS;AAAA,EAAA;AAEjB;"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@conduit-client/command-sse",
3
+ "version": "5.67.0-dev1",
4
+ "private": false,
5
+ "description": "Luvio SSE Streaming Command",
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/commands/sse"
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/command-base": "5.67.0-dev1",
35
+ "@conduit-client/command-streaming": "5.67.0-dev1",
36
+ "@conduit-client/service-fetch-network": "5.67.0-dev1",
37
+ "@conduit-client/utils": "5.67.0-dev1"
38
+ },
39
+ "volta": {
40
+ "extends": "../../../../package.json"
41
+ },
42
+ "size-limit": [
43
+ {
44
+ "path": "./dist/v1/index.js",
45
+ "limit": "2 kB"
46
+ }
47
+ ]
48
+ }