@envoy/envoy-integrations-sdk 2.0.1-beta.5 → 2.0.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/README.md +178 -110
- package/dist/base/EnvoyAPI.d.ts +28 -0
- package/dist/base/EnvoyAPI.d.ts.map +1 -0
- package/dist/base/EnvoyAPI.js +121 -0
- package/dist/base/EnvoyPluginStoragePipeline.d.ts +51 -0
- package/dist/base/EnvoyPluginStoragePipeline.d.ts.map +1 -0
- package/dist/base/EnvoyPluginStoragePipeline.js +140 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +12 -0
- package/dist/factories/entryEventBodyFactory.d.ts +42 -0
- package/dist/factories/entryEventBodyFactory.d.ts.map +1 -0
- package/dist/factories/entryEventBodyFactory.js +105 -0
- package/dist/factories/eventBodyFactory.d.ts +18 -0
- package/dist/factories/eventBodyFactory.d.ts.map +1 -0
- package/dist/factories/eventBodyFactory.js +15 -0
- package/dist/factories/inviteEventBodyFactory.d.ts +38 -0
- package/dist/factories/inviteEventBodyFactory.d.ts.map +1 -0
- package/dist/factories/inviteEventBodyFactory.js +92 -0
- package/dist/factories/metaFactory.d.ts +10 -0
- package/dist/factories/metaFactory.d.ts.map +1 -0
- package/dist/factories/metaFactory.js +90 -0
- package/dist/factories/routeBodyFactory.d.ts +19 -0
- package/dist/factories/routeBodyFactory.d.ts.map +1 -0
- package/dist/factories/routeBodyFactory.js +15 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -0
- package/dist/internal/EnvoyEntryEvent.d.ts +3 -0
- package/dist/internal/EnvoyEntryEvent.d.ts.map +1 -0
- package/dist/internal/EnvoyEntryEvent.js +2 -0
- package/dist/internal/EnvoyInviteEvent.d.ts +3 -0
- package/dist/internal/EnvoyInviteEvent.d.ts.map +1 -0
- package/dist/internal/EnvoyInviteEvent.js +2 -0
- package/dist/internal/EnvoyLocationEvent.d.ts +3 -0
- package/dist/internal/EnvoyLocationEvent.d.ts.map +1 -0
- package/dist/internal/EnvoyLocationEvent.js +2 -0
- package/dist/internal/EnvoyOption.d.ts +6 -0
- package/dist/internal/EnvoyOption.d.ts.map +1 -0
- package/dist/internal/EnvoyOption.js +2 -0
- package/dist/internal/EnvoyOptionsRouteParams.d.ts +7 -0
- package/dist/internal/EnvoyOptionsRouteParams.d.ts.map +1 -0
- package/dist/internal/EnvoyOptionsRouteParams.js +2 -0
- package/dist/internal/EnvoyOptionsRouteResponseBody.d.ts +4 -0
- package/dist/internal/EnvoyOptionsRouteResponseBody.d.ts.map +1 -0
- package/dist/internal/EnvoyOptionsRouteResponseBody.js +2 -0
- package/dist/internal/EnvoyPluginJobUpdate.d.ts +11 -0
- package/dist/internal/EnvoyPluginJobUpdate.d.ts.map +1 -0
- package/dist/internal/EnvoyPluginJobUpdate.js +2 -0
- package/dist/internal/EnvoyRemoteValueRouteResponseBody.d.ts +5 -0
- package/dist/internal/EnvoyRemoteValueRouteResponseBody.d.ts.map +1 -0
- package/dist/internal/EnvoyRemoteValueRouteResponseBody.js +2 -0
- package/dist/internal/EnvoySelectedValuesRouteParams.d.ts +5 -0
- package/dist/internal/EnvoySelectedValuesRouteParams.d.ts.map +1 -0
- package/dist/internal/EnvoySelectedValuesRouteParams.js +2 -0
- package/dist/internal/EnvoySelectedValuesRouteResponseBody.d.ts +4 -0
- package/dist/internal/EnvoySelectedValuesRouteResponseBody.d.ts.map +1 -0
- package/dist/internal/EnvoySelectedValuesRouteResponseBody.js +2 -0
- package/dist/internal/EnvoyStorageCommand.d.ts +42 -0
- package/dist/internal/EnvoyStorageCommand.d.ts.map +1 -0
- package/dist/internal/EnvoyStorageCommand.js +7 -0
- package/dist/internal/EnvoyStorageResult.d.ts +4 -0
- package/dist/internal/EnvoyStorageResult.d.ts.map +1 -0
- package/dist/internal/EnvoyStorageResult.js +2 -0
- package/dist/internal/HttpStatus.d.ts +13 -0
- package/dist/internal/HttpStatus.d.ts.map +1 -0
- package/dist/internal/HttpStatus.js +15 -0
- package/dist/mocks/EnvoyPluginJobMock.d.ts +12 -0
- package/dist/mocks/EnvoyPluginJobMock.d.ts.map +1 -0
- package/dist/mocks/EnvoyPluginJobMock.js +60 -0
- package/dist/mocks/EnvoyPluginStoragePipelineMock.d.ts +24 -0
- package/dist/mocks/EnvoyPluginStoragePipelineMock.d.ts.map +1 -0
- package/dist/mocks/EnvoyPluginStoragePipelineMock.js +212 -0
- package/dist/payloads/EntryPayload.d.ts +80 -0
- package/dist/payloads/EntryPayload.d.ts.map +1 -0
- package/dist/payloads/EntryPayload.js +28 -0
- package/dist/payloads/InvitePayload.d.ts +66 -0
- package/dist/payloads/InvitePayload.d.ts.map +1 -0
- package/dist/payloads/InvitePayload.js +24 -0
- package/dist/payloads/LocationPayload.d.ts +7 -0
- package/dist/payloads/LocationPayload.d.ts.map +1 -0
- package/dist/payloads/LocationPayload.js +2 -0
- package/dist/payloads/NotificationPayload.d.ts +54 -0
- package/dist/payloads/NotificationPayload.d.ts.map +1 -0
- package/dist/payloads/NotificationPayload.js +2 -0
- package/dist/resources/AgreementPageResource.d.ts +17 -0
- package/dist/resources/AgreementPageResource.d.ts.map +1 -0
- package/dist/resources/AgreementPageResource.js +2 -0
- package/dist/resources/AgreementResource.d.ts +24 -0
- package/dist/resources/AgreementResource.d.ts.map +1 -0
- package/dist/resources/AgreementResource.js +2 -0
- package/dist/resources/CompanyResource.d.ts +19 -0
- package/dist/resources/CompanyResource.d.ts.map +1 -0
- package/dist/resources/CompanyResource.js +2 -0
- package/dist/resources/CompanyRoleResource.d.ts +8 -0
- package/dist/resources/CompanyRoleResource.d.ts.map +1 -0
- package/dist/resources/CompanyRoleResource.js +2 -0
- package/dist/resources/CurrentUserResource.d.ts +8 -0
- package/dist/resources/CurrentUserResource.d.ts.map +1 -0
- package/dist/resources/CurrentUserResource.js +2 -0
- package/dist/resources/EmployeeResource.d.ts +43 -0
- package/dist/resources/EmployeeResource.d.ts.map +1 -0
- package/dist/resources/EmployeeResource.js +2 -0
- package/dist/resources/FlowResource.d.ts +31 -0
- package/dist/resources/FlowResource.d.ts.map +1 -0
- package/dist/resources/FlowResource.js +2 -0
- package/dist/resources/InviteResource.d.ts +86 -0
- package/dist/resources/InviteResource.d.ts.map +1 -0
- package/dist/resources/InviteResource.js +2 -0
- package/dist/resources/LocationResource.d.ts +64 -0
- package/dist/resources/LocationResource.d.ts.map +1 -0
- package/dist/resources/LocationResource.js +2 -0
- package/dist/resources/LocationRoleResource.d.ts +8 -0
- package/dist/resources/LocationRoleResource.d.ts.map +1 -0
- package/dist/resources/LocationRoleResource.js +2 -0
- package/dist/resources/SignInFieldPageResource.d.ts +17 -0
- package/dist/resources/SignInFieldPageResource.d.ts.map +1 -0
- package/dist/resources/SignInFieldPageResource.js +2 -0
- package/dist/resources/SignInFieldResource.d.ts +33 -0
- package/dist/resources/SignInFieldResource.d.ts.map +1 -0
- package/dist/resources/SignInFieldResource.js +2 -0
- package/dist/resources/UserResource.d.ts +13 -0
- package/dist/resources/UserResource.d.ts.map +1 -0
- package/dist/resources/UserResource.js +2 -0
- package/dist/sdk/EnvoyMeta.d.ts +96 -0
- package/dist/sdk/EnvoyMeta.d.ts.map +1 -0
- package/dist/sdk/EnvoyMeta.js +2 -0
- package/dist/sdk/EnvoyPluginAPI.d.ts +31 -0
- package/dist/sdk/EnvoyPluginAPI.d.ts.map +1 -0
- package/dist/sdk/EnvoyPluginAPI.js +205 -0
- package/dist/sdk/EnvoyPluginJob.d.ts +49 -0
- package/dist/sdk/EnvoyPluginJob.d.ts.map +1 -0
- package/dist/sdk/EnvoyPluginJob.js +99 -0
- package/dist/sdk/EnvoyPluginJobAttachment.d.ts +43 -0
- package/dist/sdk/EnvoyPluginJobAttachment.d.ts.map +1 -0
- package/dist/sdk/EnvoyPluginJobAttachment.js +2 -0
- package/dist/sdk/EnvoyPluginSDK.d.ts +100 -0
- package/dist/sdk/EnvoyPluginSDK.d.ts.map +1 -0
- package/dist/sdk/EnvoyPluginSDK.js +204 -0
- package/dist/sdk/EnvoyPluginStorage.d.ts +69 -0
- package/dist/sdk/EnvoyPluginStorage.d.ts.map +1 -0
- package/dist/sdk/EnvoyPluginStorage.js +78 -0
- package/dist/sdk/EnvoyRequest.d.ts +116 -0
- package/dist/sdk/EnvoyRequest.d.ts.map +1 -0
- package/dist/sdk/EnvoyRequest.js +7 -0
- package/dist/sdk/EnvoyResponse.d.ts +42 -0
- package/dist/sdk/EnvoyResponse.d.ts.map +1 -0
- package/dist/sdk/EnvoyResponse.js +2 -0
- package/dist/sdk/EnvoyStorageItem.d.ts +9 -0
- package/dist/sdk/EnvoyStorageItem.d.ts.map +1 -0
- package/dist/sdk/EnvoyStorageItem.js +2 -0
- package/dist/sdk/EnvoyUserAPI.d.ts +119 -0
- package/dist/sdk/EnvoyUserAPI.d.ts.map +1 -0
- package/dist/sdk/EnvoyUserAPI.js +493 -0
- package/dist/sdk/filters.d.ts +30 -0
- package/dist/sdk/filters.d.ts.map +1 -0
- package/dist/sdk/filters.js +72 -0
- package/dist/sdk/handlers.d.ts +125 -0
- package/dist/sdk/handlers.d.ts.map +1 -0
- package/dist/sdk/handlers.js +108 -0
- package/dist/sdk/loggers.d.ts +6 -0
- package/dist/sdk/loggers.d.ts.map +1 -0
- package/dist/sdk/loggers.js +161 -0
- package/dist/sdk/middleware.d.ts +19 -0
- package/dist/sdk/middleware.d.ts.map +1 -0
- package/dist/sdk/middleware.js +159 -0
- package/dist/util/EnvoyJWT.d.ts +17 -0
- package/dist/util/EnvoyJWT.d.ts.map +1 -0
- package/dist/util/EnvoyJWT.js +54 -0
- package/dist/util/EnvoySignatureVerifier.d.ts +26 -0
- package/dist/util/EnvoySignatureVerifier.d.ts.map +1 -0
- package/dist/util/EnvoySignatureVerifier.js +53 -0
- package/dist/util/axiosConstructor.d.ts +4 -0
- package/dist/util/axiosConstructor.d.ts.map +1 -0
- package/dist/util/axiosConstructor.js +58 -0
- package/dist/util/errorHandling.d.ts +2 -0
- package/dist/util/errorHandling.d.ts.map +1 -0
- package/dist/util/errorHandling.js +18 -0
- package/dist/util/json-api/JSONAPIData.d.ts +5 -0
- package/dist/util/json-api/JSONAPIData.d.ts.map +1 -0
- package/dist/util/json-api/JSONAPIData.js +2 -0
- package/dist/util/json-api/JSONAPIFilterParams.d.ts +5 -0
- package/dist/util/json-api/JSONAPIFilterParams.d.ts.map +1 -0
- package/dist/util/json-api/JSONAPIFilterParams.js +2 -0
- package/dist/util/json-api/JSONAPIModel.d.ts +10 -0
- package/dist/util/json-api/JSONAPIModel.d.ts.map +1 -0
- package/dist/util/json-api/JSONAPIModel.js +2 -0
- package/dist/util/json-api/JSONAPIPaginationParams.d.ts +9 -0
- package/dist/util/json-api/JSONAPIPaginationParams.d.ts.map +1 -0
- package/dist/util/json-api/JSONAPIPaginationParams.js +2 -0
- package/dist/util/json-api/JSONAPIParams.d.ts +4 -0
- package/dist/util/json-api/JSONAPIParams.d.ts.map +1 -0
- package/dist/util/json-api/JSONAPIParams.js +2 -0
- package/dist/util/json-api/JSONAPIResponse.d.ts +6 -0
- package/dist/util/json-api/JSONAPIResponse.d.ts.map +1 -0
- package/dist/util/json-api/JSONAPIResponse.js +2 -0
- package/package.json +48 -13
- package/src/base/EnvoyAPI.ts +87 -0
- package/src/base/EnvoyPluginStoragePipeline.ts +99 -0
- package/src/constants.ts +7 -0
- package/src/factories/entryEventBodyFactory.ts +124 -0
- package/src/factories/eventBodyFactory.ts +35 -0
- package/src/factories/inviteEventBodyFactory.ts +107 -0
- package/src/factories/metaFactory.ts +109 -0
- package/src/factories/routeBodyFactory.ts +37 -0
- package/src/index.ts +86 -0
- package/src/internal/EnvoyEntryEvent.ts +10 -0
- package/src/internal/EnvoyInviteEvent.ts +13 -0
- package/src/internal/EnvoyLocationEvent.ts +3 -0
- package/src/internal/EnvoyOption.ts +6 -0
- package/src/internal/EnvoyOptionsRouteParams.ts +7 -0
- package/src/internal/EnvoyOptionsRouteResponseBody.ts +4 -0
- package/src/internal/EnvoyPluginJobUpdate.ts +11 -0
- package/src/internal/EnvoyRemoteValueRouteResponseBody.ts +4 -0
- package/src/internal/EnvoySelectedValuesRouteParams.ts +5 -0
- package/src/internal/EnvoySelectedValuesRouteResponseBody.ts +4 -0
- package/src/internal/EnvoyStorageCommand.ts +60 -0
- package/src/internal/EnvoyStorageResult.ts +5 -0
- package/src/internal/HttpStatus.ts +12 -0
- package/src/mocks/EnvoyPluginJobMock.ts +33 -0
- package/src/mocks/EnvoyPluginStoragePipelineMock.ts +204 -0
- package/src/payloads/EntryPayload.ts +101 -0
- package/src/payloads/InvitePayload.ts +79 -0
- package/src/payloads/LocationPayload.ts +8 -0
- package/src/payloads/NotificationPayload.ts +54 -0
- package/src/resources/AgreementPageResource.ts +19 -0
- package/src/resources/AgreementResource.ts +26 -0
- package/src/resources/CompanyResource.ts +21 -0
- package/src/resources/CompanyRoleResource.ts +10 -0
- package/src/resources/CurrentUserResource.ts +10 -0
- package/src/resources/EmployeeResource.ts +47 -0
- package/src/resources/FlowResource.ts +35 -0
- package/src/resources/InviteResource.ts +92 -0
- package/src/resources/LocationResource.ts +68 -0
- package/src/resources/LocationRoleResource.ts +10 -0
- package/src/resources/SignInFieldPageResource.ts +23 -0
- package/src/resources/SignInFieldResource.ts +35 -0
- package/src/resources/UserResource.ts +14 -0
- package/src/sdk/EnvoyMeta.ts +101 -0
- package/src/sdk/EnvoyPluginAPI.ts +95 -0
- package/src/sdk/EnvoyPluginJob.ts +90 -0
- package/src/sdk/EnvoyPluginJobAttachment.ts +48 -0
- package/src/sdk/EnvoyPluginSDK.ts +185 -0
- package/src/sdk/EnvoyPluginStorage.ts +83 -0
- package/src/sdk/EnvoyRequest.ts +145 -0
- package/src/sdk/EnvoyResponse.ts +46 -0
- package/src/sdk/EnvoyStorageItem.ts +9 -0
- package/src/sdk/EnvoyUserAPI.ts +339 -0
- package/src/sdk/filters.ts +96 -0
- package/src/sdk/handlers.ts +234 -0
- package/src/sdk/loggers.ts +165 -0
- package/src/sdk/middleware.ts +101 -0
- package/src/util/EnvoyJWT.ts +51 -0
- package/src/util/EnvoySignatureVerifier.ts +61 -0
- package/src/util/axiosConstructor.ts +46 -0
- package/src/util/errorHandling.ts +15 -0
- package/src/util/json-api/JSONAPIData.ts +4 -0
- package/src/util/json-api/JSONAPIFilterParams.ts +5 -0
- package/src/util/json-api/JSONAPIModel.ts +10 -0
- package/src/util/json-api/JSONAPIPaginationParams.ts +12 -0
- package/src/util/json-api/JSONAPIParams.ts +3 -0
- package/src/util/json-api/JSONAPIResponse.ts +5 -0
- package/.eslintrc.js +0 -46
- package/.github/workflows/package.yaml +0 -43
- package/.github/workflows/test.yaml +0 -15
- package/asynchandler.md +0 -46
- package/envoyapi.md +0 -150
- package/envoyjwt.md +0 -46
- package/envoypluginjob.md +0 -106
- package/envoypluginsdk.md +0 -87
- package/envoypluginstorage.md +0 -95
- package/envoypluginstoragepipeline.md +0 -125
- package/envoysignatureverifier.md +0 -43
- package/errormiddleware.md +0 -41
- package/index.js +0 -49
- package/lib/EnvoyAPI.js +0 -564
- package/lib/EnvoyJWT.js +0 -72
- package/lib/EnvoyPluginJob.js +0 -124
- package/lib/EnvoyPluginSDK.js +0 -192
- package/lib/EnvoyPluginStorage.js +0 -121
- package/lib/EnvoyPluginStoragePipeline.js +0 -155
- package/lib/EnvoyResponseError.js +0 -18
- package/lib/EnvoySignatureVerifier.js +0 -67
- package/lib/HttpStatus.js +0 -20
- package/lib/asyncHandler.js +0 -17
- package/lib/axios.js +0 -34
- package/lib/errorMiddleware.js +0 -27
- package/lib/middleware.js +0 -110
- package/middleware.md +0 -53
- package/test/axios.test.js +0 -57
- package/test/promises.test.js +0 -82
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Envoy Node.js SDK
|
|
2
2
|
|
|
3
|
-
The SDK exports several classes and functions, however the most typical way to integrate the SDK is as middleware. The `
|
|
3
|
+
The SDK exports several classes and functions, however the most typical way to integrate the SDK is as middleware. The `envoyMiddleware()` function call returns a middleware that attaches an instance of `EnvoyPluginSDK` to the `req` object and verifies that the request came from Envoy. It is available as `req.envoy`.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -25,127 +25,195 @@ View our Node.js [quickstart guide](https://developers.envoy.com/hub/docs/nodejs
|
|
|
25
25
|
|
|
26
26
|
### Usage
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
#### Define your `config`
|
|
29
|
+
When customers go through your integration's setup steps, that info is saved in a `config` object that is sent along with every request Envoy makes to your integration.
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
Defining this object as a specific type allows us to safely type the various handlers that will use those values.
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// defs/Config.ts
|
|
35
|
+
type Config = {
|
|
36
|
+
greeting: string
|
|
37
|
+
};
|
|
38
|
+
export default Config;
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### Implement setup routes
|
|
42
|
+
As customers go through the setup steps of your integration, they may trigger several requests to your integration for things like:
|
|
43
|
+
- loading dropdown options
|
|
44
|
+
- loading text fields with remote data
|
|
45
|
+
- validating submitted step data
|
|
46
|
+
|
|
47
|
+
Below, we'll implement a route that will load a list of greetings into a dropdown in our setup steps.
|
|
48
|
+
|
|
49
|
+
View the other types of handlers [here](docs#handler-functions).
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// greetingOptions.ts
|
|
53
|
+
import { optionsRouteHandler } from '@envoy/envoy-integrations-sdk';
|
|
54
|
+
|
|
55
|
+
export default optionsRouteHandler((req, res) => {
|
|
56
|
+
res.send([
|
|
57
|
+
{
|
|
58
|
+
label: 'Hello',
|
|
59
|
+
value: 'Hello',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
label: 'Hola',
|
|
63
|
+
value: 'Hola',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
label: 'Aloha',
|
|
67
|
+
value: 'Aloha',
|
|
68
|
+
},
|
|
69
|
+
]);
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### Implement event handlers
|
|
74
|
+
Your integration can respond to several Envoy events. Below, we'll implement a simple event handler for an `entry_sign_in` event.
|
|
75
|
+
|
|
76
|
+
All it does is to take the greeting that the customer chose during setup, and displays it in the Envoy Dashboard when a visitor signs in.
|
|
77
|
+
|
|
78
|
+
View the other types of handlers [here](docs#handler-functions).
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
// entrySignIn.ts
|
|
82
|
+
import { entryEventHandler } from '@envoy/envoy-integrations-sdk';
|
|
83
|
+
import Config from './defs/Config';
|
|
84
|
+
|
|
85
|
+
export default entryEventHandler<Config>(async (req, res) => {
|
|
86
|
+
const { envoy } = req;
|
|
87
|
+
const { job, meta, payload: visitor } = envoy;
|
|
88
|
+
const hello = `${meta.config.greeting} ${visitor.attributes['full-name']}!`; // our custom greeting
|
|
89
|
+
await job.attach({ label: 'Greeting', value: hello }); // show in the Envoy dashboard.
|
|
90
|
+
res.send({ hello });
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
#### Setup your `express.js` app
|
|
96
|
+
Use the `envoyMiddleware` to get an instance of [EnvoyPluginSDK](docs/classes/envoypluginsdk.md) attached to every request.
|
|
97
|
+
|
|
98
|
+
View the other types of middleware [here](docs#middleware-functions).
|
|
99
|
+
```typescript
|
|
100
|
+
// index.ts
|
|
101
|
+
import express from 'express';
|
|
102
|
+
import { envoyMiddleware, errorMiddleware } from '@envoy/envoy-integrations-sdk';
|
|
103
|
+
|
|
104
|
+
import greetingOptions from './greetingOptions';
|
|
105
|
+
import entrySignIn from './entrySignIn'
|
|
33
106
|
|
|
34
107
|
const app = express();
|
|
108
|
+
app.use(envoyMiddleware());
|
|
109
|
+
app.post('/greeting-options', greetingOptions);
|
|
110
|
+
app.post('/entry-sign-in', entrySignIn);
|
|
111
|
+
app.use(errorMiddleware());
|
|
112
|
+
app.listen(process.env.PORT);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### More examples
|
|
116
|
+
Here's some more things you can do with the `req.envoy` object.
|
|
117
|
+
```typescript
|
|
118
|
+
/**
|
|
119
|
+
* @type EnvoyPluginSDK
|
|
120
|
+
*/
|
|
121
|
+
const { envoy } = req; // "envoy" is the SDK
|
|
122
|
+
const {
|
|
123
|
+
meta, // the platform event request_meta object
|
|
124
|
+
payload, // the platform event request_body object
|
|
125
|
+
userAPI, // user-scoped API calls, used in routes
|
|
126
|
+
pluginAPI, // plugin-scoped API calls, for plugin services
|
|
127
|
+
installStorage, // install-scoped storage
|
|
128
|
+
globalStorage, // global-scoped storage
|
|
129
|
+
job, // update the job (if in an event handler)
|
|
130
|
+
jwt, // helper to encode/decode jwts
|
|
131
|
+
} = envoy;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* User API usage
|
|
135
|
+
*/
|
|
136
|
+
const visitorTypes = await userAPI.getFlows({ filter: { location: '1' } });
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Storage usage
|
|
140
|
+
* The below can be used both at the install level or global level
|
|
141
|
+
*/
|
|
142
|
+
await installStorage.set('foo', 'bar'); // sets foo=bar in storage for this install
|
|
143
|
+
const { value } = await installStorage.get<string>('foo'); // also gets the current value of foo
|
|
144
|
+
const { value } = await installStorage.setUnique('foo'); // creates and returns a unique text value for foo
|
|
145
|
+
const { value } = await installStorage.get<string>('foo'); // also gets the current value of foo
|
|
146
|
+
const { value } = await installStorage.setUniqueNum('foo'); // creates and returns a unique number for foo
|
|
147
|
+
const { value } = await installStorage.get<number>('foo'); // also gets the current value of foo
|
|
148
|
+
await installStorage.unset('foo'); // deletes foo
|
|
35
149
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
150
|
+
* You can also send multiple commands at once,
|
|
151
|
+
* to be executed in the same transaction.
|
|
152
|
+
* The response will be an array of the results of each command, in order.
|
|
39
153
|
*/
|
|
40
|
-
|
|
154
|
+
const results = await installStorage.pipeline().set('foo1', 'bar').unset('foo2').get('foo3').execute();
|
|
41
155
|
|
|
42
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Job updates
|
|
158
|
+
* Note that job.complete can take any number of attachments after the first argument.
|
|
159
|
+
*/
|
|
160
|
+
await job.complete('Credentials provisioned.', { label: 'password', value: 'password' });
|
|
161
|
+
await job.ignore('No credentials provisioned.', 'Email was not supplied.');
|
|
162
|
+
await job.fail('Could not provision credentials.', 'Server could not be reached.');
|
|
163
|
+
/**
|
|
164
|
+
* You can also just attach things without completing the job.
|
|
165
|
+
* Attach more things by providing more arguments.
|
|
166
|
+
*/
|
|
167
|
+
await job.attach({ type: 'text', label: 'foo', value: 'bar' });
|
|
168
|
+
/**
|
|
169
|
+
* If the job is some multi-step process,
|
|
170
|
+
* you can update it's message without changing the status.
|
|
171
|
+
* You can also optionally attach things by providing more arguments.
|
|
172
|
+
*/
|
|
173
|
+
await job.update('Still working...');
|
|
43
174
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Job updates
|
|
82
|
-
* Note that job.complete can take any number of attachments after the first argument.
|
|
83
|
-
*/
|
|
84
|
-
await job.complete('Credentials provisioned.', { label: 'password', value: 'password' });
|
|
85
|
-
await job.ignore('No credentials provisioned.', 'Email was not supplied.');
|
|
86
|
-
await job.fail('Could not provision credentials.', 'Server could not be reached.');
|
|
87
|
-
/**
|
|
88
|
-
* You can also just attach things without completing the job.
|
|
89
|
-
* Attach more things by providing more arguments.
|
|
90
|
-
*/
|
|
91
|
-
await job.attach({ type: 'text', label: 'foo', value: 'bar' });
|
|
92
|
-
/**
|
|
93
|
-
* If the job is some multi-step process,
|
|
94
|
-
* you can update it's message without changing the status.
|
|
95
|
-
* You can also optionally attach things by providing more arguments.
|
|
96
|
-
*/
|
|
97
|
-
await job.update('Still working...');
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* JWT usage
|
|
101
|
-
*/
|
|
102
|
-
const token = await jwt.encode(visitorId, '30m');
|
|
103
|
-
const { sub: visitorId } = await jwt.decode(token);
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* If in a validation URL:
|
|
107
|
-
*/
|
|
108
|
-
res.send({ foo: 'bar' }); // will save foo in the installation config.
|
|
109
|
-
// or
|
|
110
|
-
res.sendFailed('This step has failed validation.'); // prevent the installer from progressing.
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* If in an options URL:
|
|
114
|
-
*/
|
|
115
|
-
res.send([ { label: 'Foo', value: 1 }, { label: 'Bar', value: 2 } ]); // display these options in the dropdown.
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* If in a worker:
|
|
119
|
-
*/
|
|
120
|
-
res.send({ hello: 'world' }); // the job was a success, and here's some data about it.
|
|
121
|
-
// or
|
|
122
|
-
res.sendOngoing({ hello: 'world' }); // the job is still ongoing, but here's some data about it.
|
|
123
|
-
// or
|
|
124
|
-
res.sendIgnored("We're not gonna do this one, sorry.", { hello: 'world' }); // doesnt meet the requirements to continue.
|
|
125
|
-
// or
|
|
126
|
-
res.sendFailed('We tried, but failed.', { hello: 'world' }); // we cant continue with this job.
|
|
127
|
-
|
|
128
|
-
}));
|
|
175
|
+
/**
|
|
176
|
+
* JWT usage
|
|
177
|
+
*/
|
|
178
|
+
const token = await jwt.encode(visitorId, '30m');
|
|
179
|
+
const { sub: visitorId } = await jwt.decode(token);
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* If in a validation route:
|
|
183
|
+
*/
|
|
184
|
+
res.send({ foo: 'bar' }); // will save foo in the installation config.
|
|
185
|
+
// or
|
|
186
|
+
res.sendFailed('This step has failed validation.'); // prevent the installer from progressing.
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* If in an options route:
|
|
190
|
+
*/
|
|
191
|
+
res.send([ { label: 'Foo', value: 1 }, { label: 'Bar', value: 2 } ]); // display these options in the dropdown.
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* If in an event handler:
|
|
195
|
+
*/
|
|
196
|
+
res.send({ hello: 'world' }); // the job was a success, and here's some data about it.
|
|
197
|
+
// or
|
|
198
|
+
res.sendOngoing("We're still working on it.", { hello: 'world' }); // the job is still ongoing, but here's some data about it.
|
|
199
|
+
// or
|
|
200
|
+
res.sendIgnored("We're not gonna do this one, sorry.", { hello: 'world' }); // doesnt meet the requirements to continue.
|
|
201
|
+
// or
|
|
202
|
+
res.sendFailed('We tried, but failed.', { hello: 'world' }); // we cant continue with this job.
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Implement Axios Loggers
|
|
206
|
+
*/
|
|
207
|
+
this.axios.interceptors.request.use(envoyAxiosRequestLogger, envoyAxiosErrorLogger); // Request interceptor
|
|
208
|
+
|
|
209
|
+
this.axios.interceptors.response.use(envoyAxiosResponseLogger, envoyAxiosErrorLogger); // Response interceptor
|
|
129
210
|
|
|
130
|
-
app.use(errorMiddleware());
|
|
131
211
|
```
|
|
132
212
|
|
|
213
|
+
|
|
133
214
|
## SDK Reference
|
|
134
215
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
| Name | Type |
|
|
138
|
-
| :--- | :--- |
|
|
139
|
-
| EnvoyAPI | [EnvoyAPI](envoyapi.md) |
|
|
140
|
-
| EnvoyJWT | [EnvoyJWT](envoyjwt.md) |
|
|
141
|
-
| EnvoyPluginJob | [EnvoyPluginJob](envoypluginjob.md) |
|
|
142
|
-
| EnvoyPluginSDK | [EnvoyPluginSDK](envoypluginsdk.md) |
|
|
143
|
-
| EnvoyPluginStorage | [EnvoyPluginStorage](envoypluginstorage.md) |
|
|
144
|
-
| EnvoyPluginStoragePipeline | [EnvoyPluginStoragePipeline](envoypluginstoragepipeline.md) |
|
|
145
|
-
| EnvoySignatureVerifier | [EnvoySignatureVerifier](envoysignatureverifier.md) |
|
|
146
|
-
| middleware | [middleware](middleware.md) |
|
|
147
|
-
| errorMiddleware | [errorMiddleware](errormiddleware.md) |
|
|
148
|
-
| asyncHandler | [asyncHandler](asynchandler.md) |
|
|
216
|
+
Please see detailed documentation [here](docs/README.md).
|
|
149
217
|
|
|
150
218
|
### Contributing
|
|
151
219
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import DataLoader from 'dataloader';
|
|
2
|
+
import JSONAPIData from '../util/json-api/JSONAPIData';
|
|
3
|
+
interface EnvoyWebDataLoaderKey extends JSONAPIData {
|
|
4
|
+
include?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Make typed API calls to Envoy.
|
|
8
|
+
* Uses a data loader to leverage JSONAPI's "include" functionality.
|
|
9
|
+
* This allows us to save everything that was included in the initial response
|
|
10
|
+
* to be used later without re-fetching from the API.
|
|
11
|
+
*
|
|
12
|
+
* @category Base
|
|
13
|
+
*/
|
|
14
|
+
export default class EnvoyAPI {
|
|
15
|
+
/**
|
|
16
|
+
* HTTP Client with Envoy's defaults.
|
|
17
|
+
*/
|
|
18
|
+
readonly axios: import("axios").AxiosInstance;
|
|
19
|
+
/**
|
|
20
|
+
* A dataloader: https://github.com/graphql/dataloader
|
|
21
|
+
* Will fetch individual resources from the API,
|
|
22
|
+
* unless they exist in cache (which they usually will).
|
|
23
|
+
*/
|
|
24
|
+
protected readonly dataLoader: DataLoader<EnvoyWebDataLoaderKey, any, string>;
|
|
25
|
+
constructor(accessToken: string);
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=EnvoyAPI.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvoyAPI.d.ts","sourceRoot":"","sources":["../../src/base/EnvoyAPI.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,WAAW,MAAM,8BAA8B,CAAC;AAIvD,UAAU,qBAAsB,SAAQ,WAAW;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAWD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B;;OAEG;IACH,QAAQ,CAAC,KAAK,gCAUX;IAEH;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,UAAU,iDAU3B;gBAEU,WAAW,EAAE,MAAM;CA0BhC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var qs_1 = __importDefault(require("qs"));
|
|
43
|
+
var dataloader_1 = __importDefault(require("dataloader"));
|
|
44
|
+
var constants_1 = require("../constants");
|
|
45
|
+
var axiosConstructor_1 = require("../util/axiosConstructor");
|
|
46
|
+
/**
|
|
47
|
+
* Sometimes envoy-web will give us back some relationship data
|
|
48
|
+
* with the "type" set to the relationships name instead of the actual model's name.
|
|
49
|
+
* This mapping allows us to alias those cases.
|
|
50
|
+
*/
|
|
51
|
+
var TYPE_ALIASES = new Map([
|
|
52
|
+
['employee-screening-flows', 'flows'],
|
|
53
|
+
]);
|
|
54
|
+
/**
|
|
55
|
+
* Make typed API calls to Envoy.
|
|
56
|
+
* Uses a data loader to leverage JSONAPI's "include" functionality.
|
|
57
|
+
* This allows us to save everything that was included in the initial response
|
|
58
|
+
* to be used later without re-fetching from the API.
|
|
59
|
+
*
|
|
60
|
+
* @category Base
|
|
61
|
+
*/
|
|
62
|
+
var EnvoyAPI = /** @class */ (function () {
|
|
63
|
+
function EnvoyAPI(accessToken) {
|
|
64
|
+
var _this = this;
|
|
65
|
+
/**
|
|
66
|
+
* HTTP Client with Envoy's defaults.
|
|
67
|
+
*/
|
|
68
|
+
this.axios = axiosConstructor_1.createAxiosClient({
|
|
69
|
+
baseURL: constants_1.envoyBaseURL,
|
|
70
|
+
headers: {
|
|
71
|
+
'Content-Type': 'application/vnd.api+json',
|
|
72
|
+
Accept: 'application/vnd.api+json',
|
|
73
|
+
},
|
|
74
|
+
paramsSerializer: function (params) { return qs_1.default.stringify(params, {
|
|
75
|
+
arrayFormat: 'brackets',
|
|
76
|
+
encode: false,
|
|
77
|
+
}); },
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* A dataloader: https://github.com/graphql/dataloader
|
|
81
|
+
* Will fetch individual resources from the API,
|
|
82
|
+
* unless they exist in cache (which they usually will).
|
|
83
|
+
*/
|
|
84
|
+
this.dataLoader = new dataloader_1.default(function (keys) { return Promise.all(keys.map(function (_a) {
|
|
85
|
+
var type = _a.type, id = _a.id, include = _a.include;
|
|
86
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
87
|
+
var data;
|
|
88
|
+
return __generator(this, function (_b) {
|
|
89
|
+
switch (_b.label) {
|
|
90
|
+
case 0: return [4 /*yield*/, this.axios.get("api/v3/" + type + "/" + id, { params: { include: include } })];
|
|
91
|
+
case 1:
|
|
92
|
+
data = (_b.sent()).data;
|
|
93
|
+
return [2 /*return*/, data.data];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
})); }, {
|
|
98
|
+
cacheKeyFn: function (key) { return key.type + "_" + key.id; },
|
|
99
|
+
});
|
|
100
|
+
this.axios.defaults.headers.authorization = "Bearer " + accessToken;
|
|
101
|
+
/**
|
|
102
|
+
* Saves every model that was "include"ed in the response,
|
|
103
|
+
* which saves us the trouble of fetching related data.
|
|
104
|
+
*/
|
|
105
|
+
this.axios.interceptors.response.use(function (response) {
|
|
106
|
+
var _a = response.data, modelOrModels = _a.data, included = _a.included;
|
|
107
|
+
(included || [])
|
|
108
|
+
.concat(modelOrModels)
|
|
109
|
+
.forEach(function (model) {
|
|
110
|
+
_this.dataLoader.prime({ type: model.type, id: model.id }, model);
|
|
111
|
+
var alias = TYPE_ALIASES.get(model.type);
|
|
112
|
+
if (alias) {
|
|
113
|
+
_this.dataLoader.prime({ type: alias, id: model.id }, model);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return response;
|
|
117
|
+
}, function (error) { return Promise.reject(error); });
|
|
118
|
+
}
|
|
119
|
+
return EnvoyAPI;
|
|
120
|
+
}());
|
|
121
|
+
exports.default = EnvoyAPI;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import EnvoyStorageCommand, { EnvoyStorageSetUniqueNumOptions, EnvoyStorageSetUniqueOptions } from '../internal/EnvoyStorageCommand';
|
|
2
|
+
import EnvoyStorageResult from '../internal/EnvoyStorageResult';
|
|
3
|
+
import EnvoyPluginAPI from '../sdk/EnvoyPluginAPI';
|
|
4
|
+
/**
|
|
5
|
+
* Builds up a request pipeline for submitting storage commands.
|
|
6
|
+
*
|
|
7
|
+
* @category Base
|
|
8
|
+
*/
|
|
9
|
+
export default class EnvoyPluginStoragePipeline {
|
|
10
|
+
protected readonly api: EnvoyPluginAPI;
|
|
11
|
+
readonly installId: string | undefined;
|
|
12
|
+
protected readonly commands: Array<EnvoyStorageCommand>;
|
|
13
|
+
constructor(pluginAPI: EnvoyPluginAPI, installId?: string);
|
|
14
|
+
/**
|
|
15
|
+
* Executes all the commands in the pipeline.
|
|
16
|
+
*/
|
|
17
|
+
execute<Result extends EnvoyStorageResult = EnvoyStorageResult>(): Promise<Array<Result>>;
|
|
18
|
+
/**
|
|
19
|
+
* Executes the pipeline and returns the first result.
|
|
20
|
+
*/
|
|
21
|
+
executeSingle<Result extends EnvoyStorageResult = EnvoyStorageResult>(): Promise<Result>;
|
|
22
|
+
addCommand(command: EnvoyStorageCommand): EnvoyPluginStoragePipeline;
|
|
23
|
+
/**
|
|
24
|
+
* Gets a storage item.
|
|
25
|
+
*/
|
|
26
|
+
get(key: string): EnvoyPluginStoragePipeline;
|
|
27
|
+
/**
|
|
28
|
+
* Sets a value for a storage item,
|
|
29
|
+
* and returns that item.
|
|
30
|
+
*/
|
|
31
|
+
set(key: string, value: unknown): EnvoyPluginStoragePipeline;
|
|
32
|
+
/**
|
|
33
|
+
* Sets a unique value for a storage item,
|
|
34
|
+
* and returns that item.
|
|
35
|
+
*/
|
|
36
|
+
setUnique(key: string, options?: EnvoyStorageSetUniqueOptions): EnvoyPluginStoragePipeline;
|
|
37
|
+
/**
|
|
38
|
+
* Sets a unique number value for a storage item,
|
|
39
|
+
* and returns that item.
|
|
40
|
+
*/
|
|
41
|
+
setUniqueNum(key: string, options?: EnvoyStorageSetUniqueNumOptions): EnvoyPluginStoragePipeline;
|
|
42
|
+
/**
|
|
43
|
+
* Unsets a storage item.
|
|
44
|
+
*/
|
|
45
|
+
unset(key: string): EnvoyPluginStoragePipeline;
|
|
46
|
+
/**
|
|
47
|
+
* Lists storage items.
|
|
48
|
+
*/
|
|
49
|
+
list(page?: number): EnvoyPluginStoragePipeline;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=EnvoyPluginStoragePipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvoyPluginStoragePipeline.d.ts","sourceRoot":"","sources":["../../src/base/EnvoyPluginStoragePipeline.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,EAAE,EAC1B,+BAA+B,EAC/B,4BAA4B,EAC7B,MAAM,iCAAiC,CAAC;AACzC,OAAO,kBAAkB,MAAM,gCAAgC,CAAC;AAChE,OAAO,cAAc,MAAM,uBAAuB,CAAC;AAEnD;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,0BAA0B;IAC7C,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC;IAEvC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAEvC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC;gBAE5C,SAAS,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,MAAM;IAMzD;;OAEG;IACH,OAAO,CAAC,MAAM,SAAS,kBAAkB,GAAG,kBAAkB,KAAK,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAIzF;;OAEG;IACG,aAAa,CAAC,MAAM,SAAS,kBAAkB,GAAG,kBAAkB,KAAK,OAAO,CAAC,MAAM,CAAC;IAK9F,UAAU,CAAC,OAAO,EAAE,mBAAmB,GAAG,0BAA0B;IAKpE;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,0BAA0B;IAI5C;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,0BAA0B;IAI5D;;;OAGG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,4BAAiC,GAAG,0BAA0B;IAI9F;;;OAGG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,+BAAoC,GAAG,0BAA0B;IAUpG;;OAEG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,0BAA0B;IAI9C;;OAEG;IACH,IAAI,CAAC,IAAI,SAAI,GAAG,0BAA0B;CAM3C"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
/**
|
|
51
|
+
* Builds up a request pipeline for submitting storage commands.
|
|
52
|
+
*
|
|
53
|
+
* @category Base
|
|
54
|
+
*/
|
|
55
|
+
var EnvoyPluginStoragePipeline = /** @class */ (function () {
|
|
56
|
+
function EnvoyPluginStoragePipeline(pluginAPI, installId) {
|
|
57
|
+
this.api = pluginAPI;
|
|
58
|
+
this.installId = installId;
|
|
59
|
+
this.commands = [];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Executes all the commands in the pipeline.
|
|
63
|
+
*/
|
|
64
|
+
EnvoyPluginStoragePipeline.prototype.execute = function () {
|
|
65
|
+
return this.api.storagePipeline(this.commands, this.installId);
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Executes the pipeline and returns the first result.
|
|
69
|
+
*/
|
|
70
|
+
EnvoyPluginStoragePipeline.prototype.executeSingle = function () {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
+
var result;
|
|
73
|
+
return __generator(this, function (_a) {
|
|
74
|
+
switch (_a.label) {
|
|
75
|
+
case 0: return [4 /*yield*/, this.execute()];
|
|
76
|
+
case 1:
|
|
77
|
+
result = (_a.sent())[0];
|
|
78
|
+
return [2 /*return*/, result];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
EnvoyPluginStoragePipeline.prototype.addCommand = function (command) {
|
|
84
|
+
this.commands.push(command);
|
|
85
|
+
return this;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Gets a storage item.
|
|
89
|
+
*/
|
|
90
|
+
EnvoyPluginStoragePipeline.prototype.get = function (key) {
|
|
91
|
+
return this.addCommand({ action: 'get', key: key });
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Sets a value for a storage item,
|
|
95
|
+
* and returns that item.
|
|
96
|
+
*/
|
|
97
|
+
EnvoyPluginStoragePipeline.prototype.set = function (key, value) {
|
|
98
|
+
return this.addCommand({ action: 'set', key: key, value: value });
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Sets a unique value for a storage item,
|
|
102
|
+
* and returns that item.
|
|
103
|
+
*/
|
|
104
|
+
EnvoyPluginStoragePipeline.prototype.setUnique = function (key, options) {
|
|
105
|
+
if (options === void 0) { options = {}; }
|
|
106
|
+
return this.addCommand(__assign({ action: 'set_unique', key: key }, options));
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Sets a unique number value for a storage item,
|
|
110
|
+
* and returns that item.
|
|
111
|
+
*/
|
|
112
|
+
EnvoyPluginStoragePipeline.prototype.setUniqueNum = function (key, options) {
|
|
113
|
+
if (options === void 0) { options = {}; }
|
|
114
|
+
if (options.min) {
|
|
115
|
+
options.min = Number(options.min);
|
|
116
|
+
}
|
|
117
|
+
if (options.max) {
|
|
118
|
+
options.max = Number(options.max);
|
|
119
|
+
}
|
|
120
|
+
return this.addCommand(__assign({ action: 'set_unique_num', key: key }, options));
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Unsets a storage item.
|
|
124
|
+
*/
|
|
125
|
+
EnvoyPluginStoragePipeline.prototype.unset = function (key) {
|
|
126
|
+
return this.addCommand({ action: 'unset', key: key });
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Lists storage items.
|
|
130
|
+
*/
|
|
131
|
+
EnvoyPluginStoragePipeline.prototype.list = function (page) {
|
|
132
|
+
if (page === void 0) { page = 1; }
|
|
133
|
+
if (!page) {
|
|
134
|
+
page = 1;
|
|
135
|
+
}
|
|
136
|
+
return this.addCommand({ action: 'list', page: page });
|
|
137
|
+
};
|
|
138
|
+
return EnvoyPluginStoragePipeline;
|
|
139
|
+
}());
|
|
140
|
+
exports.default = EnvoyPluginStoragePipeline;
|