@segment/action-destinations 3.421.1-staging-e3064f0f4.0 → 3.421.1-staging-a34dd23ea.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,2 @@
1
+ export declare const BASE_URL = "https://campaign.api.bingads.microsoft.com/CampaignManagement/v13";
2
+ export declare const TOKEN_URL = "https://login.microsoftonline.com/common/oauth2/v2.0/token";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TOKEN_URL = exports.BASE_URL = void 0;
4
+ const API_VERSION = 'v13';
5
+ exports.BASE_URL = `https://campaign.api.bingads.microsoft.com/CampaignManagement/${API_VERSION}`;
6
+ exports.TOKEN_URL = 'https://login.microsoftonline.com/common/oauth2/v2.0/token';
7
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/destinations/ms-bing-ads-audiences/constants.ts"],"names":[],"mappings":";;;AAAA,MAAM,WAAW,GAAG,KAAK,CAAA;AACZ,QAAA,QAAQ,GAAG,iEAAiE,WAAW,EAAE,CAAA;AACzF,QAAA,SAAS,GAAG,4DAA4D,CAAA"}
@@ -1,2 +1,5 @@
1
1
  export interface Settings {
2
+ developerToken: string;
3
+ customerAccountId: string;
4
+ customerId: string;
2
5
  }
@@ -1,4 +1,4 @@
1
- import type { AudienceDestinationDefinition } from '@segment/actions-core';
1
+ import { AudienceDestinationDefinition } from '@segment/actions-core';
2
2
  import type { Settings } from './generated-types';
3
3
  declare const destination: AudienceDestinationDefinition<Settings>;
4
4
  export default destination;
@@ -3,19 +3,59 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const actions_core_1 = require("@segment/actions-core");
6
7
  const syncAudiences_1 = __importDefault(require("./syncAudiences"));
8
+ const constants_1 = require("./constants");
7
9
  const destination = {
8
10
  name: 'Ms Bing Ads Audiences',
9
11
  slug: 'actions-ms-bing-ads-audiences',
10
12
  mode: 'cloud',
11
13
  authentication: {
12
14
  scheme: 'oauth2',
13
- fields: {}
15
+ fields: {
16
+ developerToken: {
17
+ label: 'Developer Token',
18
+ description: 'The developer token for authenticating API requests. You can find it in the Microsoft Advertising UI under Settings → Developer Settings.',
19
+ type: 'string',
20
+ required: true
21
+ },
22
+ customerAccountId: {
23
+ label: 'Customer Account ID',
24
+ description: 'The account ID of the Microsoft Advertising account you want to manage. You can find it in the URL when viewing the account in the Microsoft Ads UI.',
25
+ type: 'string',
26
+ required: true
27
+ },
28
+ customerId: {
29
+ label: 'Customer ID',
30
+ description: 'The customer (parent) ID associated with your Microsoft Advertising account. You can also find this in the URL when viewing your account in the Microsoft Ads UI.',
31
+ type: 'string',
32
+ required: true
33
+ }
34
+ },
35
+ refreshAccessToken: async (request, { auth }) => {
36
+ const res = await request(constants_1.TOKEN_URL, {
37
+ method: 'POST',
38
+ body: new URLSearchParams({
39
+ refresh_token: auth.refreshToken,
40
+ client_id: auth.clientId,
41
+ client_secret: auth.clientSecret,
42
+ grant_type: 'refresh_token',
43
+ scope: 'https://ads.microsoft.com/msads.manage offline_access'
44
+ })
45
+ });
46
+ return {
47
+ accessToken: res?.data?.access_token,
48
+ refreshToken: res?.data?.refresh_token
49
+ };
50
+ }
14
51
  },
15
- extendRequest({ auth }) {
52
+ extendRequest({ auth, settings }) {
16
53
  return {
17
54
  headers: {
18
- authorization: `Bearer ${auth?.accessToken}`
55
+ Authorization: `Bearer ${auth?.accessToken}`,
56
+ DeveloperToken: settings?.developerToken,
57
+ CustomerAccountId: settings?.customerAccountId,
58
+ CustomerId: settings?.customerId
19
59
  }
20
60
  };
21
61
  },
@@ -24,6 +64,45 @@ const destination = {
24
64
  mode: {
25
65
  type: 'synced',
26
66
  full_audience_sync: false
67
+ },
68
+ createAudience: async (request, createAudienceInput) => {
69
+ const audienceName = createAudienceInput?.audienceName;
70
+ if (!audienceName) {
71
+ throw new actions_core_1.PayloadValidationError('Missing audience name value');
72
+ }
73
+ const response = await request(`${constants_1.BASE_URL}/Audiences`, {
74
+ method: 'POST',
75
+ json: {
76
+ Audiences: [
77
+ {
78
+ Name: audienceName,
79
+ Type: 'CustomerList'
80
+ }
81
+ ]
82
+ }
83
+ });
84
+ if (response?.data?.PartialErrors?.length) {
85
+ const errorObj = response.data.PartialErrors[0];
86
+ if (errorObj?.ErrorCode === 'CustomerListTermsAndConditionsNotAccepted') {
87
+ throw new actions_core_1.IntegrationError("The Customer Match 'Terms And Conditions' are not yet Accepted in the Microsoft Advertising web UI. Please create a Customer List in the Microsoft Advertising UI to accept the terms.", 'TERMS_NOT_ACCEPTED', 400);
88
+ }
89
+ }
90
+ const audienceId = response?.data?.AudienceIds?.[0];
91
+ if (!audienceId) {
92
+ throw new actions_core_1.IntegrationError('Failed to create audience: No AudienceId returned', 'NO_AUDIENCE_ID', 400);
93
+ }
94
+ return { externalId: audienceId };
95
+ },
96
+ getAudience: async (request, getAudienceInput) => {
97
+ const audienceId = getAudienceInput?.externalId;
98
+ const response = await request(`${constants_1.BASE_URL}/Audiences/QueryByIds`, {
99
+ method: 'POST',
100
+ json: {
101
+ AudienceIds: [audienceId],
102
+ Type: 'CustomerList'
103
+ }
104
+ });
105
+ return { externalId: response?.data?.Audiences?.[0]?.Id };
27
106
  }
28
107
  },
29
108
  actions: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/ms-bing-ads-audiences/index.ts"],"names":[],"mappings":";;;;;AAEA,oEAA2C;AAG3C,MAAM,WAAW,GAA4C;IAC3D,IAAI,EAAE,uBAAuB;IAC7B,IAAI,EAAE,+BAA+B;IACrC,IAAI,EAAE,OAAO;IAEb,cAAc,EAAE;QACd,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,EAAE;KAoBX;IACD,aAAa,CAAC,EAAE,IAAI,EAAE;QACpB,OAAO;YACL,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,IAAI,EAAE,WAAW,EAAE;aAC7C;SACF,CAAA;IACH,CAAC;IAED,cAAc,EAAE,EAAE;IAElB,cAAc,EAAE;QACd,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,kBAAkB,EAAE,KAAK;SAC1B;KAaF;IAQD,OAAO,EAAE;QACP,aAAa,EAAb,uBAAa;KACd;CACF,CAAA;AAED,kBAAe,WAAW,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/ms-bing-ads-audiences/index.ts"],"names":[],"mappings":";;;;;AAAA,wDAA+G;AAE/G,oEAA2C;AAE3C,2CAAiD;AAEjD,MAAM,WAAW,GAA4C;IAC3D,IAAI,EAAE,uBAAuB;IAC7B,IAAI,EAAE,+BAA+B;IACrC,IAAI,EAAE,OAAO;IAEb,cAAc,EAAE;QACd,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE;YACN,cAAc,EAAE;gBACd,KAAK,EAAE,iBAAiB;gBACxB,WAAW,EACT,2IAA2I;gBAC7I,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;aACf;YACD,iBAAiB,EAAE;gBACjB,KAAK,EAAE,qBAAqB;gBAC5B,WAAW,EACT,sJAAsJ;gBACxJ,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;aACf;YACD,UAAU,EAAE;gBACV,KAAK,EAAE,aAAa;gBACpB,WAAW,EACT,mKAAmK;gBACrK,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;aACf;SACF;QACD,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;YAG9C,MAAM,GAAG,GAAG,MAAM,OAAO,CAAuB,qBAAS,EAAE;gBACzD,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,IAAI,eAAe,CAAC;oBACxB,aAAa,EAAE,IAAI,CA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AAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;gBAC/C,IAAI,QAAQ,EAAE,SAAS,KAAK,2CAA2C,EAAE,CAAC;oBACxE,MAAM,IAAI,+BAAgB,CACxB,wLAAwL,EACxL,oBAAoB,EACpB,GAAG,CACJ,CAAA;gBACH,CAAC;YACH,CAAC;YAGD,MAAM,UAAU,GAAG,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,CAAA;YACnD,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,MAAM,IAAI,+BAAgB,CAAC,mDAAmD,EAAE,gBAAgB,EAAE,GAAG,CAAC,CAAA;YACxG,CAAC;YAED,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,CAAA;QACnC,CAAC;QACD,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE;YAG/C,MAAM,UAAU,GAAG,gBAAgB,EAAE,UAAU,CAAA;YAC/C,MAAM,QAAQ,GAAwB,MAAM,OAAO,CAAC,GAAG,oBAAQ,uBAAuB,EAAE;gBACtF,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE;oBACJ,WAAW,EAAE,CAAC,UAAU,CAAC;oBACzB,IAAI,EAAE,cAAc;iBACrB;aACF,CAAC,CAAA;YAEF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAA;QAC3D,CAAC;KACF;IAED,OAAO,EAAE;QACP,aAAa,EAAb,uBAAa;KACd;CACF,CAAA;AAED,kBAAe,WAAW,CAAA"}
@@ -0,0 +1,29 @@
1
+ export interface RefreshTokenResponse {
2
+ access_token: string;
3
+ refresh_token?: string;
4
+ }
5
+ export interface CreateAudienceResponse {
6
+ data: {
7
+ AudienceIds: string[];
8
+ PartialErrors: {
9
+ FieldPath: string | null;
10
+ ErrorCode: string;
11
+ Message: string;
12
+ Code: number;
13
+ Details: string | null;
14
+ Index: number;
15
+ Type: string;
16
+ ForwardCompatibilityMap: null;
17
+ }[];
18
+ };
19
+ }
20
+ export interface GetAudienceResponse {
21
+ data: {
22
+ Audiences: [
23
+ {
24
+ Id: string;
25
+ }
26
+ ];
27
+ PartialErrors: [];
28
+ };
29
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/destinations/ms-bing-ads-audiences/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@segment/action-destinations",
3
3
  "description": "Destination Actions engine and definitions.",
4
- "version": "3.421.1-staging-e3064f0f4.0",
4
+ "version": "3.421.1-staging-a34dd23ea.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/segmentio/action-destinations",
@@ -91,5 +91,5 @@
91
91
  "__tests__/__helpers__/"
92
92
  ]
93
93
  },
94
- "gitHead": "59b456226a762937ea13f709e06b30f5d0809381"
94
+ "gitHead": "2c74d97fda376035e638c92a5fdc3db5f0f21211"
95
95
  }