@segment/actions-shared 1.115.0 → 1.115.1-extensible-destination-http.0

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.
@@ -0,0 +1,23 @@
1
+ export declare enum CachedResponseType {
2
+ Success = 0,
3
+ Error = 1
4
+ }
5
+ export declare class CachedValueSerializationError extends Error {
6
+ constructor(message: string);
7
+ }
8
+ export declare class CachedValue {
9
+ status: number;
10
+ type: CachedResponseType;
11
+ protected seperator: string;
12
+ constructor(status: number);
13
+ serialize(): string;
14
+ }
15
+ export declare class CachedError extends CachedValue {
16
+ message: string;
17
+ code: string;
18
+ constructor(status: number, message: string, code: string);
19
+ serialize(): string;
20
+ }
21
+ export declare class CachedValueFactory {
22
+ static fromString(value: string): CachedValue | CachedError;
23
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CachedValueFactory = exports.CachedError = exports.CachedValue = exports.CachedValueSerializationError = exports.CachedResponseType = void 0;
4
+ var CachedResponseType;
5
+ (function (CachedResponseType) {
6
+ CachedResponseType[CachedResponseType["Success"] = 0] = "Success";
7
+ CachedResponseType[CachedResponseType["Error"] = 1] = "Error";
8
+ })(CachedResponseType = exports.CachedResponseType || (exports.CachedResponseType = {}));
9
+ class CachedValueSerializationError extends Error {
10
+ constructor(message) {
11
+ super(message);
12
+ this.name = 'CachedValueSerializationError';
13
+ }
14
+ }
15
+ exports.CachedValueSerializationError = CachedValueSerializationError;
16
+ class CachedValue {
17
+ constructor(status) {
18
+ this.seperator = ':-:';
19
+ this.status = status;
20
+ this.type = CachedResponseType.Success;
21
+ }
22
+ serialize() {
23
+ return `${this.type}${this.seperator}${this.status}`;
24
+ }
25
+ }
26
+ exports.CachedValue = CachedValue;
27
+ class CachedError extends CachedValue {
28
+ constructor(status, message, code) {
29
+ super(status);
30
+ this.type = CachedResponseType.Error;
31
+ this.code = code;
32
+ this.message = message;
33
+ }
34
+ serialize() {
35
+ return `${super.serialize()}${this.seperator}${this.message}${this.seperator}${this.code}`;
36
+ }
37
+ }
38
+ exports.CachedError = CachedError;
39
+ class CachedValueFactory {
40
+ static fromString(value) {
41
+ const parts = value.split(':-:');
42
+ if (parts.length < 2) {
43
+ throw new CachedValueSerializationError(`Invalid cached value ${value}`);
44
+ }
45
+ const [type, status] = parts;
46
+ if (CachedResponseType.Success === +type) {
47
+ return new CachedValue(+status);
48
+ }
49
+ else if (CachedResponseType.Error === +type) {
50
+ if (parts.length < 4) {
51
+ throw new CachedValueSerializationError(`Invalid cached value ${value}`);
52
+ }
53
+ const [message, code] = parts.slice(2);
54
+ return new CachedError(+status, message, code);
55
+ }
56
+ else {
57
+ throw new CachedValueSerializationError(`Invalid cached value ${value}`);
58
+ }
59
+ }
60
+ }
61
+ exports.CachedValueFactory = CachedValueFactory;
62
+ //# sourceMappingURL=CachedResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CachedResponse.js","sourceRoot":"","sources":["../../../src/engage/utils/CachedResponse.ts"],"names":[],"mappings":";;;AAAA,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,iEAAW,CAAA;IACX,6DAAS,CAAA;AACX,CAAC,EAHW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAG7B;AAED,MAAa,6BAA8B,SAAQ,KAAK;IACtD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAA;IAC7C,CAAC;CACF;AALD,sEAKC;AAED,MAAa,WAAW;IAKtB,YAAY,MAAc;QAFhB,cAAS,GAAG,KAAK,CAAA;QAGzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC,OAAO,CAAA;IACxC,CAAC;IAED,SAAS;QACP,OAAO,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,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,OAAO,EAAE,IAAI,CAAC,CAAA;SAC/C;aAAM;YACL,MAAM,IAAI,6BAA6B,CAAC,wBAAwB,KAAK,EAAE,CAAC,CAAA;SACzE;IACH,CAAC;CACF;AAnBD,gDAmBC"}
@@ -0,0 +1 @@
1
+ export declare function delay(ms: number): Promise<void>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.delay = void 0;
4
+ async function delay(ms) {
5
+ return new Promise((resolve) => {
6
+ setTimeout(() => {
7
+ resolve();
8
+ }, ms);
9
+ });
10
+ }
11
+ exports.delay = delay;
12
+ //# sourceMappingURL=delay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delay.js","sourceRoot":"","sources":["../../../src/engage/utils/delay.ts"],"names":[],"mappings":";;;AAAO,KAAK,UAAU,KAAK,CAAC,EAAU;IACpC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,GAAG,EAAE;YACd,OAAO,EAAE,CAAA;QACX,CAAC,EAAE,EAAE,CAAC,CAAA;IACR,CAAC,CAAC,CAAA;AACJ,CAAC;AAND,sBAMC"}
@@ -0,0 +1,6 @@
1
+ export declare type ValueOrError<T> = {
2
+ value?: T;
3
+ error?: any;
4
+ };
5
+ export declare function getOrCatch<T>(getValue: () => Promise<T>): Promise<ValueOrError<T>>;
6
+ export declare function getOrCatch<T>(getValue: () => T): ValueOrError<T>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOrCatch = void 0;
4
+ function getOrCatch(getValue) {
5
+ try {
6
+ const value = getValue();
7
+ if (value instanceof Promise) {
8
+ return value.then((value) => ({ value })).catch((error) => ({ error }));
9
+ }
10
+ else {
11
+ return { value };
12
+ }
13
+ }
14
+ catch (error) {
15
+ return { error };
16
+ }
17
+ }
18
+ exports.getOrCatch = getOrCatch;
19
+ //# sourceMappingURL=getOrCatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getOrCatch.js","sourceRoot":"","sources":["../../../src/engage/utils/getOrCatch.ts"],"names":[],"mappings":";;;AAIA,SAAgB,UAAU,CAAC,QAAmB;IAC5C,IAAI;QACF,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA;QAExB,IAAI,KAAK,YAAY,OAAO,EAAE;YAC5B,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAA;SACxE;aAAM;YACL,OAAO,EAAE,KAAK,EAAE,CAAA;SACjB;KACF;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,EAAE,KAAK,EAAE,CAAA;KACjB;AACH,CAAC;AAZD,gCAYC"}
@@ -0,0 +1,15 @@
1
+ import { ValueOrError } from './getOrCatch';
2
+ export declare function getOrRetry<T>(action: (attempt: number) => PromiseLike<T> | T, args?: GetOrRetryArgs): Promise<ValueOrError<T>>;
3
+ export declare type GetOrRetryArgs = {
4
+ attempts?: number;
5
+ retryIntervalMs?: number | RetryIntervalMsPolicy;
6
+ onFailedAttempt?: (error: any, attemptCount: number) => PromiseLike<void> | void;
7
+ };
8
+ export declare type RetryIntervalMsPolicy = (attempt: number, error: any) => number;
9
+ export declare function backoffRetryPolicy(initialDelayMs?: number, multiplier?: number): RetryIntervalMsPolicy;
10
+ interface RetryOptions {
11
+ retries?: number;
12
+ onFailedAttempt?: (error: any, attemptCount: number) => PromiseLike<void> | void;
13
+ }
14
+ export declare function retry<T>(input: (attemptCount: number) => PromiseLike<T> | T, options?: RetryOptions): Promise<T>;
15
+ export {};
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.retry = exports.backoffRetryPolicy = exports.getOrRetry = void 0;
4
+ const delay_1 = require("./delay");
5
+ const getOrCatch_1 = require("./getOrCatch");
6
+ async function getOrRetry(action, args) {
7
+ const retryIntervalMs = args?.retryIntervalMs === undefined ? backoffRetryPolicy() : args?.retryIntervalMs ?? 1000;
8
+ return getOrCatch_1.getOrCatch(async () => await retry((attempt) => action(attempt), {
9
+ retries: args?.attempts,
10
+ async onFailedAttempt(error, attemptCount) {
11
+ if (args?.onFailedAttempt)
12
+ await args.onFailedAttempt(error, attemptCount);
13
+ const intervalMs = typeof retryIntervalMs == 'function' ? retryIntervalMs(attemptCount, error) : retryIntervalMs;
14
+ if (intervalMs > 0)
15
+ await delay_1.delay(intervalMs);
16
+ }
17
+ }));
18
+ }
19
+ exports.getOrRetry = getOrRetry;
20
+ function backoffRetryPolicy(initialDelayMs = 500, multiplier = 1) {
21
+ return (attempt) => initialDelayMs * attempt * multiplier;
22
+ }
23
+ exports.backoffRetryPolicy = backoffRetryPolicy;
24
+ const DEFAULT_RETRY_ATTEMPTS = 2;
25
+ async function retry(input, options) {
26
+ const retries = options?.retries ?? DEFAULT_RETRY_ATTEMPTS;
27
+ for (let attemptCount = 1; attemptCount <= retries; attemptCount++) {
28
+ try {
29
+ return await input(attemptCount);
30
+ }
31
+ catch (error) {
32
+ if (options?.onFailedAttempt) {
33
+ await options.onFailedAttempt(error, attemptCount);
34
+ }
35
+ if (!error || attemptCount >= retries) {
36
+ throw error;
37
+ }
38
+ }
39
+ }
40
+ throw new Error('Exhausted all retries.');
41
+ }
42
+ exports.retry = retry;
43
+ //# sourceMappingURL=getOrRetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getOrRetry.js","sourceRoot":"","sources":["../../../src/engage/utils/getOrRetry.ts"],"names":[],"mappings":";;;AAEA,mCAA+B;AAC/B,6CAAuD;AAEhD,KAAK,UAAU,UAAU,CAC9B,MAA+C,EAC/C,IAAqB;IAErB,MAAM,eAAe,GAAG,IAAI,EAAE,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,kBAAkB,EAA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,CAAA;aACnD;YAGD,IAAI,CAAC,KAAK,IAAI,YAAY,IAAI,OAAO,EAAE;gBACrC,MAAM,KAAK,CAAA;aACZ;SACF;KACF;IAGD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;AAC3C,CAAC;AAvBD,sBAuBC"}
@@ -1,10 +1,10 @@
1
1
  import { ContextFromDecorator } from './operationTracking';
2
2
  export declare const track: ((decoratorArgs?: ({
3
3
  onError?: ((ctx: import("./operationTracking").OperationErrorHandlerContext<import("./operationTracking").TryCatchFinallyContext<(this: any, ...args: any[]) => any>>) => void) | undefined;
4
- } & import("./operationTracking").OperationLoggerDecoratorArgs & {
4
+ } & {
5
5
  onTry?: ((ctx: import("./operationTracking").TryCatchFinallyContext<(this: any, ...args: any[]) => any>) => void) | undefined;
6
6
  onFinally?: ((ctx: import("./operationTracking").TryCatchFinallyContext<(this: any, ...args: any[]) => any>) => void) | undefined;
7
- } & {
7
+ } & import("./operationTracking").OperationLoggerDecoratorArgs & {
8
8
  shouldStats?: ((args: import("./operationTracking").OperationStatsEventArgs) => boolean | void) | undefined;
9
9
  } & {
10
10
  wrapIntegrationError?: ((ctx: import("./operationTracking").TryCatchFinallyContext<(this: any, ...args: any[]) => any>) => import("@segment/actions-core/*").IntegrationError | [message: string, code: string, status: number]) | undefined;
@@ -15,9 +15,6 @@ export declare const track: ((decoratorArgs?: ({
15
15
  }) | undefined;
16
16
  } & {
17
17
  _contextType: import("./operationTracking").TryCatchFinallyContext<(this: any, ...args: any[]) => any> & {
18
- start?: number | undefined;
19
- duration?: number | undefined;
20
- } & {
21
18
  decoratorArgs?: {
22
19
  onError?: ((ctx: import("./operationTracking").OperationErrorHandlerContext<import("./operationTracking").TryCatchFinallyContext<(this: any, ...args: any[]) => any>>) => void) | undefined;
23
20
  } | undefined;
@@ -25,16 +22,19 @@ export declare const track: ((decoratorArgs?: ({
25
22
  parent?: (import("./operationTracking").TryCatchFinallyContext<(this: any, ...args: any[]) => any> & any) | undefined;
26
23
  sharedContext: {};
27
24
  } & {
28
- logs: string[];
29
- logMetadata?: Record<string, unknown> | undefined;
30
- decoratorArgs?: import("./operationTracking").OperationLoggerDecoratorArgs | undefined;
31
- sharedContext: import("./operationTracking").OperationLoggerSharedContext;
25
+ start?: number | undefined;
26
+ duration?: number | undefined;
32
27
  } & {
33
28
  onFinally: (() => void)[];
34
29
  decoratorArgs?: {
35
30
  onTry?: ((ctx: import("./operationTracking").TryCatchFinallyContext<(this: any, ...args: any[]) => any>) => void) | undefined;
36
31
  onFinally?: ((ctx: import("./operationTracking").TryCatchFinallyContext<(this: any, ...args: any[]) => any>) => void) | undefined;
37
32
  } | undefined;
33
+ } & {
34
+ logs: string[];
35
+ logMetadata?: Record<string, unknown> | undefined;
36
+ decoratorArgs?: import("./operationTracking").OperationLoggerDecoratorArgs | undefined;
37
+ sharedContext: import("./operationTracking").OperationLoggerSharedContext;
38
38
  } & {
39
39
  tags: string[];
40
40
  sharedContext: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@segment/actions-shared",
3
3
  "description": "Shared destination action methods and definitions.",
4
- "version": "1.115.0",
4
+ "version": "1.115.1-extensible-destination-http.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/segmentio/action-destinations",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@amplitude/ua-parser-js": "^0.7.25",
40
- "@segment/actions-core": "^3.134.0",
40
+ "@segment/actions-core": "3.134.1-extensible-destination-http.0",
41
41
  "cheerio": "^1.0.0-rc.10",
42
42
  "dayjs": "^1.10.7",
43
43
  "escape-goat": "^3",
@@ -64,5 +64,5 @@
64
64
  "<rootDir>/test/setup-after-env.ts"
65
65
  ]
66
66
  },
67
- "gitHead": "a6ffde1a78e772c4f7d31ff40fcf199ac00ac526"
67
+ "gitHead": "d6a2b5accf0d077d249cfab0c2ec09ffe8cceb6e"
68
68
  }