@segment/actions-shared 1.0.1-alpha.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.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # actions-shared
2
+
3
+ Shared definitions and utilities
4
+
5
+ ## License
6
+
7
+ MIT License
8
+
9
+ Copyright (c) 2021 Segment
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ ## Contributing
30
+
31
+ All third party contributors acknowledge that any contributions they provide will be made under the same open source license that the open source project is provided under.
@@ -0,0 +1,3 @@
1
+ import type { InputField } from '@segment/actions-core';
2
+ export declare type FriendbuyAPI = 'pub' | 'mapi';
3
+ export declare function commonCustomerFields(requireIdAndEmail: boolean): Record<string, InputField>;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.commonCustomerFields = void 0;
4
+ function commonCustomerFields(requireIdAndEmail) {
5
+ return {
6
+ customerId: {
7
+ label: 'Customer ID',
8
+ description: "The user's customer ID.",
9
+ type: 'string',
10
+ required: requireIdAndEmail,
11
+ default: {
12
+ '@if': {
13
+ exists: { '@path': '$.properties.customerId' },
14
+ then: { '@path': '$.properties.customerId' },
15
+ else: { '@path': '$.userId' }
16
+ }
17
+ }
18
+ },
19
+ anonymousId: {
20
+ label: 'Anonymous ID',
21
+ description: "The user's anonymous ID.",
22
+ type: 'string',
23
+ required: false,
24
+ default: { '@path': '$.anonymousId' }
25
+ },
26
+ email: {
27
+ label: 'Email',
28
+ description: "The user's email address.",
29
+ type: 'string',
30
+ required: requireIdAndEmail,
31
+ default: { '@path': '$.properties.email' }
32
+ },
33
+ isNewCustomer: {
34
+ label: 'New Customer Flag',
35
+ description: 'Flag to indicate whether the user is a new customer.',
36
+ type: 'boolean',
37
+ required: false,
38
+ default: { '@path': '$.properties.isNewCustomer' }
39
+ },
40
+ loyaltyStatus: {
41
+ label: 'Loyalty Program Status',
42
+ description: 'The status of the user in your loyalty program. Valid values are "in", "out", or "blocked".',
43
+ type: 'string',
44
+ required: false,
45
+ default: { '@path': '$.properties.loyaltyStatus' }
46
+ },
47
+ firstName: {
48
+ label: 'First Name',
49
+ description: "The user's given name.",
50
+ type: 'string',
51
+ required: false,
52
+ default: { '@path': '$.properties.firstName' }
53
+ },
54
+ lastName: {
55
+ label: 'Last Name',
56
+ description: "The user's surname.",
57
+ type: 'string',
58
+ required: false,
59
+ default: { '@path': '$.properties.lastName' }
60
+ },
61
+ name: {
62
+ label: 'Name',
63
+ description: "The user's full name.",
64
+ type: 'string',
65
+ required: false,
66
+ default: { '@path': '$.properties.name' }
67
+ },
68
+ age: {
69
+ label: 'Age',
70
+ description: "The user's age.",
71
+ type: 'number',
72
+ required: false,
73
+ default: { '@path': '$.properties.age' }
74
+ },
75
+ birthday: {
76
+ label: 'Birthday',
77
+ description: 'The user\'s birthday in the format "YYYY-MM-DD", or "0000-MM-DD" to omit the year.',
78
+ type: 'string',
79
+ format: 'date',
80
+ default: { '@path': '$.properties.birthday' }
81
+ }
82
+ };
83
+ }
84
+ exports.commonCustomerFields = commonCustomerFields;
85
+ //# sourceMappingURL=commonFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commonFields.js","sourceRoot":"","sources":["../../src/friendbuy/commonFields.ts"],"names":[],"mappings":";;;AAIA,SAAgB,oBAAoB,CAAC,iBAA0B;IAK7D,OAAO;QACL,UAAU,EAAE;YACV,KAAK,EAAE,aAAa;YACpB,WAAW,EAAE,yBAAyB;YACtC,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,iBAAiB;YAC3B,OAAO,EAAE;gBAKP,KAAK,EAAE;oBACL,MAAM,EAAE,EAAE,OAAO,EAAE,yBAAyB,EAAE;oBAC9C,IAAI,EAAE,EAAE,OAAO,EAAE,yBAAyB,EAAE;oBAC5C,IAAI,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;iBAC9B;aACF;SACF;QACD,WAAW,EAAE;YACX,KAAK,EAAE,cAAc;YACrB,WAAW,EAAE,0BAA0B;YACvC,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE;SACtC;QACD,KAAK,EAAE;YACL,KAAK,EAAE,OAAO;YACd,WAAW,EAAE,2BAA2B;YACxC,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,iBAAiB;YAC3B,OAAO,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE;SAC3C;QACD,aAAa,EAAE;YACb,KAAK,EAAE,mBAAmB;YAC1B,WAAW,EAAE,sDAAsD;YACnE,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,EAAE,OAAO,EAAE,4BAA4B,EAAE;SACnD;QACD,aAAa,EAAE;YACb,KAAK,EAAE,wBAAwB;YAC/B,WAAW,EAAE,6FAA6F;YAC1G,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,EAAE,OAAO,EAAE,4BAA4B,EAAE;SACnD;QACD,SAAS,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,WAAW,EAAE,wBAAwB;YACrC,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,EAAE,OAAO,EAAE,wBAAwB,EAAE;SAC/C;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,WAAW;YAClB,WAAW,EAAE,qBAAqB;YAClC,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,EAAE,OAAO,EAAE,uBAAuB,EAAE;SAC9C;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,MAAM;YACb,WAAW,EAAE,uBAAuB;YACpC,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,EAAE,OAAO,EAAE,mBAAmB,EAAE;SAC1C;QACD,GAAG,EAAE;YACH,KAAK,EAAE,KAAK;YACZ,WAAW,EAAE,iBAAiB;YAC9B,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,EAAE,OAAO,EAAE,kBAAkB,EAAE;SACzC;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,UAAU;YACjB,WAAW,EAAE,oFAAoF;YACjG,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,OAAO,EAAE,uBAAuB,EAAE;SAC9C;KACF,CAAA;AACH,CAAC;AAvFD,oDAuFC"}
@@ -0,0 +1,10 @@
1
+ import type { InputField } from '@segment/actions-core';
2
+ import { FriendbuyPayloadItem } from './util';
3
+ export declare const contextFields: Record<string, InputField>;
4
+ export interface ContextFields {
5
+ pageUrl?: string;
6
+ pageTitle?: string;
7
+ userAgent?: string;
8
+ ipAddress?: string;
9
+ }
10
+ export declare function contextAttributes(context: ContextFields): FriendbuyPayloadItem[];
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.contextAttributes = exports.contextFields = void 0;
4
+ exports.contextFields = {
5
+ pageUrl: {
6
+ label: 'Page URL',
7
+ description: 'The URL of the web page the event was generated on.',
8
+ type: 'string',
9
+ format: 'uri',
10
+ required: false,
11
+ default: { '@path': '$.context.page.url' }
12
+ },
13
+ pageTitle: {
14
+ label: 'Page Title',
15
+ description: 'The title of the web page the event was generated on.',
16
+ type: 'string',
17
+ required: false,
18
+ default: { '@path': '$.context.page.title' }
19
+ },
20
+ userAgent: {
21
+ label: 'User Agent',
22
+ description: "The browser's User-Agent string.",
23
+ type: 'string',
24
+ required: false,
25
+ default: { '@path': '$.context.userAgent' }
26
+ },
27
+ ipAddress: {
28
+ label: 'IP Address',
29
+ description: "The users's IP address.",
30
+ type: 'string',
31
+ required: false,
32
+ default: { '@path': '$.context.ip' }
33
+ }
34
+ };
35
+ function contextAttributes(context) {
36
+ return [
37
+ ['pageUrl', context.pageUrl],
38
+ ['pageTitle', context.pageTitle],
39
+ ['userAgent', context.userAgent],
40
+ ['ipAddress', context.ipAddress]
41
+ ];
42
+ }
43
+ exports.contextAttributes = contextAttributes;
44
+ //# sourceMappingURL=contextFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contextFields.js","sourceRoot":"","sources":["../../src/friendbuy/contextFields.ts"],"names":[],"mappings":";;;AAMa,QAAA,aAAa,GAA+B;IACvD,OAAO,EAAE;QACP,KAAK,EAAE,UAAU;QACjB,WAAW,EAAE,qDAAqD;QAClE,IAAI,EAAE,QAAQ;QACd,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE;KAC3C;IACD,SAAS,EAAE;QACT,KAAK,EAAE,YAAY;QACnB,WAAW,EAAE,uDAAuD;QACpE,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,sBAAsB,EAAE;KAC7C;IACD,SAAS,EAAE;QACT,KAAK,EAAE,YAAY;QACnB,WAAW,EAAE,kCAAkC;QAC/C,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,qBAAqB,EAAE;KAC5C;IACD,SAAS,EAAE;QACT,KAAK,EAAE,YAAY;QACnB,WAAW,EAAE,yBAAyB;QACtC,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE;KACrC;CACF,CAAA;AASD,SAAgB,iBAAiB,CAAC,OAAsB;IACtD,OAAO;QACL,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC;QAC5B,CAAC,WAAW,EAAE,OAAO,CAAC,SAAS,CAAC;QAChC,CAAC,WAAW,EAAE,OAAO,CAAC,SAAS,CAAC;QAChC,CAAC,WAAW,EAAE,OAAO,CAAC,SAAS,CAAC;KACjC,CAAA;AACH,CAAC;AAPD,8CAOC"}
@@ -0,0 +1,20 @@
1
+ import { JSONObject, JSONValue } from '@segment/actions-core';
2
+ export declare type ConvertFun = (rawValue: unknown) => JSONValue;
3
+ export declare const ROOT: unique symbol;
4
+ export declare const COPY: {};
5
+ export declare const DROP: unique symbol;
6
+ export interface EventMap {
7
+ fields: Record<string, FieldMap | typeof DROP>;
8
+ unmappedFieldObject?: string | typeof ROOT;
9
+ defaultObject?: JSONObject;
10
+ finalize?: (o: JSONObject) => JSONObject;
11
+ }
12
+ export interface FieldMap extends Partial<EventMap> {
13
+ type?: 'array' | 'object';
14
+ name?: string | string[];
15
+ convert?: ConvertFun;
16
+ }
17
+ export declare type AnalyticsPayload = Record<string, JSONValue>;
18
+ export declare function mapEvent(map: EventMap, analyticsPayload: AnalyticsPayload): JSONObject;
19
+ export declare function mapEventHelper(map: EventMap, analyticsPayload: AnalyticsPayload): JSONObject | undefined;
20
+ export declare function stringify(rawValue: JSONValue): string;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringify = exports.mapEventHelper = exports.mapEvent = exports.DROP = exports.COPY = exports.ROOT = void 0;
4
+ const actions_core_1 = require("@segment/actions-core");
5
+ const util_1 = require("./util");
6
+ exports.ROOT = Symbol('ROOT');
7
+ exports.COPY = {};
8
+ Object.freeze(exports.COPY);
9
+ exports.DROP = Symbol('DROP');
10
+ function mapEvent(map, analyticsPayload) {
11
+ const friendbuyPayload = mapEventHelper(map, analyticsPayload);
12
+ if (!friendbuyPayload) {
13
+ throw new actions_core_1.IntegrationError('Payload has no supported fields', 'INVALID_REQUEST_DATA', 400);
14
+ }
15
+ return friendbuyPayload;
16
+ }
17
+ exports.mapEvent = mapEvent;
18
+ function mapEventHelper(map, analyticsPayload) {
19
+ if (analyticsPayload.friendbuyAttributes) {
20
+ if (typeof analyticsPayload.friendbuyAttributes === 'object') {
21
+ analyticsPayload = Object.assign({}, analyticsPayload.friendbuyAttributes, analyticsPayload);
22
+ }
23
+ delete analyticsPayload.friendbuyAttributes;
24
+ }
25
+ let friendbuyPayload = Object.assign({}, map.defaultObject);
26
+ for (const [key, rawValue] of Object.entries(analyticsPayload)) {
27
+ const fieldMap = typeof map.fields === 'object' && map.fields[key];
28
+ if (!fieldMap) {
29
+ let value = rawValue;
30
+ if (util_1.isNonEmpty(rawValue)) {
31
+ if (map.unmappedFieldObject) {
32
+ let unmappedFieldObject = friendbuyPayload;
33
+ if (map.unmappedFieldObject !== exports.ROOT) {
34
+ if (typeof friendbuyPayload[map.unmappedFieldObject] !== 'object') {
35
+ unmappedFieldObject = friendbuyPayload[map.unmappedFieldObject] = {};
36
+ }
37
+ else {
38
+ unmappedFieldObject = friendbuyPayload[map.unmappedFieldObject];
39
+ }
40
+ value = stringify(rawValue);
41
+ }
42
+ unmappedFieldObject[key] = value;
43
+ }
44
+ }
45
+ }
46
+ else if (fieldMap === exports.DROP) {
47
+ }
48
+ else {
49
+ const name = fieldMap.name || key;
50
+ let value = fieldMap.convert ? fieldMap.convert(rawValue) : rawValue;
51
+ switch (fieldMap.type) {
52
+ case 'object':
53
+ value = mapEventHelper(fieldMap, value);
54
+ break;
55
+ case 'array':
56
+ if (fieldMap.fields) {
57
+ value = value.reduce((acc, o) => {
58
+ const v = mapEventHelper(fieldMap, o);
59
+ if (v !== undefined) {
60
+ acc.push(v);
61
+ }
62
+ return acc;
63
+ }, []);
64
+ }
65
+ break;
66
+ default:
67
+ break;
68
+ }
69
+ if (util_1.isNonEmpty(value)) {
70
+ if (typeof name === 'string') {
71
+ friendbuyPayload[name] = value;
72
+ }
73
+ else {
74
+ let o = friendbuyPayload;
75
+ for (let i = 0; i < name.length - 1; i++) {
76
+ if (!(name[i] in o)) {
77
+ o[name[i]] = {};
78
+ }
79
+ o = o[name[i]];
80
+ }
81
+ o[name[name.length - 1]] = value;
82
+ }
83
+ }
84
+ }
85
+ }
86
+ if (map.finalize) {
87
+ friendbuyPayload = map.finalize(friendbuyPayload);
88
+ }
89
+ return util_1.isNonEmpty(friendbuyPayload) ? friendbuyPayload : undefined;
90
+ }
91
+ exports.mapEventHelper = mapEventHelper;
92
+ function stringify(rawValue) {
93
+ switch (typeof rawValue) {
94
+ case 'string':
95
+ return rawValue;
96
+ case 'object':
97
+ return JSON.stringify(rawValue);
98
+ default:
99
+ return rawValue.toString();
100
+ }
101
+ }
102
+ exports.stringify = stringify;
103
+ //# sourceMappingURL=mapEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapEvent.js","sourceRoot":"","sources":["../../src/friendbuy/mapEvent.ts"],"names":[],"mappings":";;;AAAA,wDAA+E;AAE/E,iCAAmC;AAQtB,QAAA,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;AAMrB,QAAA,IAAI,GAAG,EAAE,CAAA;AACtB,MAAM,CAAC,MAAM,CAAC,YAAI,CAAC,CAAA;AAKN,QAAA,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,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qBAAM;oBACL,IAAI,CAAC,GAAG,gBAAgB,CAAA;oBACxB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;wBACxC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE;4BACnB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAA;yBAChB;wBACD,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAe,CAAA;qBAC7B;oBACD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA;iBACjC;aACF;SACF;KACF;IAED,IAAI,GAAG,CAAC,QAAQ,EAAE;QAChB,gBAAgB,GAAG,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAA;KAClD;IAED,OAAO,iBAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAA;AACpE,CAAC;AAxFD,wCAwFC;AAED,SAAgB,SAAS,CAAC,QAAmB;IAC3C,QAAQ,OAAO,QAAQ,EAAE;QACvB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAA;QACjB,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;QACjC;YACE,OAAO,QAAQ,CAAC,QAAQ,EAAE,CAAA;KAC7B;AACH,CAAC;AATD,8BASC"}
@@ -0,0 +1,2 @@
1
+ import type { InputField } from '@segment/actions-core';
2
+ export declare const trackCustomEventFields: Record<string, InputField>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trackCustomEventFields = void 0;
4
+ exports.trackCustomEventFields = {
5
+ eventType: {
6
+ type: 'string',
7
+ required: true,
8
+ description: 'The type of the event to track.',
9
+ label: 'Event Type',
10
+ default: { '@path': '$.event' }
11
+ },
12
+ eventProperties: {
13
+ type: 'object',
14
+ required: true,
15
+ description: 'Object containing the properties for the event being tracked. All of the fields in this object will be sent in the root of the Friendbuy track event.',
16
+ label: 'Event Properties',
17
+ default: { '@path': '$.properties' }
18
+ },
19
+ deduplicationId: {
20
+ type: 'string',
21
+ required: false,
22
+ description: 'An identifier for the event being tracked to prevent the same event from being rewarded more than once.',
23
+ label: 'Event ID',
24
+ default: { '@path': '$.properties.deduplicationId' }
25
+ },
26
+ customerId: {
27
+ label: 'Customer ID',
28
+ description: "The user's customerId.",
29
+ type: 'string',
30
+ required: true,
31
+ default: { '@path': '$.userId' }
32
+ },
33
+ anonymousId: {
34
+ label: 'Anonymous ID',
35
+ description: "The user's anonymous id",
36
+ type: 'string',
37
+ required: false,
38
+ default: { '@path': '$.anonymousId' }
39
+ }
40
+ };
41
+ //# sourceMappingURL=sharedCustomEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharedCustomEvent.js","sourceRoot":"","sources":["../../src/friendbuy/sharedCustomEvent.ts"],"names":[],"mappings":";;;AAEa,QAAA,sBAAsB,GAA+B;IAChE,SAAS,EAAE;QACT,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,WAAW,EAAE,iCAAiC;QAC9C,KAAK,EAAE,YAAY;QACnB,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE;KAChC;IACD,eAAe,EAAE;QACf,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,WAAW,EACT,uJAAuJ;QACzJ,KAAK,EAAE,kBAAkB;QACzB,OAAO,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE;KACrC;IACD,eAAe,EAAE;QACf,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,WAAW,EACT,yGAAyG;QAC3G,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,EAAE,OAAO,EAAE,8BAA8B,EAAE;KACrD;IACD,UAAU,EAAE;QACV,KAAK,EAAE,aAAa;QACpB,WAAW,EAAE,wBAAwB;QACrC,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;KACjC;IACD,WAAW,EAAE;QACX,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,yBAAyB;QACtC,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE;KACtC;CACF,CAAA"}
@@ -0,0 +1,2 @@
1
+ import type { InputField } from '@segment/actions-core';
2
+ export declare const trackCustomerFields: Record<string, InputField>;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trackCustomerFields = void 0;
4
+ exports.trackCustomerFields = {
5
+ customerId: {
6
+ label: 'Customer ID',
7
+ description: "The user's customer ID.",
8
+ type: 'string',
9
+ required: true,
10
+ default: { '@path': '$.userId' }
11
+ },
12
+ anonymousId: {
13
+ label: 'Anonymous ID',
14
+ description: "The user's anonymous id.",
15
+ type: 'string',
16
+ required: false,
17
+ default: { '@path': '$.anonymousId' }
18
+ },
19
+ email: {
20
+ label: 'Email',
21
+ description: "The user's email address.",
22
+ type: 'string',
23
+ required: true,
24
+ default: { '@path': '$.traits.email' }
25
+ },
26
+ firstName: {
27
+ label: 'First Name',
28
+ description: "The user's given name.",
29
+ type: 'string',
30
+ required: false,
31
+ default: { '@path': '$.traits.firstName' }
32
+ },
33
+ lastName: {
34
+ label: 'Last Name',
35
+ description: "The user's surname.",
36
+ type: 'string',
37
+ required: false,
38
+ default: { '@path': '$.traits.lastName' }
39
+ },
40
+ name: {
41
+ label: 'Name',
42
+ description: "The user's full name. If the name trait doesn't exist then it will be automatically derived from the firstName and lastName traits if they are defined.",
43
+ type: 'string',
44
+ required: false,
45
+ default: { '@path': '$.traits.name' }
46
+ },
47
+ age: {
48
+ label: 'Age',
49
+ description: "The user's age.",
50
+ type: 'number',
51
+ required: false,
52
+ default: { '@path': '$.traits.age' }
53
+ },
54
+ birthday: {
55
+ label: 'Birthday',
56
+ description: 'The user\'s birthday in the format "YYYY-MM-DD", or "0000-MM-DD" to omit the year.',
57
+ type: 'string',
58
+ format: 'date',
59
+ required: false,
60
+ default: { '@path': '$.traits.birthday' }
61
+ },
62
+ language: {
63
+ label: 'Language',
64
+ description: "The user's language.",
65
+ type: 'string',
66
+ required: false,
67
+ default: { '@path': '$.traits.language' }
68
+ },
69
+ addressCountry: {
70
+ label: 'Country',
71
+ description: "The user's country.",
72
+ type: 'string',
73
+ required: false,
74
+ default: { '@path': '$.traits.address.country' }
75
+ },
76
+ addressState: {
77
+ label: 'State',
78
+ description: "The user's state.",
79
+ type: 'string',
80
+ required: false,
81
+ default: { '@path': '$.traits.address.state' }
82
+ },
83
+ addressCity: {
84
+ label: 'City',
85
+ description: "The user's city.",
86
+ type: 'string',
87
+ required: false,
88
+ default: { '@path': '$.traits.address.city' }
89
+ },
90
+ addressPostalCode: {
91
+ label: 'State',
92
+ description: "The user's postal code.",
93
+ type: 'string',
94
+ required: false,
95
+ default: { '@path': '$.traits.address.postalCode' }
96
+ },
97
+ customerSince: {
98
+ label: 'Customer Since',
99
+ description: 'The date the user became a customer.',
100
+ type: 'string',
101
+ format: 'date-time',
102
+ required: false,
103
+ default: { '@path': '$.traits.customerSince' }
104
+ },
105
+ loyaltyStatus: {
106
+ label: 'Loyalty Status',
107
+ description: 'The status of the user in your loyalty program. Valid values are "in", "out", or "blocked".',
108
+ type: 'string',
109
+ required: false,
110
+ default: { '@path': '$.traits.loyaltyStatus' }
111
+ },
112
+ isNewCustomer: {
113
+ label: 'New Customer Flag',
114
+ description: 'Flag to indicate whether the user is a new customer.',
115
+ type: 'boolean',
116
+ required: false,
117
+ default: { '@path': '$.traits.isNewCustomer' }
118
+ },
119
+ friendbuyAttributes: {
120
+ label: 'Custom Attributes',
121
+ description: 'Custom attributes to send to Friendbuy. You should pass an object whose keys are the names of the custom attributes and whose values are strings. Non-string-valued attributes will be dropped.',
122
+ type: 'object',
123
+ required: false,
124
+ default: { '@path': '$.traits.friendbuyAttributes' }
125
+ }
126
+ };
127
+ //# sourceMappingURL=sharedCustomer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharedCustomer.js","sourceRoot":"","sources":["../../src/friendbuy/sharedCustomer.ts"],"names":[],"mappings":";;;AAIa,QAAA,mBAAmB,GAA+B;IAC7D,UAAU,EAAE;QACV,KAAK,EAAE,aAAa;QACpB,WAAW,EAAE,yBAAyB;QACtC,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;KACjC;IACD,WAAW,EAAE;QACX,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,0BAA0B;QACvC,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE;KACtC;IACD,KAAK,EAAE;QACL,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,2BAA2B;QACxC,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE;KACvC;IACD,SAAS,EAAE;QACT,KAAK,EAAE,YAAY;QACnB,WAAW,EAAE,wBAAwB;QACrC,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE;KAC3C;IACD,QAAQ,EAAE;QACR,KAAK,EAAE,WAAW;QAClB,WAAW,EAAE,qBAAqB;QAClC,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,mBAAmB,EAAE;KAC1C;IACD,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM;QACb,WAAW,EACT,y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B;QACtC,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,6BAA6B,EAAE;KACpD;IACD,aAAa,EAAE;QACb,KAAK,EAAE,gBAAgB;QACvB,WAAW,EAAE,sCAAsC;QACnD,IAAI,EAAE,QAAQ;QACd,MAAM,EAAE,WAAW;QACnB,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,wBAAwB,EAAE;KAC/C;IACD,aAAa,EAAE;QACb,KAAK,EAAE,gBAAgB;QACvB,WAAW,EAAE,6FAA6F;QAC1G,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,wBAAwB,EAAE;KAC/C;IACD,aAAa,EAAE;QACb,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EAAE,sDAAsD;QACnE,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,wBAAwB,EAAE;KAC/C;IACD,mBAAmB,EAAE;QACnB,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EACT,iMAAiM;QACnM,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,8BAA8B,EAAE;KACrD;CACF,CAAA"}
@@ -0,0 +1,2 @@
1
+ import type { InputField } from '@segment/actions-core';
2
+ export declare const trackPurchaseFields: Record<string, InputField>;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trackPurchaseFields = void 0;
4
+ const commonFields_1 = require("./commonFields");
5
+ exports.trackPurchaseFields = {
6
+ orderId: {
7
+ label: 'Order ID',
8
+ description: 'The order ID.',
9
+ type: 'string',
10
+ required: true,
11
+ default: { '@path': '$.properties.order_id' }
12
+ },
13
+ amount: {
14
+ label: 'Amount Source',
15
+ description: 'Purchase amount to be considered when evaluating reward rules.',
16
+ type: 'number',
17
+ required: true,
18
+ default: { '@path': '$.properties.total' }
19
+ },
20
+ currency: {
21
+ label: 'Currency',
22
+ description: 'The currency of the purchase amount.',
23
+ type: 'string',
24
+ required: true,
25
+ default: { '@path': '$.properties.currency' }
26
+ },
27
+ coupon: {
28
+ label: 'Coupon',
29
+ description: 'The coupon code of any coupon redeemed with the order.',
30
+ type: 'string',
31
+ required: false,
32
+ default: { '@path': '$.properties.coupon' }
33
+ },
34
+ giftCardCodes: {
35
+ label: 'Gift Card Codes',
36
+ description: 'An array of gift card codes applied to the order.',
37
+ type: 'string',
38
+ multiple: true,
39
+ required: false,
40
+ default: { '@path': '$.properties.giftCardCodes' }
41
+ },
42
+ products: {
43
+ label: 'Products',
44
+ description: 'Products purchased.',
45
+ type: 'object',
46
+ multiple: true,
47
+ required: false,
48
+ properties: {
49
+ sku: {
50
+ label: 'Product SKU',
51
+ type: 'string',
52
+ required: false
53
+ },
54
+ name: {
55
+ label: 'Product Name',
56
+ type: 'string',
57
+ required: false
58
+ },
59
+ quantity: {
60
+ label: 'Quantity (default 1)',
61
+ type: 'integer',
62
+ required: false
63
+ },
64
+ price: {
65
+ label: 'Price',
66
+ type: 'number',
67
+ required: true
68
+ },
69
+ description: {
70
+ label: 'Product Description',
71
+ type: 'string',
72
+ required: false
73
+ },
74
+ category: {
75
+ label: 'Product Category',
76
+ type: 'string',
77
+ required: false
78
+ },
79
+ url: {
80
+ label: 'Product URL',
81
+ type: 'string',
82
+ required: false
83
+ },
84
+ image_url: {
85
+ label: 'Product Image URL',
86
+ type: 'string',
87
+ required: false
88
+ }
89
+ },
90
+ default: { '@path': '$.properties.products' }
91
+ },
92
+ ...commonFields_1.commonCustomerFields(false),
93
+ friendbuyAttributes: {
94
+ label: 'Custom Attributes',
95
+ description: 'Custom attributes to send to Friendbuy. You should pass an object whose keys are the names of the custom attributes and whose values are strings. Non-string-valued attributes will be dropped.',
96
+ type: 'object',
97
+ required: false,
98
+ default: { '@path': '$.properties.friendbuyAttributes' }
99
+ }
100
+ };
101
+ //# sourceMappingURL=sharedPurchase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharedPurchase.js","sourceRoot":"","sources":["../../src/friendbuy/sharedPurchase.ts"],"names":[],"mappings":";;;AAEA,iDAAqD;AAGxC,QAAA,mBAAmB,GAA+B;IAC7D,OAAO,EAAE;QACP,KAAK,EAAE,UAAU;QACjB,WAAW,EAAE,eAAe;QAC5B,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,EAAE,OAAO,EAAE,uBAAuB,EAAE;KAC9C;IAED,MAAM,EAAE;QAKN,KAAK,EAAE,eAAe;QACtB,WAAW,EAAE,gEAAgE;QAC7E,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE;KAC3C;IACD,QAAQ,EAAE;QACR,KAAK,EAAE,UAAU;QACjB,WAAW,EAAE,sCAAsC;QACnD,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,EAAE,OAAO,EAAE,uBAAuB,EAAE;KAC9C;IACD,MAAM,EAAE;QAEN,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,wDAAwD;QACrE,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,qBAAqB,EAAE;KAC5C;IACD,aAAa,EAAE;QAEb,KAAK,EAAE,iBAAiB;QACxB,WAAW,EAAE,mDAAmD;QAChE,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,4BAA4B,EAAE;KACnD;IAED,QAAQ,EAAE;QACR,KAAK,EAAE,UAAU;QACjB,WAAW,EAAE,qBAAqB;QAClC,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE;YACV,GAAG,EAAE;gBACH,KAAK,EAAE,aAAa;gBACpB,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,KAAK;aAChB;YACD,IAAI,EAAE;gBACJ,KAAK,EAAE,cAAc;gBACrB,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,KAAK;aAChB;YACD,QAAQ,EAAE;gBACR,KAAK,EAAE,sBAAsB;gBAC7B,IAAI,EAAE,SAAS;gBACf,QAAQ,EAAE,KAAK;aAChB;YACD,KAAK,EAAE;gBACL,KAAK,EAAE,OAAO;gBACd,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;aACf;YACD,WAAW,EAAE;gBACX,KAAK,EAAE,qBAAqB;gBAC5B,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,KAAK;aAChB;YACD,QAAQ,EAAE;gBACR,KAAK,EAAE,kBAAkB;gBACzB,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,KAAK;aAChB;YACD,GAAG,EAAE;gBACH,KAAK,EAAE,aAAa;gBACpB,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,KAAK;aAChB;YACD,SAAS,EAAE;gBACT,KAAK,EAAE,mBAAmB;gBAC1B,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,KAAK;aAChB;SACF;QACD,OAAO,EAAE,EAAE,OAAO,EAAE,uBAAuB,EAAE;KAC9C;IAED,GAAG,mCAAoB,CAAC,KAAK,CAAC;IAE9B,mBAAmB,EAAE;QACnB,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EACT,iMAAiM;QACnM,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,kCAAkC,EAAE;KACzD;CACF,CAAA"}
@@ -0,0 +1,2 @@
1
+ import type { InputField } from '@segment/actions-core';
2
+ export declare const trackSignUpFields: Record<string, InputField>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trackSignUpFields = void 0;
4
+ const commonFields_1 = require("./commonFields");
5
+ exports.trackSignUpFields = {
6
+ ...commonFields_1.commonCustomerFields(true),
7
+ friendbuyAttributes: {
8
+ label: 'Custom Attributes',
9
+ description: 'Custom attributes to send to Friendbuy. You should pass an object whose keys are the names of the custom attributes and whose values are strings. Non-string-valued attributes will be dropped.',
10
+ type: 'object',
11
+ required: false,
12
+ default: { '@path': '$.properties.friendbuyAttributes' }
13
+ }
14
+ };
15
+ //# sourceMappingURL=sharedSignUp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharedSignUp.js","sourceRoot":"","sources":["../../src/friendbuy/sharedSignUp.ts"],"names":[],"mappings":";;;AAEA,iDAAqD;AAGxC,QAAA,iBAAiB,GAA+B;IAC3D,GAAG,mCAAoB,CAAC,IAAI,CAAC;IAC7B,mBAAmB,EAAE;QACnB,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EACT,iMAAiM;QACnM,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,EAAE,OAAO,EAAE,kCAAkC,EAAE;KACzD;CACF,CAAA"}
@@ -0,0 +1,35 @@
1
+ import type { JSONObject, JSONValue } from '@segment/actions-core';
2
+ import type { FriendbuyAPI } from './commonFields';
3
+ import { AnalyticsPayload } from './mapEvent';
4
+ export interface GetNameParams {
5
+ name?: string;
6
+ firstName?: string;
7
+ lastName?: string;
8
+ }
9
+ export declare function getName(payload: GetNameParams): string | undefined;
10
+ export declare function addName(payload: GetNameParams | undefined): void;
11
+ export declare function removeCustomerIfNoId(payload: {
12
+ customer?: {
13
+ id?: string;
14
+ };
15
+ }): {
16
+ customer?: {
17
+ id?: string | undefined;
18
+ } | undefined;
19
+ };
20
+ export declare function moveEventPropertiesToRoot(payload: AnalyticsPayload): AnalyticsPayload;
21
+ declare type NotUndefined<T> = T extends undefined ? never : T;
22
+ export declare function isNonEmpty<T extends unknown>(o: T): o is NotUndefined<T>;
23
+ export declare type FriendbuyPayloadItem = [string, JSONValue | undefined];
24
+ export interface CreateFriendbuyPayloadFlags {
25
+ dropEmpty?: boolean;
26
+ }
27
+ export declare function createFriendbuyPayload(payloadItems: FriendbuyPayloadItem[], flags?: CreateFriendbuyPayloadFlags): JSONObject;
28
+ export declare type DateRecord = {
29
+ year?: number;
30
+ month: number;
31
+ day: number;
32
+ };
33
+ export declare function filterFriendbuyAttributes(api: FriendbuyAPI, friendbuyAttributes: Record<string, unknown> | undefined): [string, JSONValue][];
34
+ export declare function parseDate(date: string | DateRecord | undefined): DateRecord | undefined;
35
+ export {};
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseDate = exports.filterFriendbuyAttributes = exports.createFriendbuyPayload = exports.isNonEmpty = exports.moveEventPropertiesToRoot = exports.removeCustomerIfNoId = exports.addName = exports.getName = void 0;
4
+ function getName(payload) {
5
+ return (payload.name ? payload.name :
6
+ payload.firstName && payload.lastName ? `${payload.firstName} ${payload.lastName}`
7
+ : undefined);
8
+ }
9
+ exports.getName = getName;
10
+ function addName(payload) {
11
+ if (typeof payload === 'object' && !payload.name && payload.firstName && payload.lastName) {
12
+ payload.name = `${payload.firstName} ${payload.lastName}`;
13
+ }
14
+ }
15
+ exports.addName = addName;
16
+ function removeCustomerIfNoId(payload) {
17
+ if (typeof payload !== 'object' || typeof payload.customer !== 'object' || payload.customer.id) {
18
+ return payload;
19
+ }
20
+ payload = { ...payload };
21
+ delete payload.customer;
22
+ return payload;
23
+ }
24
+ exports.removeCustomerIfNoId = removeCustomerIfNoId;
25
+ function moveEventPropertiesToRoot(payload) {
26
+ if (typeof payload !== 'object' || typeof payload.eventProperties !== 'object') {
27
+ return payload;
28
+ }
29
+ const analyticsPayload = {
30
+ ...(payload.eventProperties || {}),
31
+ ...payload
32
+ };
33
+ delete analyticsPayload.eventProperties;
34
+ return analyticsPayload;
35
+ }
36
+ exports.moveEventPropertiesToRoot = moveEventPropertiesToRoot;
37
+ function isNonEmpty(o) {
38
+ if (o === undefined || o === '') {
39
+ return false;
40
+ }
41
+ if (typeof o !== 'object') {
42
+ return true;
43
+ }
44
+ for (const _e in o) {
45
+ return true;
46
+ }
47
+ if (o === null) {
48
+ return true;
49
+ }
50
+ return false;
51
+ }
52
+ exports.isNonEmpty = isNonEmpty;
53
+ function createFriendbuyPayload(payloadItems, flags = {}) {
54
+ const friendbuyPayload = {};
55
+ payloadItems.forEach(([k, v]) => {
56
+ if (!(v === undefined || v === '' || (flags.dropEmpty && !isNonEmpty(v)))) {
57
+ friendbuyPayload[k] = v;
58
+ }
59
+ });
60
+ return friendbuyPayload;
61
+ }
62
+ exports.createFriendbuyPayload = createFriendbuyPayload;
63
+ function filterFriendbuyAttributes(api, friendbuyAttributes) {
64
+ const filteredAttributes = [];
65
+ if (friendbuyAttributes) {
66
+ Object.entries(friendbuyAttributes).forEach((attribute) => {
67
+ if (typeof attribute[1] === 'string') {
68
+ if (attribute[0] === 'birthday') {
69
+ const dateRecord = parseDate(attribute[1]);
70
+ if (dateRecord) {
71
+ filteredAttributes.push([attribute[0], dateRecord]);
72
+ }
73
+ }
74
+ else {
75
+ filteredAttributes.push(attribute);
76
+ }
77
+ }
78
+ });
79
+ }
80
+ return (filteredAttributes.length === 0 ? [] :
81
+ api === 'mapi' ? [['additionalProperties', createFriendbuyPayload(filteredAttributes)]]
82
+ : filteredAttributes);
83
+ }
84
+ exports.filterFriendbuyAttributes = filterFriendbuyAttributes;
85
+ const dateRegexp = /^(?:(\d\d\d\d)-)?(\d\d)-(\d\d)(?:[^\d]|$)/;
86
+ function parseDate(date) {
87
+ if (typeof date === 'object' &&
88
+ (!('year' in date) || typeof date.year === 'number') &&
89
+ typeof date.month === 'number' &&
90
+ typeof date.day === 'number') {
91
+ return date;
92
+ }
93
+ if (typeof date !== 'string') {
94
+ return undefined;
95
+ }
96
+ const match = dateRegexp.exec(date);
97
+ if (!match) {
98
+ return undefined;
99
+ }
100
+ const year = match[1] && match[1] !== '0000' ? { year: parseInt(match[1], 10) } : {};
101
+ return { month: parseInt(match[2], 10), day: parseInt(match[3], 10), ...year };
102
+ }
103
+ exports.parseDate = parseDate;
104
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/friendbuy/util.ts"],"names":[],"mappings":";;;AAUA,SAAgB,OAAO,CAAC,OAAsB;IAE5C,OAAO,CACL,OAAO,CAAC,IAAI,CAA0B,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACtD,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,QAAQ,EAAE;YAClF,CAAC,CAAuC,SAAS,CAClD,CAAA;AACH,CAAC;AAPD,0BAOC;AAED,SAAgB,OAAO,CAAC,OAAkC;IACxD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,QAAQ,EAAE;QACzF,OAAO,CAAC,IAAI,GAAG,GAAG,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAA;KAC1D;AACH,CAAC;AAJD,0BAIC;AAED,SAAgB,oBAAoB,CAAC,OAAuC;IAC1E,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE;QAC9F,OAAO,OAAO,CAAA;KACf;IAED,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,CAAA;IACxB,OAAO,OAAO,CAAC,QAAQ,CAAA;IACvB,OAAO,OAAO,CAAA;AAChB,CAAC;AARD,oDAQC;AAED,SAAgB,yBAAyB,CAAC,OAAyB;IACjE,IAAI,OAAO,OAAO,KAAK,Q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,CAAA;IACnC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,SAAS,CAAA;KACjB;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACpF,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAA;AAChF,CAAC;AArBD,8BAqBC"}
@@ -0,0 +1,8 @@
1
+ export * from './friendbuy/commonFields';
2
+ export * from './friendbuy/contextFields';
3
+ export * from './friendbuy/mapEvent';
4
+ export * from './friendbuy/sharedCustomer';
5
+ export * from './friendbuy/sharedCustomEvent';
6
+ export * from './friendbuy/sharedPurchase';
7
+ export * from './friendbuy/sharedSignUp';
8
+ export * from './friendbuy/util';
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./friendbuy/commonFields"), exports);
14
+ __exportStar(require("./friendbuy/contextFields"), exports);
15
+ __exportStar(require("./friendbuy/mapEvent"), exports);
16
+ __exportStar(require("./friendbuy/sharedCustomer"), exports);
17
+ __exportStar(require("./friendbuy/sharedCustomEvent"), exports);
18
+ __exportStar(require("./friendbuy/sharedPurchase"), exports);
19
+ __exportStar(require("./friendbuy/sharedSignUp"), exports);
20
+ __exportStar(require("./friendbuy/util"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAwC;AACxC,4DAAyC;AACzC,uDAAoC;AACpC,6DAA0C;AAC1C,gEAA6C;AAC7C,6DAA0C;AAC1C,2DAAwC;AACxC,mDAAgC"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@segment/actions-shared",
3
+ "description": "Shared destination action methods and definitions.",
4
+ "version": "1.0.1-alpha.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/segmentio/action-destinations",
8
+ "directory": "packages/actions-shared"
9
+ },
10
+ "main": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "files": [
13
+ "dist",
14
+ "package.json"
15
+ ],
16
+ "engines": {
17
+ "node": "^14.16"
18
+ },
19
+ "engineStrict": true,
20
+ "license": "MIT",
21
+ "publishConfig": {
22
+ "access": "public",
23
+ "registry": "https://registry.npmjs.org"
24
+ },
25
+ "scripts": {
26
+ "build": "yarn clean && yarn tsc -b tsconfig.build.json",
27
+ "clean": "tsc -b tsconfig.build.json --clean",
28
+ "postclean": "rm -rf dist",
29
+ "prepublishOnly": "yarn build",
30
+ "test": "jest",
31
+ "typecheck": "tsc -p tsconfig.build.json --noEmit"
32
+ },
33
+ "devDependencies": {
34
+ "@types/jest": "^27.0.0",
35
+ "@types/mustache": "^4.1.2",
36
+ "jest": "^27.3.1",
37
+ "nock": "^13.1.4"
38
+ },
39
+ "dependencies": {
40
+ "@amplitude/ua-parser-js": "^0.7.25",
41
+ "@segment/actions-core": "^3.21.1",
42
+ "cheerio": "^1.0.0-rc.10",
43
+ "dayjs": "^1.10.7",
44
+ "escape-goat": "^3",
45
+ "lodash": "^4.17.21",
46
+ "mustache": "^4.2.0"
47
+ },
48
+ "jest": {
49
+ "preset": "ts-jest",
50
+ "testEnvironment": "node",
51
+ "modulePathIgnorePatterns": [
52
+ "<rootDir>/dist/"
53
+ ],
54
+ "moduleNameMapper": {
55
+ "@segment/ajv-human-errors": "<rootDir>/../ajv-human-errors/src",
56
+ "@segment/actions-core": "<rootDir>/../core/src",
57
+ "@segment/destination-subscriptions": "<rootDir>/../destination-subscriptions/src"
58
+ },
59
+ "setupFilesAfterEnv": [
60
+ "<rootDir>/test/setup-after-env.ts"
61
+ ]
62
+ },
63
+ "gitHead": "86ab5bacabe73e862014b787335076c40ddaf624"
64
+ }