pingen2-sdk-js 0.1.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/LICENSE +28 -0
- package/README.md +415 -0
- package/dist/client.d.ts +30 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +72 -0
- package/dist/client.js.map +1 -0
- package/dist/common/enums/address-position.d.ts +5 -0
- package/dist/common/enums/address-position.d.ts.map +1 -0
- package/dist/common/enums/address-position.js +9 -0
- package/dist/common/enums/address-position.js.map +1 -0
- package/dist/common/enums/delivery-product.d.ts +8 -0
- package/dist/common/enums/delivery-product.d.ts.map +1 -0
- package/dist/common/enums/delivery-product.js +12 -0
- package/dist/common/enums/delivery-product.js.map +1 -0
- package/dist/common/enums/index.d.ts +6 -0
- package/dist/common/enums/index.d.ts.map +1 -0
- package/dist/common/enums/index.js +14 -0
- package/dist/common/enums/index.js.map +1 -0
- package/dist/common/enums/paper-type.d.ts +7 -0
- package/dist/common/enums/paper-type.d.ts.map +1 -0
- package/dist/common/enums/paper-type.js +11 -0
- package/dist/common/enums/paper-type.js.map +1 -0
- package/dist/common/enums/print-mode.d.ts +5 -0
- package/dist/common/enums/print-mode.d.ts.map +1 -0
- package/dist/common/enums/print-mode.js +9 -0
- package/dist/common/enums/print-mode.js.map +1 -0
- package/dist/common/enums/print-spectrum.d.ts +5 -0
- package/dist/common/enums/print-spectrum.d.ts.map +1 -0
- package/dist/common/enums/print-spectrum.js +9 -0
- package/dist/common/enums/print-spectrum.js.map +1 -0
- package/dist/common/index.d.ts +8 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +24 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/json-api.d.ts +37 -0
- package/dist/common/json-api.d.ts.map +1 -0
- package/dist/common/json-api.js +3 -0
- package/dist/common/json-api.js.map +1 -0
- package/dist/common/preset.d.ts +13 -0
- package/dist/common/preset.d.ts.map +1 -0
- package/dist/common/preset.js +20 -0
- package/dist/common/preset.js.map +1 -0
- package/dist/common/relationships.d.ts +20 -0
- package/dist/common/relationships.d.ts.map +1 -0
- package/dist/common/relationships.js +3 -0
- package/dist/common/relationships.js.map +1 -0
- package/dist/common/response.d.ts +12 -0
- package/dist/common/response.d.ts.map +1 -0
- package/dist/common/response.js +77 -0
- package/dist/common/response.js.map +1 -0
- package/dist/common/typed-response.d.ts +29 -0
- package/dist/common/typed-response.d.ts.map +1 -0
- package/dist/common/typed-response.js +3 -0
- package/dist/common/typed-response.js.map +1 -0
- package/dist/common/webhook-event.d.ts +34 -0
- package/dist/common/webhook-event.d.ts.map +1 -0
- package/dist/common/webhook-event.js +3 -0
- package/dist/common/webhook-event.js.map +1 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +16 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +50 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +115 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/oauth.d.ts +17 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +68 -0
- package/dist/oauth.js.map +1 -0
- package/dist/requestor.d.ts +28 -0
- package/dist/requestor.d.ts.map +1 -0
- package/dist/requestor.js +163 -0
- package/dist/requestor.js.map +1 -0
- package/dist/resources/base.d.ts +19 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/base.js +40 -0
- package/dist/resources/base.js.map +1 -0
- package/dist/resources/batches/batches.d.ts +15 -0
- package/dist/resources/batches/batches.d.ts.map +1 -0
- package/dist/resources/batches/batches.js +68 -0
- package/dist/resources/batches/batches.js.map +1 -0
- package/dist/resources/batches/enums.d.ts +39 -0
- package/dist/resources/batches/enums.d.ts.map +1 -0
- package/dist/resources/batches/enums.js +44 -0
- package/dist/resources/batches/enums.js.map +1 -0
- package/dist/resources/batches/response.d.ts +27 -0
- package/dist/resources/batches/response.d.ts.map +1 -0
- package/dist/resources/batches/response.js +3 -0
- package/dist/resources/batches/response.js.map +1 -0
- package/dist/resources/batches/types.d.ts +41 -0
- package/dist/resources/batches/types.d.ts.map +1 -0
- package/dist/resources/batches/types.js +3 -0
- package/dist/resources/batches/types.js.map +1 -0
- package/dist/resources/ebills/ebills.d.ts +13 -0
- package/dist/resources/ebills/ebills.d.ts.map +1 -0
- package/dist/resources/ebills/ebills.js +38 -0
- package/dist/resources/ebills/ebills.js.map +1 -0
- package/dist/resources/ebills/response.d.ts +27 -0
- package/dist/resources/ebills/response.d.ts.map +1 -0
- package/dist/resources/ebills/response.js +3 -0
- package/dist/resources/ebills/response.js.map +1 -0
- package/dist/resources/ebills/types.d.ts +23 -0
- package/dist/resources/ebills/types.d.ts.map +1 -0
- package/dist/resources/ebills/types.js +3 -0
- package/dist/resources/ebills/types.js.map +1 -0
- package/dist/resources/emails/emails.d.ts +13 -0
- package/dist/resources/emails/emails.d.ts.map +1 -0
- package/dist/resources/emails/emails.js +38 -0
- package/dist/resources/emails/emails.js.map +1 -0
- package/dist/resources/emails/response.d.ts +24 -0
- package/dist/resources/emails/response.d.ts.map +1 -0
- package/dist/resources/emails/response.js +3 -0
- package/dist/resources/emails/response.js.map +1 -0
- package/dist/resources/emails/types.d.ts +26 -0
- package/dist/resources/emails/types.d.ts.map +1 -0
- package/dist/resources/emails/types.js +3 -0
- package/dist/resources/emails/types.js.map +1 -0
- package/dist/resources/events/batch-events.d.ts +6 -0
- package/dist/resources/events/batch-events.d.ts.map +1 -0
- package/dist/resources/events/batch-events.js +11 -0
- package/dist/resources/events/batch-events.js.map +1 -0
- package/dist/resources/events/ebill-events.d.ts +6 -0
- package/dist/resources/events/ebill-events.d.ts.map +1 -0
- package/dist/resources/events/ebill-events.js +11 -0
- package/dist/resources/events/ebill-events.js.map +1 -0
- package/dist/resources/events/email-events.d.ts +6 -0
- package/dist/resources/events/email-events.d.ts.map +1 -0
- package/dist/resources/events/email-events.js +11 -0
- package/dist/resources/events/email-events.js.map +1 -0
- package/dist/resources/events/letter-events.d.ts +11 -0
- package/dist/resources/events/letter-events.d.ts.map +1 -0
- package/dist/resources/events/letter-events.js +26 -0
- package/dist/resources/events/letter-events.js.map +1 -0
- package/dist/resources/events/response.d.ts +20 -0
- package/dist/resources/events/response.d.ts.map +1 -0
- package/dist/resources/events/response.js +3 -0
- package/dist/resources/events/response.js.map +1 -0
- package/dist/resources/file-upload.d.ts +17 -0
- package/dist/resources/file-upload.d.ts.map +1 -0
- package/dist/resources/file-upload.js +24 -0
- package/dist/resources/file-upload.js.map +1 -0
- package/dist/resources/index.d.ts +30 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +58 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/letters/letters.d.ts +18 -0
- package/dist/resources/letters/letters.d.ts.map +1 -0
- package/dist/resources/letters/letters.js +88 -0
- package/dist/resources/letters/letters.js.map +1 -0
- package/dist/resources/letters/response.d.ts +35 -0
- package/dist/resources/letters/response.d.ts.map +1 -0
- package/dist/resources/letters/response.js +3 -0
- package/dist/resources/letters/response.js.map +1 -0
- package/dist/resources/letters/types.d.ts +61 -0
- package/dist/resources/letters/types.d.ts.map +1 -0
- package/dist/resources/letters/types.js +3 -0
- package/dist/resources/letters/types.js.map +1 -0
- package/dist/resources/organisations/organisations.d.ts +7 -0
- package/dist/resources/organisations/organisations.d.ts.map +1 -0
- package/dist/resources/organisations/organisations.js +14 -0
- package/dist/resources/organisations/organisations.js.map +1 -0
- package/dist/resources/organisations/response.d.ts +24 -0
- package/dist/resources/organisations/response.d.ts.map +1 -0
- package/dist/resources/organisations/response.js +3 -0
- package/dist/resources/organisations/response.js.map +1 -0
- package/dist/resources/users/response.d.ts +21 -0
- package/dist/resources/users/response.d.ts.map +1 -0
- package/dist/resources/users/response.js +3 -0
- package/dist/resources/users/response.js.map +1 -0
- package/dist/resources/users/user-associations.d.ts +6 -0
- package/dist/resources/users/user-associations.d.ts.map +1 -0
- package/dist/resources/users/user-associations.js +11 -0
- package/dist/resources/users/user-associations.js.map +1 -0
- package/dist/resources/users/users.d.ts +6 -0
- package/dist/resources/users/users.d.ts.map +1 -0
- package/dist/resources/users/users.js +11 -0
- package/dist/resources/users/users.js.map +1 -0
- package/dist/resources/webhooks/enums.d.ts +8 -0
- package/dist/resources/webhooks/enums.d.ts.map +1 -0
- package/dist/resources/webhooks/enums.js +12 -0
- package/dist/resources/webhooks/enums.js.map +1 -0
- package/dist/resources/webhooks/response.d.ts +8 -0
- package/dist/resources/webhooks/response.d.ts.map +1 -0
- package/dist/resources/webhooks/response.js +3 -0
- package/dist/resources/webhooks/response.js.map +1 -0
- package/dist/resources/webhooks/types.d.ts +7 -0
- package/dist/resources/webhooks/types.d.ts.map +1 -0
- package/dist/resources/webhooks/types.js +3 -0
- package/dist/resources/webhooks/types.js.map +1 -0
- package/dist/resources/webhooks/webhooks.d.ts +10 -0
- package/dist/resources/webhooks/webhooks.d.ts.map +1 -0
- package/dist/resources/webhooks/webhooks.js +24 -0
- package/dist/resources/webhooks/webhooks.js.map +1 -0
- package/dist/utils/headers.d.ts +2 -0
- package/dist/utils/headers.d.ts.map +1 -0
- package/dist/utils/headers.js +13 -0
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/idempotency.d.ts +2 -0
- package/dist/utils/idempotency.d.ts.map +1 -0
- package/dist/utils/idempotency.js +8 -0
- package/dist/utils/idempotency.js.map +1 -0
- package/dist/utils/object.d.ts +2 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/object.js +17 -0
- package/dist/utils/object.js.map +1 -0
- package/dist/utils/payload.d.ts +8 -0
- package/dist/utils/payload.d.ts.map +1 -0
- package/dist/utils/payload.js +20 -0
- package/dist/utils/payload.js.map +1 -0
- package/dist/utils/retry.d.ts +6 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +45 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/webhook.d.ts +7 -0
- package/dist/webhook.d.ts.map +1 -0
- package/dist/webhook.js +25 -0
- package/dist/webhook.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,2BAA2B,EAC3B,wBAAwB,EACxB,mBAAmB,EACnB,eAAe,EACf,2BAA2B,EAC3B,8BAA8B,EAC9B,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,6BAA6B,EAC7B,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,KAAK,UAAU,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACxH,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.sleep = exports.computeBackoffMs = exports.shouldAttachIdempotencyKey = exports.isRetryableStatus = exports.newIdempotencyKey = exports.definedOnly = exports.buildJsonApi = exports.constructWebhookEvent = exports.verifyWebhookSignature = exports.OAuth = exports.createPingenError = exports.WebhookSignatureError = exports.ValidationError = exports.AuthenticationError = exports.PingenTimeoutError = exports.PingenServiceUnavailableError = exports.PingenServerError = exports.PingenRateLimitError = exports.PingenDependencyError = exports.PingenUnprocessableEntityError = exports.PingenUnsupportedMediaError = exports.PingenGoneError = exports.PingenConflictError = exports.PingenNotAcceptableError = exports.PingenMethodNotAllowedError = exports.PingenNotFoundError = exports.PingenForbiddenError = exports.PingenUnauthorizedError = exports.PingenBadRequestError = exports.PingenError = exports.ApiRequestor = exports.PingenClient = void 0;
|
|
18
|
+
var client_1 = require("./client");
|
|
19
|
+
Object.defineProperty(exports, "PingenClient", { enumerable: true, get: function () { return client_1.PingenClient; } });
|
|
20
|
+
var requestor_1 = require("./requestor");
|
|
21
|
+
Object.defineProperty(exports, "ApiRequestor", { enumerable: true, get: function () { return requestor_1.ApiRequestor; } });
|
|
22
|
+
var errors_1 = require("./errors");
|
|
23
|
+
Object.defineProperty(exports, "PingenError", { enumerable: true, get: function () { return errors_1.PingenError; } });
|
|
24
|
+
Object.defineProperty(exports, "PingenBadRequestError", { enumerable: true, get: function () { return errors_1.PingenBadRequestError; } });
|
|
25
|
+
Object.defineProperty(exports, "PingenUnauthorizedError", { enumerable: true, get: function () { return errors_1.PingenUnauthorizedError; } });
|
|
26
|
+
Object.defineProperty(exports, "PingenForbiddenError", { enumerable: true, get: function () { return errors_1.PingenForbiddenError; } });
|
|
27
|
+
Object.defineProperty(exports, "PingenNotFoundError", { enumerable: true, get: function () { return errors_1.PingenNotFoundError; } });
|
|
28
|
+
Object.defineProperty(exports, "PingenMethodNotAllowedError", { enumerable: true, get: function () { return errors_1.PingenMethodNotAllowedError; } });
|
|
29
|
+
Object.defineProperty(exports, "PingenNotAcceptableError", { enumerable: true, get: function () { return errors_1.PingenNotAcceptableError; } });
|
|
30
|
+
Object.defineProperty(exports, "PingenConflictError", { enumerable: true, get: function () { return errors_1.PingenConflictError; } });
|
|
31
|
+
Object.defineProperty(exports, "PingenGoneError", { enumerable: true, get: function () { return errors_1.PingenGoneError; } });
|
|
32
|
+
Object.defineProperty(exports, "PingenUnsupportedMediaError", { enumerable: true, get: function () { return errors_1.PingenUnsupportedMediaError; } });
|
|
33
|
+
Object.defineProperty(exports, "PingenUnprocessableEntityError", { enumerable: true, get: function () { return errors_1.PingenUnprocessableEntityError; } });
|
|
34
|
+
Object.defineProperty(exports, "PingenDependencyError", { enumerable: true, get: function () { return errors_1.PingenDependencyError; } });
|
|
35
|
+
Object.defineProperty(exports, "PingenRateLimitError", { enumerable: true, get: function () { return errors_1.PingenRateLimitError; } });
|
|
36
|
+
Object.defineProperty(exports, "PingenServerError", { enumerable: true, get: function () { return errors_1.PingenServerError; } });
|
|
37
|
+
Object.defineProperty(exports, "PingenServiceUnavailableError", { enumerable: true, get: function () { return errors_1.PingenServiceUnavailableError; } });
|
|
38
|
+
Object.defineProperty(exports, "PingenTimeoutError", { enumerable: true, get: function () { return errors_1.PingenTimeoutError; } });
|
|
39
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
|
|
40
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
|
|
41
|
+
Object.defineProperty(exports, "WebhookSignatureError", { enumerable: true, get: function () { return errors_1.WebhookSignatureError; } });
|
|
42
|
+
Object.defineProperty(exports, "createPingenError", { enumerable: true, get: function () { return errors_1.createPingenError; } });
|
|
43
|
+
var oauth_1 = require("./oauth");
|
|
44
|
+
Object.defineProperty(exports, "OAuth", { enumerable: true, get: function () { return oauth_1.OAuth; } });
|
|
45
|
+
var webhook_1 = require("./webhook");
|
|
46
|
+
Object.defineProperty(exports, "verifyWebhookSignature", { enumerable: true, get: function () { return webhook_1.verifyWebhookSignature; } });
|
|
47
|
+
Object.defineProperty(exports, "constructWebhookEvent", { enumerable: true, get: function () { return webhook_1.constructWebhookEvent; } });
|
|
48
|
+
var payload_1 = require("./utils/payload");
|
|
49
|
+
Object.defineProperty(exports, "buildJsonApi", { enumerable: true, get: function () { return payload_1.buildJsonApi; } });
|
|
50
|
+
var object_1 = require("./utils/object");
|
|
51
|
+
Object.defineProperty(exports, "definedOnly", { enumerable: true, get: function () { return object_1.definedOnly; } });
|
|
52
|
+
var idempotency_1 = require("./utils/idempotency");
|
|
53
|
+
Object.defineProperty(exports, "newIdempotencyKey", { enumerable: true, get: function () { return idempotency_1.newIdempotencyKey; } });
|
|
54
|
+
var retry_1 = require("./utils/retry");
|
|
55
|
+
Object.defineProperty(exports, "isRetryableStatus", { enumerable: true, get: function () { return retry_1.isRetryableStatus; } });
|
|
56
|
+
Object.defineProperty(exports, "shouldAttachIdempotencyKey", { enumerable: true, get: function () { return retry_1.shouldAttachIdempotencyKey; } });
|
|
57
|
+
Object.defineProperty(exports, "computeBackoffMs", { enumerable: true, get: function () { return retry_1.computeBackoffMs; } });
|
|
58
|
+
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return retry_1.sleep; } });
|
|
59
|
+
__exportStar(require("./common"), exports);
|
|
60
|
+
__exportStar(require("./resources"), exports);
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAiE;AAAxD,sGAAA,YAAY,OAAA;AACrB,yCAAqE;AAA5D,yGAAA,YAAY,OAAA;AACrB,mCAqBkB;AApBhB,qGAAA,WAAW,OAAA;AACX,+GAAA,qBAAqB,OAAA;AACrB,iHAAA,uBAAuB,OAAA;AACvB,8GAAA,oBAAoB,OAAA;AACpB,6GAAA,mBAAmB,OAAA;AACnB,qHAAA,2BAA2B,OAAA;AAC3B,kHAAA,wBAAwB,OAAA;AACxB,6GAAA,mBAAmB,OAAA;AACnB,yGAAA,eAAe,OAAA;AACf,qHAAA,2BAA2B,OAAA;AAC3B,wHAAA,8BAA8B,OAAA;AAC9B,+GAAA,qBAAqB,OAAA;AACrB,8GAAA,oBAAoB,OAAA;AACpB,2GAAA,iBAAiB,OAAA;AACjB,uHAAA,6BAA6B,OAAA;AAC7B,4GAAA,kBAAkB,OAAA;AAClB,6GAAA,mBAAmB,OAAA;AACnB,yGAAA,eAAe,OAAA;AACf,+GAAA,qBAAqB,OAAA;AACrB,2GAAA,iBAAiB,OAAA;AAEnB,iCAAkD;AAAzC,8FAAA,KAAK,OAAA;AACd,qCAA6F;AAApF,iHAAA,sBAAsB,OAAA;AAAE,gHAAA,qBAAqB,OAAA;AACtD,2CAAqE;AAA5D,uGAAA,YAAY,OAAA;AACrB,yCAA6C;AAApC,qGAAA,WAAW,OAAA;AACpB,mDAAwD;AAA/C,gHAAA,iBAAiB,OAAA;AAC1B,uCAAwH;AAA9F,0GAAA,iBAAiB,OAAA;AAAE,mHAAA,0BAA0B,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,8FAAA,KAAK,OAAA;AAChG,2CAAyB;AACzB,8CAA4B"}
|
package/dist/oauth.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface OAuthConfig {
|
|
2
|
+
clientId: string;
|
|
3
|
+
clientSecret: string;
|
|
4
|
+
useStaging?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class OAuth {
|
|
7
|
+
private readonly clientId;
|
|
8
|
+
private readonly clientSecret;
|
|
9
|
+
private readonly useStaging;
|
|
10
|
+
private cachedToken;
|
|
11
|
+
private pendingRequest;
|
|
12
|
+
constructor(config: OAuthConfig);
|
|
13
|
+
getAccessToken(): Promise<string>;
|
|
14
|
+
invalidate(): void;
|
|
15
|
+
private fetchToken;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAOD,qBAAa,KAAK;IAChB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAU;IACrC,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,cAAc,CAAgC;gBAE1C,MAAM,EAAE,WAAW;IASzB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAavC,UAAU,IAAI,IAAI;YAIJ,UAAU;CAgCzB"}
|
package/dist/oauth.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OAuth = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
class OAuth {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.cachedToken = null;
|
|
9
|
+
this.pendingRequest = null;
|
|
10
|
+
if (!config.clientId || !config.clientSecret) {
|
|
11
|
+
throw new errors_1.AuthenticationError('OAuth requires clientId and clientSecret.');
|
|
12
|
+
}
|
|
13
|
+
this.clientId = config.clientId;
|
|
14
|
+
this.clientSecret = config.clientSecret;
|
|
15
|
+
this.useStaging = config.useStaging ?? false;
|
|
16
|
+
}
|
|
17
|
+
async getAccessToken() {
|
|
18
|
+
if (this.cachedToken && Date.now() < this.cachedToken.expiresAt) {
|
|
19
|
+
return this.cachedToken.accessToken;
|
|
20
|
+
}
|
|
21
|
+
if (this.pendingRequest) {
|
|
22
|
+
return this.pendingRequest;
|
|
23
|
+
}
|
|
24
|
+
this.pendingRequest = this.fetchToken().finally(() => {
|
|
25
|
+
this.pendingRequest = null;
|
|
26
|
+
});
|
|
27
|
+
return this.pendingRequest;
|
|
28
|
+
}
|
|
29
|
+
invalidate() {
|
|
30
|
+
this.cachedToken = null;
|
|
31
|
+
}
|
|
32
|
+
async fetchToken() {
|
|
33
|
+
const base = this.useStaging ? constants_1.API_STAGING : constants_1.API_PRODUCTION;
|
|
34
|
+
const body = new URLSearchParams({
|
|
35
|
+
client_id: this.clientId,
|
|
36
|
+
client_secret: this.clientSecret,
|
|
37
|
+
grant_type: 'client_credentials',
|
|
38
|
+
}).toString();
|
|
39
|
+
let res;
|
|
40
|
+
try {
|
|
41
|
+
res = await fetch(`${base}/auth/access-tokens`, {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
44
|
+
body,
|
|
45
|
+
signal: AbortSignal.timeout(constants_1.DEFAULT_TIMEOUT_MS),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
throw (0, errors_1.classifyFetchError)('Pingen auth request', e);
|
|
50
|
+
}
|
|
51
|
+
if (!res.ok) {
|
|
52
|
+
const text = await res.text();
|
|
53
|
+
throw (0, errors_1.createPingenError)(`Pingen auth endpoint returned ${res.status}: ${text || res.statusText}`, res.status);
|
|
54
|
+
}
|
|
55
|
+
let response;
|
|
56
|
+
try {
|
|
57
|
+
response = (await res.json());
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
throw new errors_1.PingenError('Pingen auth endpoint returned non-JSON body.', res.status);
|
|
61
|
+
}
|
|
62
|
+
const ttlMs = Math.max(0, response.expires_in - constants_1.TOKEN_EXPIRY_BUFFER_SEC) * 1000;
|
|
63
|
+
this.cachedToken = { accessToken: response.access_token, expiresAt: Date.now() + ttlMs };
|
|
64
|
+
return response.access_token;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.OAuth = OAuth;
|
|
68
|
+
//# sourceMappingURL=oauth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.js","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":";;;AAAA,qCAAmG;AACnG,2CAAuG;AAmBvG,MAAa,KAAK;IAOhB,YAAY,MAAmB;QAHvB,gBAAW,GAAuB,IAAI,CAAC;QACvC,mBAAc,GAA2B,IAAI,CAAC;QAGpD,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;YAC7C,MAAM,IAAI,4BAAmB,CAAC,2CAA2C,CAAC,CAAC;QAC7E,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,KAAK,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,G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,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YAC9B,MAAM,IAAA,0BAAiB,EAAC,iCAAiC,GAAG,CAAC,MAAM,KAAK,IAAI,IAAI,GAAG,CAAC,UAAU,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QAChH,CAAC;QACD,IAAI,QAA+B,CAAC;QACpC,IAAI,CAAC;YACH,QAAQ,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAA0B,CAAC;QACzD,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,oBAAW,CAAC,8CAA8C,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QACpF,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,UAAU,GAAG,mCAAuB,CAAC,GAAG,IAAI,CAAC;QAChF,IAAI,CAAC,WAAW,GAAG,EAAE,WAAW,EAAE,QAAQ,CAAC,YAAY,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;QACzF,OAAO,QAAQ,CAAC,YAAY,CAAC;IAC/B,CAAC;CACF;AAjED,sBAiEC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PingenResponse } from './common/response';
|
|
2
|
+
export interface ApiRequestorOptions {
|
|
3
|
+
useStaging?: boolean;
|
|
4
|
+
maxAttempts?: number;
|
|
5
|
+
timeoutMs?: number;
|
|
6
|
+
uploadTimeoutMs?: number;
|
|
7
|
+
on401?: () => Promise<string | undefined>;
|
|
8
|
+
}
|
|
9
|
+
export declare class ApiRequestor {
|
|
10
|
+
private accessToken;
|
|
11
|
+
private readonly apiBase;
|
|
12
|
+
private readonly maxAttempts;
|
|
13
|
+
private readonly timeoutMs;
|
|
14
|
+
private readonly uploadTimeoutMs;
|
|
15
|
+
private readonly on401?;
|
|
16
|
+
constructor(accessToken: string | null, options?: ApiRequestorOptions);
|
|
17
|
+
setAccessToken(accessToken: string): void;
|
|
18
|
+
get(path: string, params?: Record<string, string>, extraHeaders?: Record<string, string>): Promise<PingenResponse>;
|
|
19
|
+
post(path: string, payload: string, extraHeaders?: Record<string, string>): Promise<PingenResponse>;
|
|
20
|
+
patch(path: string, payload?: string, extraHeaders?: Record<string, string>): Promise<PingenResponse>;
|
|
21
|
+
delete(path: string): Promise<PingenResponse>;
|
|
22
|
+
put(url: string, filePath: string): Promise<void>;
|
|
23
|
+
stream(path: string): Promise<string>;
|
|
24
|
+
private buildUrl;
|
|
25
|
+
private defaultHeaders;
|
|
26
|
+
private execute;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=requestor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestor.d.ts","sourceRoot":"","sources":["../src/requestor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAanD,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CAC3C;AAwBD,qBAAa,YAAY;IACvB,OAAO,CAAC,WAAW,CAAgB;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAoC;gBAE/C,WAAW,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,GAAE,mBAAwB;IASzE,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAIzC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;IAIlH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;IAInG,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;IAIrG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAIvC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBjD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAwB3C,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,cAAc;YAeR,OAAO;CAyDtB"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiRequestor = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
const response_1 = require("./common/response");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
const idempotency_1 = require("./utils/idempotency");
|
|
9
|
+
const retry_1 = require("./utils/retry");
|
|
10
|
+
const headers_1 = require("./utils/headers");
|
|
11
|
+
function safeParseJson(body) {
|
|
12
|
+
if (!body) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(body);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return body;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function parseRetryAfterMs(value) {
|
|
23
|
+
if (!value) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const seconds = parseInt(value, 10);
|
|
27
|
+
if (!Number.isFinite(seconds) || seconds <= 0) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return seconds * 1000;
|
|
31
|
+
}
|
|
32
|
+
class ApiRequestor {
|
|
33
|
+
constructor(accessToken, options = {}) {
|
|
34
|
+
this.accessToken = accessToken;
|
|
35
|
+
this.apiBase = options.useStaging ? constants_1.API_STAGING : constants_1.API_PRODUCTION;
|
|
36
|
+
this.maxAttempts = options.maxAttempts ?? constants_1.MAX_RETRY_ATTEMPTS;
|
|
37
|
+
this.timeoutMs = options.timeoutMs ?? constants_1.DEFAULT_TIMEOUT_MS;
|
|
38
|
+
this.uploadTimeoutMs = options.uploadTimeoutMs ?? constants_1.UPLOAD_TIMEOUT_MS;
|
|
39
|
+
this.on401 = options.on401;
|
|
40
|
+
}
|
|
41
|
+
setAccessToken(accessToken) {
|
|
42
|
+
this.accessToken = accessToken;
|
|
43
|
+
}
|
|
44
|
+
get(path, params, extraHeaders) {
|
|
45
|
+
return this.execute('GET', this.buildUrl(path, params), undefined, extraHeaders);
|
|
46
|
+
}
|
|
47
|
+
post(path, payload, extraHeaders) {
|
|
48
|
+
return this.execute('POST', this.apiBase + path, payload, extraHeaders);
|
|
49
|
+
}
|
|
50
|
+
patch(path, payload, extraHeaders) {
|
|
51
|
+
return this.execute('PATCH', this.apiBase + path, payload, extraHeaders);
|
|
52
|
+
}
|
|
53
|
+
delete(path) {
|
|
54
|
+
return this.execute('DELETE', this.apiBase + path, undefined);
|
|
55
|
+
}
|
|
56
|
+
async put(url, filePath) {
|
|
57
|
+
const fileBuffer = await fs_1.promises.readFile(filePath);
|
|
58
|
+
let res;
|
|
59
|
+
try {
|
|
60
|
+
res = await fetch(url, {
|
|
61
|
+
method: 'PUT',
|
|
62
|
+
body: fileBuffer,
|
|
63
|
+
signal: AbortSignal.timeout(this.uploadTimeoutMs),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
throw (0, errors_1.classifyFetchError)('File upload to signed URL', e);
|
|
68
|
+
}
|
|
69
|
+
if (!res.ok) {
|
|
70
|
+
const respBody = await res.text();
|
|
71
|
+
const respHeaders = (0, headers_1.headersToRecord)(res.headers);
|
|
72
|
+
throw (0, errors_1.createPingenError)(`File upload to signed URL failed (status ${res.status}).`, res.status, safeParseJson(respBody), respHeaders['x-request-id'], parseRetryAfterMs(respHeaders['retry-after']));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async stream(path) {
|
|
76
|
+
let res;
|
|
77
|
+
try {
|
|
78
|
+
res = await fetch(this.buildUrl(path), {
|
|
79
|
+
headers: this.defaultHeaders(false),
|
|
80
|
+
signal: AbortSignal.timeout(this.uploadTimeoutMs),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
throw (0, errors_1.classifyFetchError)('File download', e);
|
|
85
|
+
}
|
|
86
|
+
const body = await res.text();
|
|
87
|
+
if (!res.ok) {
|
|
88
|
+
const respHeaders = (0, headers_1.headersToRecord)(res.headers);
|
|
89
|
+
throw (0, errors_1.createPingenError)(`File download failed (status ${res.status}).`, res.status, safeParseJson(body), respHeaders['x-request-id'], parseRetryAfterMs(respHeaders['retry-after']));
|
|
90
|
+
}
|
|
91
|
+
return body;
|
|
92
|
+
}
|
|
93
|
+
buildUrl(path, params) {
|
|
94
|
+
const url = new URL(this.apiBase + path);
|
|
95
|
+
if (params) {
|
|
96
|
+
for (const [name, value] of Object.entries(params))
|
|
97
|
+
url.searchParams.set(name, value);
|
|
98
|
+
}
|
|
99
|
+
return url.toString();
|
|
100
|
+
}
|
|
101
|
+
defaultHeaders(hasBody, extra = {}) {
|
|
102
|
+
const headers = {
|
|
103
|
+
'User-Agent': constants_1.USER_AGENT,
|
|
104
|
+
Accept: 'application/vnd.api+json',
|
|
105
|
+
...extra,
|
|
106
|
+
};
|
|
107
|
+
if (hasBody) {
|
|
108
|
+
headers['Content-Type'] = 'application/vnd.api+json';
|
|
109
|
+
}
|
|
110
|
+
if (this.accessToken) {
|
|
111
|
+
headers.Authorization = `Bearer ${this.accessToken}`;
|
|
112
|
+
}
|
|
113
|
+
return headers;
|
|
114
|
+
}
|
|
115
|
+
async execute(method, url, body, extra) {
|
|
116
|
+
const idempotencyKey = (0, retry_1.shouldAttachIdempotencyKey)(method) ? (0, idempotency_1.newIdempotencyKey)() : undefined;
|
|
117
|
+
let refreshed = false;
|
|
118
|
+
let attempt = 0;
|
|
119
|
+
// Infinite loop pattern: every path either returns (2xx), throws (terminal/non-retryable
|
|
120
|
+
// status, hit retry budget, or fetch network error), or `continue`s without incrementing
|
|
121
|
+
// (one-time 401-driven token refresh, which is orthogonal to the retry budget). This way
|
|
122
|
+
// there's no "unreachable" tail line to silence.
|
|
123
|
+
for (;;) {
|
|
124
|
+
const headers = this.defaultHeaders(body !== undefined, extra);
|
|
125
|
+
if (idempotencyKey && !headers['Idempotency-Key']) {
|
|
126
|
+
headers['Idempotency-Key'] = idempotencyKey;
|
|
127
|
+
}
|
|
128
|
+
let res;
|
|
129
|
+
try {
|
|
130
|
+
res = await fetch(url, {
|
|
131
|
+
method,
|
|
132
|
+
headers,
|
|
133
|
+
body,
|
|
134
|
+
signal: AbortSignal.timeout(this.timeoutMs),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
throw (0, errors_1.classifyFetchError)(`Pingen API ${method} ${url}`, e);
|
|
139
|
+
}
|
|
140
|
+
const respBody = await res.text();
|
|
141
|
+
const respHeaders = (0, headers_1.headersToRecord)(res.headers);
|
|
142
|
+
if (res.status >= 200 && res.status < 300) {
|
|
143
|
+
return new response_1.PingenResponse(respBody, res.status, respHeaders);
|
|
144
|
+
}
|
|
145
|
+
if (res.status === 401 && !refreshed && this.on401) {
|
|
146
|
+
const fresh = await this.on401();
|
|
147
|
+
refreshed = true;
|
|
148
|
+
if (fresh) {
|
|
149
|
+
this.accessToken = fresh;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const lastAttempt = attempt >= this.maxAttempts - 1;
|
|
154
|
+
if (lastAttempt || !(0, retry_1.isRetryableStatus)(method, res.status)) {
|
|
155
|
+
throw (0, errors_1.createPingenError)(`Pingen API returned ${res.status}.`, res.status, safeParseJson(respBody), respHeaders['x-request-id'], parseRetryAfterMs(respHeaders['retry-after']));
|
|
156
|
+
}
|
|
157
|
+
await (0, retry_1.sleep)((0, retry_1.computeBackoffMs)(respHeaders['retry-after'], attempt));
|
|
158
|
+
attempt++;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.ApiRequestor = ApiRequestor;
|
|
163
|
+
//# sourceMappingURL=requestor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestor.js","sourceRoot":"","sources":["../src/requestor.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AACpC,qCAAiE;AACjE,gDAAmD;AACnD,2CAOqB;AACrB,qDAAwD;AACxD,yCAAmH;AACnH,6CAAkD;AAUlD,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAyB;IAClD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,EAA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pload } from './file-upload';
|
|
3
|
+
export declare abstract class BaseResource {
|
|
4
|
+
protected readonly requestor: ApiRequestor;
|
|
5
|
+
constructor(requestor: ApiRequestor);
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class OrgResource {
|
|
8
|
+
protected readonly orgId: string;
|
|
9
|
+
protected readonly requestor: ApiRequestor;
|
|
10
|
+
constructor(orgId: string, requestor: ApiRequestor);
|
|
11
|
+
protected uploadFile(filePath: string): Promise<SignedUpload>;
|
|
12
|
+
protected uploadAndCall<U extends {
|
|
13
|
+
filePath: string;
|
|
14
|
+
}, R>(opts: U, create: (rest: Omit<U, 'filePath'> & {
|
|
15
|
+
fileUrl: string;
|
|
16
|
+
fileSignature: string;
|
|
17
|
+
}) => Promise<R>): Promise<R>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/resources/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAc,YAAY,EAAE,MAAM,eAAe,CAAC;AAKzD,8BAAsB,YAAY;IACpB,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,YAAY;gBAAvB,SAAS,EAAE,YAAY;CACvD;AAED,8BAAsB,WAAW;IAE7B,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;IAChC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,YAAY;gBADvB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,YAAY;IAM5C,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;cAY7C,aAAa,CAAC,CAAC,SAAS;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC,EAC7D,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,CAAC,CAAC,GAC7F,OAAO,CAAC,CAAC,CAAC;CAQd"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OrgResource = exports.BaseResource = void 0;
|
|
4
|
+
const file_upload_1 = require("./file-upload");
|
|
5
|
+
// Resources accept a pre-built ApiRequestor only. Direct token-based instantiation goes
|
|
6
|
+
// through the static `withToken` factory — this keeps the constructor signature unambiguous
|
|
7
|
+
// and lets PingenClient share a single requestor across all resources.
|
|
8
|
+
class BaseResource {
|
|
9
|
+
constructor(requestor) {
|
|
10
|
+
this.requestor = requestor;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.BaseResource = BaseResource;
|
|
14
|
+
class OrgResource {
|
|
15
|
+
constructor(orgId, requestor) {
|
|
16
|
+
this.orgId = orgId;
|
|
17
|
+
this.requestor = requestor;
|
|
18
|
+
}
|
|
19
|
+
// Shared upload flow used by Letters/Batches/Ebills/Emails. Requests a signed URL, PUTs the
|
|
20
|
+
// file to it, and returns the URL + signature so the caller can attach them to its create()
|
|
21
|
+
// call. Throws if the signed-URL upload fails (see ApiRequestor.put).
|
|
22
|
+
uploadFile(filePath) {
|
|
23
|
+
const fu = new file_upload_1.FileUpload(this.requestor);
|
|
24
|
+
return fu.requestFileUpload().then(async (signed) => {
|
|
25
|
+
await fu.putFile(filePath, signed.url);
|
|
26
|
+
return signed;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// Shared "upload then create" flow: takes upload options containing `filePath`, runs the
|
|
30
|
+
// signed-URL upload, then forwards the rest to the resource-specific `create` step with
|
|
31
|
+
// fileUrl/fileSignature attached. Each resource keeps its own typed Create/Upload pair —
|
|
32
|
+
// this helper just removes the four-line boilerplate that used to live in every subclass.
|
|
33
|
+
async uploadAndCall(opts, create) {
|
|
34
|
+
const { url, signature } = await this.uploadFile(opts.filePath);
|
|
35
|
+
const { filePath: _filePath, ...rest } = opts;
|
|
36
|
+
return create({ ...rest, fileUrl: url, fileSignature: signature });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.OrgResource = OrgResource;
|
|
40
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/resources/base.ts"],"names":[],"mappings":";;;AACA,+CAAyD;AAEzD,wFAAwF;AACxF,4FAA4F;AAC5F,uEAAuE;AACvE,MAAsB,YAAY;IAChC,YAA+B,SAAuB;QAAvB,cAAS,GAAT,SAAS,CAAc;IAAG,CAAC;CAC3D;AAFD,oCAEC;AAED,MAAsB,WAAW;IAC/B,YACqB,KAAa,EACb,SAAuB;QADvB,UAAK,GAAL,KAAK,CAAQ;QACb,cAAS,GAAT,SAAS,CAAc;IACzC,CAAC;IAEJ,4FAA4F;IAC5F,4FAA4F;IAC5F,sEAAsE;IAC5D,UAAU,CAAC,QAAgB;QACnC,MAAM,EAAE,GAAG,IAAI,wBAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1C,OAAO,EAAE,CAAC,iBAAiB,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YAClD,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;YACvC,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,yFAAyF;IACzF,wFAAwF;IACxF,yFAAyF;IACzF,0FAA0F;IAChF,KAAK,CAAC,aAAa,CAC3B,IAAO,EACP,MAA8F;QAE9F,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QAC9C,OAAO,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,SAAS,EAG9D,CAAC,CAAC;IACL,CAAC;CACF;AAhCD,kCAgCC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PingenResponse } from '../../common/response';
|
|
2
|
+
import { OrgResource } from '../base';
|
|
3
|
+
import { BatchCreateOptions, BatchUploadOptions, BatchSendOptions, BatchEditOptions } from './types';
|
|
4
|
+
export declare class Batches extends OrgResource {
|
|
5
|
+
getDetails(batchId: string, params?: Record<string, string>): Promise<PingenResponse>;
|
|
6
|
+
getCollection(params?: Record<string, string>): Promise<PingenResponse>;
|
|
7
|
+
uploadAndCreate(opts: BatchUploadOptions): Promise<PingenResponse>;
|
|
8
|
+
create(opts: BatchCreateOptions): Promise<PingenResponse>;
|
|
9
|
+
send(opts: BatchSendOptions): Promise<PingenResponse>;
|
|
10
|
+
cancel(batchId: string): Promise<PingenResponse>;
|
|
11
|
+
delete(batchId: string): Promise<PingenResponse>;
|
|
12
|
+
edit(batchId: string, opts: BatchEditOptions): Promise<PingenResponse>;
|
|
13
|
+
getStatistics(batchId: string): Promise<PingenResponse>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=batches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batches.d.ts","sourceRoot":"","sources":["../../../src/resources/batches/batches.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAKrG,qBAAa,OAAQ,SAAQ,WAAW;IACtC,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;IAIrF,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;IAIvE,eAAe,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IAIlE,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IAoBzD,IAAI,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC;IAerD,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAIhD,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAIhD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC;IActE,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;CAGxD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Batches = void 0;
|
|
4
|
+
const errors_1 = require("../../errors");
|
|
5
|
+
const base_1 = require("../base");
|
|
6
|
+
const payload_1 = require("../../utils/payload");
|
|
7
|
+
const object_1 = require("../../utils/object");
|
|
8
|
+
const BATCH_NAME_MIN = 5;
|
|
9
|
+
const BATCH_NAME_MAX = 100;
|
|
10
|
+
class Batches extends base_1.OrgResource {
|
|
11
|
+
getDetails(batchId, params) {
|
|
12
|
+
return this.requestor.get(`/organisations/${this.orgId}/batches/${batchId}`, params);
|
|
13
|
+
}
|
|
14
|
+
getCollection(params) {
|
|
15
|
+
return this.requestor.get(`/organisations/${this.orgId}/batches`, params);
|
|
16
|
+
}
|
|
17
|
+
uploadAndCreate(opts) {
|
|
18
|
+
return this.uploadAndCall(opts, (rest) => this.create(rest));
|
|
19
|
+
}
|
|
20
|
+
create(opts) {
|
|
21
|
+
const attributes = (0, object_1.definedOnly)({
|
|
22
|
+
file_url: opts.fileUrl,
|
|
23
|
+
file_url_signature: opts.fileSignature,
|
|
24
|
+
name: opts.name,
|
|
25
|
+
icon: opts.icon,
|
|
26
|
+
file_original_name: opts.fileOriginalName,
|
|
27
|
+
address_position: opts.addressPosition,
|
|
28
|
+
grouping_type: opts.groupingType,
|
|
29
|
+
grouping_options_split_type: opts.splitType,
|
|
30
|
+
grouping_options_split_size: opts.splitSize,
|
|
31
|
+
grouping_options_split_separator: opts.splitSeparator,
|
|
32
|
+
grouping_options_split_position: opts.splitPosition,
|
|
33
|
+
});
|
|
34
|
+
return this.requestor.post(`/organisations/${this.orgId}/batches`, (0, payload_1.buildJsonApi)({ type: 'batches', attributes, relationships: opts.preset?.toValue() }));
|
|
35
|
+
}
|
|
36
|
+
send(opts) {
|
|
37
|
+
return this.requestor.patch(`/organisations/${this.orgId}/batches/${opts.batchId}/send`, (0, payload_1.buildJsonApi)({
|
|
38
|
+
type: 'batches',
|
|
39
|
+
id: opts.batchId,
|
|
40
|
+
attributes: {
|
|
41
|
+
delivery_products: opts.deliveryProducts,
|
|
42
|
+
print_mode: opts.printMode,
|
|
43
|
+
print_spectrum: opts.printSpectrum,
|
|
44
|
+
},
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
cancel(batchId) {
|
|
48
|
+
return this.requestor.patch(`/organisations/${this.orgId}/batches/${batchId}/cancel`);
|
|
49
|
+
}
|
|
50
|
+
delete(batchId) {
|
|
51
|
+
return this.requestor.delete(`/organisations/${this.orgId}/batches/${batchId}`);
|
|
52
|
+
}
|
|
53
|
+
edit(batchId, opts) {
|
|
54
|
+
if (opts.name !== undefined && (opts.name.length < BATCH_NAME_MIN || opts.name.length > BATCH_NAME_MAX)) {
|
|
55
|
+
throw new errors_1.ValidationError('name', `name must be between ${BATCH_NAME_MIN} and ${BATCH_NAME_MAX} characters`);
|
|
56
|
+
}
|
|
57
|
+
return this.requestor.patch(`/organisations/${this.orgId}/batches/${batchId}`, (0, payload_1.buildJsonApi)({
|
|
58
|
+
type: 'batches',
|
|
59
|
+
id: batchId,
|
|
60
|
+
attributes: (0, object_1.definedOnly)({ name: opts.name, icon: opts.icon }),
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
getStatistics(batchId) {
|
|
64
|
+
return this.requestor.get(`/organisations/${this.orgId}/batches/${batchId}/statistics`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.Batches = Batches;
|
|
68
|
+
//# sourceMappingURL=batches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batches.js","sourceRoot":"","sources":["../../../src/resources/batches/batches.ts"],"names":[],"mappings":";;;AACA,yCAA+C;AAC/C,kCAAsC;AACtC,iDAAmD;AACnD,+CAAiD;AAGjD,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B,MAAa,OAAQ,SAAQ,kBAAW;IACtC,UAAU,CAAC,OAAe,EAAE,MAA+B;QACzD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,KAAK,YAAY,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;IACvF,CAAC;IAED,aAAa,CAAC,MAA+B;QAC3C,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,KAAK,UAAU,EAAE,MAAM,CAAC,CAAC;IAC5E,CAAC;IAED,eAAe,CAAC,IAAwB;QACtC,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,CAA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AAC;IACxF,CAAC;IAED,MAAM,CAAC,OAAe;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,IAAI,CAAC,KAAK,YAAY,OAAO,EAAE,CAAC,CAAC;IAClF,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,IAAsB;QAC1C,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,cAAc,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,EAAE,CAAC;YACxG,MAAM,IAAI,wBAAe,CAAC,MAAM,EAAE,wBAAwB,cAAc,QAAQ,cAAc,aAAa,CAAC,CAAC;QAC/G,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CACzB,kBAAkB,IAAI,CAAC,KAAK,YAAY,OAAO,EAAE,EACjD,IAAA,sBAAY,EAAC;YACX,IAAI,EAAE,SAAS;YACf,EAAE,EAAE,OAAO;YACX,UAAU,EAAE,IAAA,oBAAW,EAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;SAC9D,CAAC,CACH,CAAC;IACJ,CAAC;IAED,aAAa,CAAC,OAAe;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,KAAK,YAAY,OAAO,aAAa,CAAC,CAAC;IAC1F,CAAC;CACF;AAzED,0BAyEC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DeliveryProduct } from '../../common/enums';
|
|
2
|
+
export declare enum BatchIcon {
|
|
3
|
+
Campaign = "campaign",
|
|
4
|
+
Megaphone = "megaphone",
|
|
5
|
+
WaveHand = "wave-hand",
|
|
6
|
+
Flash = "flash",
|
|
7
|
+
Rocket = "rocket",
|
|
8
|
+
Bell = "bell",
|
|
9
|
+
PercentTag = "percent-tag",
|
|
10
|
+
PercentBadge = "percent-badge",
|
|
11
|
+
Present = "present",
|
|
12
|
+
Receipt = "receipt",
|
|
13
|
+
Document = "document",
|
|
14
|
+
Information = "information",
|
|
15
|
+
Calendar = "calendar",
|
|
16
|
+
Newspaper = "newspaper",
|
|
17
|
+
Crown = "crown",
|
|
18
|
+
Virus = "virus"
|
|
19
|
+
}
|
|
20
|
+
export declare enum GroupingType {
|
|
21
|
+
Merge = "merge",
|
|
22
|
+
Zip = "zip"
|
|
23
|
+
}
|
|
24
|
+
export declare enum SplitType {
|
|
25
|
+
File = "file",
|
|
26
|
+
Page = "page",
|
|
27
|
+
Custom = "custom",
|
|
28
|
+
QrInvoice = "qr_invoice"
|
|
29
|
+
}
|
|
30
|
+
export declare enum SplitPosition {
|
|
31
|
+
FirstPage = "first_page",
|
|
32
|
+
LastPage = "last_page"
|
|
33
|
+
}
|
|
34
|
+
export interface BatchDeliveryProduct {
|
|
35
|
+
country: string;
|
|
36
|
+
delivery_product: string;
|
|
37
|
+
}
|
|
38
|
+
export declare function createBatchDeliveryProduct(country: string, deliveryProduct: DeliveryProduct): BatchDeliveryProduct;
|
|
39
|
+
//# sourceMappingURL=enums.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../../src/resources/batches/enums.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,oBAAY,SAAS;IACnB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,QAAQ,cAAc;IACtB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,UAAU,gBAAgB;IAC1B,YAAY,kBAAkB;IAC9B,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,KAAK,UAAU;IACf,KAAK,UAAU;CAChB;AAED,oBAAY,YAAY;IACtB,KAAK,UAAU;IACf,GAAG,QAAQ;CACZ;AAED,oBAAY,SAAS;IACnB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,SAAS,eAAe;CACzB;AAED,oBAAY,aAAa;IACvB,SAAS,eAAe;IACxB,QAAQ,cAAc;CACvB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,eAAe,GAAG,oBAAoB,CAElH"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SplitPosition = exports.SplitType = exports.GroupingType = exports.BatchIcon = void 0;
|
|
4
|
+
exports.createBatchDeliveryProduct = createBatchDeliveryProduct;
|
|
5
|
+
var BatchIcon;
|
|
6
|
+
(function (BatchIcon) {
|
|
7
|
+
BatchIcon["Campaign"] = "campaign";
|
|
8
|
+
BatchIcon["Megaphone"] = "megaphone";
|
|
9
|
+
BatchIcon["WaveHand"] = "wave-hand";
|
|
10
|
+
BatchIcon["Flash"] = "flash";
|
|
11
|
+
BatchIcon["Rocket"] = "rocket";
|
|
12
|
+
BatchIcon["Bell"] = "bell";
|
|
13
|
+
BatchIcon["PercentTag"] = "percent-tag";
|
|
14
|
+
BatchIcon["PercentBadge"] = "percent-badge";
|
|
15
|
+
BatchIcon["Present"] = "present";
|
|
16
|
+
BatchIcon["Receipt"] = "receipt";
|
|
17
|
+
BatchIcon["Document"] = "document";
|
|
18
|
+
BatchIcon["Information"] = "information";
|
|
19
|
+
BatchIcon["Calendar"] = "calendar";
|
|
20
|
+
BatchIcon["Newspaper"] = "newspaper";
|
|
21
|
+
BatchIcon["Crown"] = "crown";
|
|
22
|
+
BatchIcon["Virus"] = "virus";
|
|
23
|
+
})(BatchIcon || (exports.BatchIcon = BatchIcon = {}));
|
|
24
|
+
var GroupingType;
|
|
25
|
+
(function (GroupingType) {
|
|
26
|
+
GroupingType["Merge"] = "merge";
|
|
27
|
+
GroupingType["Zip"] = "zip";
|
|
28
|
+
})(GroupingType || (exports.GroupingType = GroupingType = {}));
|
|
29
|
+
var SplitType;
|
|
30
|
+
(function (SplitType) {
|
|
31
|
+
SplitType["File"] = "file";
|
|
32
|
+
SplitType["Page"] = "page";
|
|
33
|
+
SplitType["Custom"] = "custom";
|
|
34
|
+
SplitType["QrInvoice"] = "qr_invoice";
|
|
35
|
+
})(SplitType || (exports.SplitType = SplitType = {}));
|
|
36
|
+
var SplitPosition;
|
|
37
|
+
(function (SplitPosition) {
|
|
38
|
+
SplitPosition["FirstPage"] = "first_page";
|
|
39
|
+
SplitPosition["LastPage"] = "last_page";
|
|
40
|
+
})(SplitPosition || (exports.SplitPosition = SplitPosition = {}));
|
|
41
|
+
function createBatchDeliveryProduct(country, deliveryProduct) {
|
|
42
|
+
return { country, delivery_product: deliveryProduct };
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=enums.js.map
|