@verdocs/js-sdk 3.1.4 → 3.1.5

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.
@@ -195,3 +195,9 @@ export declare const getEnvelopesByTemplateId: (endpoint: VerdocsEndpoint, templ
195
195
  * for DISPLAY ONLY, are not legally binding documents, and do not contain any encoded metadata from participants.
196
196
  */
197
197
  export declare const getEnvelopeDocumentPageDisplayUri: (endpoint: VerdocsEndpoint, envelopeId: string, documentId: string, page: number) => Promise<string>;
198
+ /**
199
+ * Wrapper for `getEnvelope()` that limits queries to one every 2 seconds per template ID.
200
+ * This is intended for use in component hierarchies that all rely on the same template
201
+ * to avoid unnecessary repeat server calls.
202
+ */
203
+ export declare const throttledGetEnvelope: (endpoint: VerdocsEndpoint, envelopeId: string) => IEnvelope | Promise<IEnvelope>;
@@ -258,3 +258,18 @@ export var getEnvelopesByTemplateId = function (endpoint, templateId) { return _
258
258
  export var getEnvelopeDocumentPageDisplayUri = function (endpoint, envelopeId, documentId, page) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
259
259
  return [2 /*return*/, endpoint.api.get("/envelopes/".concat(envelopeId, "/envelope_documents/").concat(documentId, "/pages/").concat(page, "/image")).then(function (r) { return r.data; })];
260
260
  }); }); };
261
+ var cachedEnvelopes = {};
262
+ /**
263
+ * Wrapper for `getEnvelope()` that limits queries to one every 2 seconds per template ID.
264
+ * This is intended for use in component hierarchies that all rely on the same template
265
+ * to avoid unnecessary repeat server calls.
266
+ */
267
+ export var throttledGetEnvelope = function (endpoint, envelopeId) {
268
+ if (cachedEnvelopes[envelopeId] && cachedEnvelopes[envelopeId].loaded + 2000 < new Date().getTime()) {
269
+ return cachedEnvelopes[envelopeId].envelope;
270
+ }
271
+ return getEnvelope(endpoint, envelopeId).then(function (envelope) {
272
+ cachedEnvelopes[envelopeId] = { loaded: new Date().getTime(), envelope: envelope };
273
+ return envelope;
274
+ });
275
+ };
@@ -122,3 +122,9 @@ export interface IGetTemplateSummaryParams {
122
122
  * ```
123
123
  */
124
124
  export declare const getSummary: (endpoint: VerdocsEndpoint, params?: IGetTemplateSummaryParams) => Promise<ITemplatesSummary>;
125
+ /**
126
+ * Wrapper for `getTemplate()` that limits queries to one every 2 seconds per template ID.
127
+ * This is intended for use in component hierarchies that all rely on the same template
128
+ * to avoid unnecessary repeat server calls.
129
+ */
130
+ export declare const throttledGetTemplate: (endpoint: VerdocsEndpoint, templateId: string) => ITemplate | Promise<ITemplate>;
@@ -162,3 +162,18 @@ export var getSummary = function (endpoint, params) {
162
162
  });
163
163
  });
164
164
  };
165
+ var cachedTemplates = {};
166
+ /**
167
+ * Wrapper for `getTemplate()` that limits queries to one every 2 seconds per template ID.
168
+ * This is intended for use in component hierarchies that all rely on the same template
169
+ * to avoid unnecessary repeat server calls.
170
+ */
171
+ export var throttledGetTemplate = function (endpoint, templateId) {
172
+ if (cachedTemplates[templateId] && cachedTemplates[templateId].loaded + 2000 < new Date().getTime()) {
173
+ return cachedTemplates[templateId].template;
174
+ }
175
+ return getTemplate(endpoint, templateId).then(function (template) {
176
+ cachedTemplates[templateId] = { loaded: new Date().getTime(), template: template };
177
+ return template;
178
+ });
179
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdocs/js-sdk",
3
- "version": "3.1.4",
3
+ "version": "3.1.5",
4
4
  "private": false,
5
5
  "homepage": "https://github.com/Verdocs/js-sdk",
6
6
  "description": "Verdocs JS SDK",