@salesforce/lds-adapters-community-microbatching 1.100.2

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/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@salesforce/lds-adapters-community-microbatching",
3
+ "version": "1.100.2",
4
+ "license": "SEE LICENSE IN LICENSE.txt",
5
+ "description": "Microbatching requests",
6
+ "main": "dist/umd/es2018/community-microbatching.js",
7
+ "module": "dist/es/es2018/community-microbatching.js",
8
+ "types": "dist/types/src/generated/artifacts/main.d.ts",
9
+ "files": [
10
+ "dist",
11
+ "sfdc",
12
+ "src/raml/*"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/es/es2018/community-microbatching.js",
17
+ "require": "./dist/umd/es2018/community-microbatching.js",
18
+ "types": "./dist/types/src/generated/artifacts/main.d.ts"
19
+ },
20
+ "./sfdc": {
21
+ "import": "./sfdc/index.js",
22
+ "types": "./sfdc/index.d.ts",
23
+ "default": "./sfdc/index.js"
24
+ }
25
+ },
26
+ "contributors": [
27
+ "pmaliwat@salesforce.com"
28
+ ],
29
+ "scripts": {
30
+ "build": "yarn build:raml && yarn build:services && yarn build:karma",
31
+ "build:karma": "rollup --config rollup.config.karma.js",
32
+ "build:raml": "luvio generate src/raml/luvio.raml src/generated -p '../lds-compiler-plugins'",
33
+ "build:services": "rollup --config rollup.config.js",
34
+ "clean": "rm -rf dist sfdc src/generated karma/dist",
35
+ "release:core": "../../scripts/release/core.js --adapter=lds-adapters-community-microbatching",
36
+ "release:corejar": "yarn build && packages/core-build/scripts/core.js --adapter=lds-adapters-community-microbatching",
37
+ "start": "karma start",
38
+ "test": "karma start --single-run",
39
+ "test:compat": "karma start --single-run --compat"
40
+ },
41
+ "dependencies": {
42
+ "@salesforce/lds-bindings": "^1.100.2"
43
+ },
44
+ "devDependencies": {
45
+ "@luvio/cli": "0.135.4",
46
+ "@luvio/compiler": "0.135.4",
47
+ "@luvio/engine": "0.135.4",
48
+ "@luvio/lwc-luvio": "0.135.4",
49
+ "@salesforce/lds-karma": "^1.100.2"
50
+ },
51
+ "nx": {
52
+ "targets": {
53
+ "build": {
54
+ "outputs": [
55
+ "packages/lds-adapters-community-microbatching/dist",
56
+ "packages/lds-adapters-community-microbatching/karma/dist",
57
+ "packages/lds-adapters-community-microbatching/sfdc",
58
+ "packages/lds-adapters-community-microbatching/src/generated"
59
+ ]
60
+ }
61
+ }
62
+ },
63
+ "volta": {
64
+ "extends": "../../package.json"
65
+ }
66
+ }
@@ -0,0 +1 @@
1
+ export * from '../dist/types/src/generated/artifacts/sfdc';
package/sfdc/index.js ADDED
@@ -0,0 +1,337 @@
1
+ /**
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+
7
+ /* *******************************************************************************************
8
+ * ATTENTION!
9
+ * THIS IS A GENERATED FILE FROM https://github.com/salesforce-experience-platform-emu/lds-lightning-platform
10
+ * If you would like to contribute to LDS, please follow the steps outlined in the git repo.
11
+ * Any changes made to this file in p4 will be automatically overwritten.
12
+ * *******************************************************************************************
13
+ */
14
+ /* proxy-compat-disable */
15
+ import { withDefaultLuvio } from 'force/ldsEngine';
16
+ import { serializeStructuredKey, StoreKeyMap } from 'force/luvioEngine';
17
+
18
+ const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
19
+ const { keys: ObjectKeys$1, freeze: ObjectFreeze$1, create: ObjectCreate$1 } = Object;
20
+ const { isArray: ArrayIsArray$1 } = Array;
21
+ /**
22
+ * Validates an adapter config is well-formed.
23
+ * @param config The config to validate.
24
+ * @param adapter The adapter validation configuration.
25
+ * @param oneOf The keys the config must contain at least one of.
26
+ * @throws A TypeError if config doesn't satisfy the adapter's config validation.
27
+ */
28
+ function validateConfig(config, adapter, oneOf) {
29
+ const { displayName } = adapter;
30
+ const { required, optional, unsupported } = adapter.parameters;
31
+ if (config === undefined ||
32
+ required.every(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
33
+ throw new TypeError(`adapter ${displayName} configuration must specify ${required.sort().join(', ')}`);
34
+ }
35
+ if (oneOf && oneOf.some(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
36
+ throw new TypeError(`adapter ${displayName} configuration must specify one of ${oneOf.sort().join(', ')}`);
37
+ }
38
+ if (unsupported !== undefined &&
39
+ unsupported.some(req => ObjectPrototypeHasOwnProperty.call(config, req))) {
40
+ throw new TypeError(`adapter ${displayName} does not yet support ${unsupported.sort().join(', ')}`);
41
+ }
42
+ const supported = required.concat(optional);
43
+ if (ObjectKeys$1(config).some(key => !supported.includes(key))) {
44
+ throw new TypeError(`adapter ${displayName} configuration supports only ${supported.sort().join(', ')}`);
45
+ }
46
+ }
47
+ function untrustedIsObject(untrusted) {
48
+ return typeof untrusted === 'object' && untrusted !== null && ArrayIsArray$1(untrusted) === false;
49
+ }
50
+ function areRequiredParametersPresent(config, configPropertyNames) {
51
+ return configPropertyNames.parameters.required.every(req => req in config);
52
+ }
53
+ const keyPrefix = 'microbatching';
54
+
55
+ const { freeze: ObjectFreeze, keys: ObjectKeys, create: ObjectCreate, assign: ObjectAssign } = Object;
56
+ const { isArray: ArrayIsArray } = Array;
57
+ function deepFreeze(value) {
58
+ // No need to freeze primitives
59
+ if (typeof value !== 'object' || value === null) {
60
+ return;
61
+ }
62
+ if (ArrayIsArray(value)) {
63
+ for (let i = 0, len = value.length; i < len; i += 1) {
64
+ deepFreeze(value[i]);
65
+ }
66
+ }
67
+ else {
68
+ const keys = ObjectKeys(value);
69
+ for (let i = 0, len = keys.length; i < len; i += 1) {
70
+ deepFreeze(value[keys[i]]);
71
+ }
72
+ }
73
+ ObjectFreeze(value);
74
+ }
75
+ function createLink(ref) {
76
+ return {
77
+ __ref: serializeStructuredKey(ref),
78
+ };
79
+ }
80
+
81
+ function validate$1(obj, path = 'MicrobatchingIngestionInputRepresentation') {
82
+ const v_error = (() => {
83
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
84
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
85
+ }
86
+ if (obj.groupBy !== undefined) {
87
+ const obj_groupBy = obj.groupBy;
88
+ const path_groupBy = path + '.groupBy';
89
+ if (typeof obj_groupBy !== 'string') {
90
+ return new TypeError('Expected "string" but received "' + typeof obj_groupBy + '" (at "' + path_groupBy + '")');
91
+ }
92
+ }
93
+ if (obj.keyPrefix !== undefined) {
94
+ const obj_keyPrefix = obj.keyPrefix;
95
+ const path_keyPrefix = path + '.keyPrefix';
96
+ if (typeof obj_keyPrefix !== 'string') {
97
+ return new TypeError('Expected "string" but received "' + typeof obj_keyPrefix + '" (at "' + path_keyPrefix + '")');
98
+ }
99
+ }
100
+ const obj_processType = obj.processType;
101
+ const path_processType = path + '.processType';
102
+ if (typeof obj_processType !== 'string') {
103
+ return new TypeError('Expected "string" but received "' + typeof obj_processType + '" (at "' + path_processType + '")');
104
+ }
105
+ const obj_requestBody = obj.requestBody;
106
+ const path_requestBody = path + '.requestBody';
107
+ if (typeof obj_requestBody !== 'object' || ArrayIsArray(obj_requestBody) || obj_requestBody === null) {
108
+ return new TypeError('Expected "object" but received "' + typeof obj_requestBody + '" (at "' + path_requestBody + '")');
109
+ }
110
+ const obj_requestBody_keys = ObjectKeys(obj_requestBody);
111
+ for (let i = 0; i < obj_requestBody_keys.length; i++) {
112
+ const key = obj_requestBody_keys[i];
113
+ const obj_requestBody_prop = obj_requestBody[key];
114
+ const path_requestBody_prop = path_requestBody + '["' + key + '"]';
115
+ if (obj_requestBody_prop === undefined) {
116
+ return new TypeError('Expected "defined" but received "' + typeof obj_requestBody_prop + '" (at "' + path_requestBody_prop + '")');
117
+ }
118
+ }
119
+ })();
120
+ return v_error === undefined ? null : v_error;
121
+ }
122
+
123
+ const TTL = 100;
124
+ const VERSION = "d9a668888b418883dcdd91e33b218549";
125
+ function validate(obj, path = 'MicrobatchingIngestionOutputRepresentation') {
126
+ const v_error = (() => {
127
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
128
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
129
+ }
130
+ const obj_recordUUID = obj.recordUUID;
131
+ const path_recordUUID = path + '.recordUUID';
132
+ if (typeof obj_recordUUID !== 'string') {
133
+ return new TypeError('Expected "string" but received "' + typeof obj_recordUUID + '" (at "' + path_recordUUID + '")');
134
+ }
135
+ })();
136
+ return v_error === undefined ? null : v_error;
137
+ }
138
+ const RepresentationType = 'MicrobatchingIngestionOutputRepresentation';
139
+ function keyBuilder(luvio, config) {
140
+ return keyPrefix + '::' + RepresentationType + ':' + config.recordUUID;
141
+ }
142
+ function keyBuilderFromType(luvio, object) {
143
+ const keyParams = {
144
+ recordUUID: object.recordUUID
145
+ };
146
+ return keyBuilder(luvio, keyParams);
147
+ }
148
+ function normalize(input, existing, path, luvio, store, timestamp) {
149
+ return input;
150
+ }
151
+ const select$1 = function MicrobatchingIngestionOutputRepresentationSelect() {
152
+ return {
153
+ kind: 'Fragment',
154
+ version: VERSION,
155
+ private: [],
156
+ selections: [
157
+ {
158
+ name: 'recordUUID',
159
+ kind: 'Scalar'
160
+ }
161
+ ]
162
+ };
163
+ };
164
+ function equals(existing, incoming) {
165
+ const existing_recordUUID = existing.recordUUID;
166
+ const incoming_recordUUID = incoming.recordUUID;
167
+ if (!(existing_recordUUID === incoming_recordUUID)) {
168
+ return false;
169
+ }
170
+ return true;
171
+ }
172
+ const ingest = function MicrobatchingIngestionOutputRepresentationIngest(input, path, luvio, store, timestamp) {
173
+ if (process.env.NODE_ENV !== 'production') {
174
+ const validateError = validate(input);
175
+ if (validateError !== null) {
176
+ throw validateError;
177
+ }
178
+ }
179
+ const key = keyBuilderFromType(luvio, input);
180
+ const existingRecord = store.readEntry(key);
181
+ const ttlToUse = TTL;
182
+ let incomingRecord = normalize(input, store.readEntry(key), {
183
+ fullPath: key,
184
+ parent: path.parent,
185
+ propertyName: path.propertyName,
186
+ ttl: ttlToUse
187
+ });
188
+ if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
189
+ luvio.storePublish(key, incomingRecord);
190
+ }
191
+ {
192
+ const storeMetadataParams = {
193
+ ttl: ttlToUse,
194
+ namespace: "microbatching",
195
+ version: VERSION,
196
+ representationName: RepresentationType,
197
+ };
198
+ luvio.publishStoreMetadata(key, storeMetadataParams);
199
+ }
200
+ return createLink(key);
201
+ };
202
+ function getTypeCacheKeys(luvio, input, fullPathFactory) {
203
+ const rootKeySet = new StoreKeyMap();
204
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
205
+ const rootKey = keyBuilderFromType(luvio, input);
206
+ rootKeySet.set(rootKey, {
207
+ namespace: keyPrefix,
208
+ representationName: RepresentationType,
209
+ mergeable: false
210
+ });
211
+ return rootKeySet;
212
+ }
213
+
214
+ function select(luvio, params) {
215
+ return select$1();
216
+ }
217
+ function getResponseCacheKeys(luvio, resourceParams, response) {
218
+ return getTypeCacheKeys(luvio, response);
219
+ }
220
+ function ingestSuccess(luvio, resourceParams, response) {
221
+ const { body } = response;
222
+ const key = keyBuilderFromType(luvio, body);
223
+ luvio.storeIngest(key, ingest, body);
224
+ const snapshot = luvio.storeLookup({
225
+ recordId: key,
226
+ node: select(),
227
+ variables: {},
228
+ });
229
+ if (process.env.NODE_ENV !== 'production') {
230
+ if (snapshot.state !== 'Fulfilled') {
231
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
232
+ }
233
+ }
234
+ return snapshot;
235
+ }
236
+ function createResourceRequest(config) {
237
+ const headers = {};
238
+ return {
239
+ baseUri: '/services/data/v58.0',
240
+ basePath: '/connect/communities/' + config.urlParams.communityId + '/microbatching',
241
+ method: 'post',
242
+ body: config.body,
243
+ urlParams: config.urlParams,
244
+ queryParams: {},
245
+ headers,
246
+ priority: 'normal',
247
+ };
248
+ }
249
+
250
+ const ingestRecord_ConfigPropertyNames = {
251
+ displayName: 'ingestRecord',
252
+ parameters: {
253
+ required: ['communityId', 'requestIngestionInput'],
254
+ optional: []
255
+ }
256
+ };
257
+ function createResourceParams(config) {
258
+ const resourceParams = {
259
+ urlParams: {
260
+ communityId: config.communityId
261
+ },
262
+ body: {
263
+ requestIngestionInput: config.requestIngestionInput
264
+ }
265
+ };
266
+ return resourceParams;
267
+ }
268
+ function typeCheckConfig(untrustedConfig) {
269
+ const config = {};
270
+ const untrustedConfig_communityId = untrustedConfig.communityId;
271
+ if (typeof untrustedConfig_communityId === 'string') {
272
+ config.communityId = untrustedConfig_communityId;
273
+ }
274
+ const untrustedConfig_requestIngestionInput = untrustedConfig.requestIngestionInput;
275
+ const referenceMicrobatchingIngestionInputRepresentationValidationError = validate$1(untrustedConfig_requestIngestionInput);
276
+ if (referenceMicrobatchingIngestionInputRepresentationValidationError === null) {
277
+ config.requestIngestionInput = untrustedConfig_requestIngestionInput;
278
+ }
279
+ return config;
280
+ }
281
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
282
+ if (!untrustedIsObject(untrustedConfig)) {
283
+ return null;
284
+ }
285
+ if (process.env.NODE_ENV !== 'production') {
286
+ validateConfig(untrustedConfig, configPropertyNames);
287
+ }
288
+ const config = typeCheckConfig(untrustedConfig);
289
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
290
+ return null;
291
+ }
292
+ return config;
293
+ }
294
+ function buildNetworkSnapshot(luvio, config, options) {
295
+ const resourceParams = createResourceParams(config);
296
+ const request = createResourceRequest(resourceParams);
297
+ return luvio.dispatchResourceRequest(request, options)
298
+ .then((response) => {
299
+ return luvio.handleSuccessResponse(() => {
300
+ const snapshot = ingestSuccess(luvio, resourceParams, response);
301
+ return luvio.storeBroadcast().then(() => snapshot);
302
+ }, () => getResponseCacheKeys(luvio, resourceParams, response.body));
303
+ }, (response) => {
304
+ deepFreeze(response);
305
+ throw response;
306
+ });
307
+ }
308
+ const ingestRecordAdapterFactory = (luvio) => {
309
+ return function ingestRecord(untrustedConfig) {
310
+ const config = validateAdapterConfig(untrustedConfig, ingestRecord_ConfigPropertyNames);
311
+ // Invalid or incomplete config
312
+ if (config === null) {
313
+ throw new Error('Invalid config for "ingestRecord"');
314
+ }
315
+ return buildNetworkSnapshot(luvio, config);
316
+ };
317
+ };
318
+
319
+ let ingestRecord;
320
+ function bindExportsTo(luvio) {
321
+ function unwrapSnapshotData(factory) {
322
+ const adapter = factory(luvio);
323
+ return (config) => adapter(config).then(snapshot => snapshot.data);
324
+ }
325
+ return {
326
+ ingestRecord: unwrapSnapshotData(ingestRecordAdapterFactory),
327
+ // Imperative GET Adapters
328
+ };
329
+ }
330
+ withDefaultLuvio((luvio) => {
331
+ ({
332
+ ingestRecord,
333
+ } = bindExportsTo(luvio));
334
+ });
335
+
336
+ export { ingestRecord };
337
+ // version: 1.100.2-ca56bb821
@@ -0,0 +1,89 @@
1
+ #%RAML 1.0
2
+ securedBy:
3
+ - OAuth2
4
+ title: Salesforce Connect API
5
+ version: '54.0'
6
+ mediaType: application/json
7
+ protocols:
8
+ - https
9
+ baseUri: /services/data/v58.0
10
+ securitySchemes:
11
+ OAuth2:
12
+ type: OAuth 2.0
13
+ settings:
14
+ authorizationUri: https://example.com/oauth/authorize
15
+ accessTokenUri: ''
16
+ authorizationGrants:
17
+ - implicit
18
+ annotationTypes:
19
+ oas-readOnly:
20
+ type: boolean
21
+ allowedTargets: TypeDeclaration
22
+ oas-collectionFormat:
23
+ type: string
24
+ oas-body-name:
25
+ type: string
26
+ allowedTargets: TypeDeclaration
27
+ types:
28
+ MicrobatchingIngestionInputWrapperRepresentation: # TODO Hand-rolled W-8334626
29
+ description: Wrapper Microbatching Ingestion Input Representation
30
+ type: object
31
+ properties:
32
+ requestIngestionInput:
33
+ description: Set parameters for ingestion.
34
+ type: MicrobatchingIngestionInputRepresentation
35
+ MicrobatchingIngestionInputRepresentation:
36
+ description: Microbatching Ingestion Input Representation
37
+ type: object
38
+ properties:
39
+ groupBy:
40
+ description: GroupBy
41
+ type: string
42
+ required: false # TODO handrolled W-9314597
43
+ keyPrefix:
44
+ description: KeyPrefix
45
+ type: string
46
+ required: false # TODO handrolled W-9314597
47
+ processType:
48
+ description: ProcessType
49
+ type: string
50
+ requestBody:
51
+ description: RequestBody
52
+ type: object
53
+ properties:
54
+ //:
55
+ type: any # TODO Hand-rolled W-10049570
56
+ MicrobatchingIngestionOutputRepresentation:
57
+ description: Representation for microbatching buffering response
58
+ type: object
59
+ properties:
60
+ recordUUID:
61
+ description: UUID of the ingested record
62
+ type: string
63
+ MicrobatchingIngestionRequestBodyInputRepresentation:
64
+ description: Encapsulates request body payload
65
+ type: object
66
+ properties:
67
+ requestBody:
68
+ description: RequestBody
69
+ type: object
70
+ properties:
71
+ //:
72
+ type: object
73
+ /connect/communities/{communityId}/microbatching:
74
+ post:
75
+ description: Microbatching record ingestion.
76
+ responses:
77
+ '200':
78
+ description: Success
79
+ body:
80
+ application/json:
81
+ type: MicrobatchingIngestionOutputRepresentation
82
+ body:
83
+ application/json:
84
+ type: MicrobatchingIngestionInputWrapperRepresentation
85
+ (oas-body-name): requestIngestionInput
86
+ uriParameters:
87
+ communityId:
88
+ type: string
89
+ required: true
@@ -0,0 +1,18 @@
1
+ #%RAML 1.0 Overlay
2
+ extends: ./api.raml
3
+
4
+ uses:
5
+ luvio: luvio://annotations.raml
6
+
7
+ (luvio.keyPrefix): 'microbatching'
8
+
9
+ types:
10
+ MicrobatchingIngestionOutputRepresentation:
11
+ (luvio.ttl): 100
12
+ (luvio.key):
13
+ recordUUID: recordUUID
14
+
15
+ /connect/communities/{communityId}/microbatching:
16
+ post:
17
+ (luvio.adapter):
18
+ name: ingestRecord