@postrun/js 3.0.0 → 3.2.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/dist/index.cjs CHANGED
@@ -3,6 +3,7 @@
3
3
  var z = require('zod');
4
4
  var Uppy = require('@uppy/core');
5
5
  var AwsS3 = require('@uppy/aws-s3');
6
+ var pWaitFor = require('p-wait-for');
6
7
 
7
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
9
 
@@ -27,6 +28,7 @@ function _interopNamespace(e) {
27
28
  var z__namespace = /*#__PURE__*/_interopNamespace(z);
28
29
  var Uppy__default = /*#__PURE__*/_interopDefault(Uppy);
29
30
  var AwsS3__default = /*#__PURE__*/_interopDefault(AwsS3);
31
+ var pWaitFor__default = /*#__PURE__*/_interopDefault(pWaitFor);
30
32
 
31
33
  // src/client/core/bodySerializer.gen.ts
32
34
  var jsonBodySerializer = {
@@ -824,6 +826,7 @@ var zErrorCode = z__namespace.enum([
824
826
  "media_processing",
825
827
  "media_upload_init_failed",
826
828
  "media_upload_incomplete",
829
+ "media_upload_invalid_parts",
827
830
  "not_publishable",
828
831
  "invalid_connection",
829
832
  "invalid_media",
@@ -1284,6 +1287,7 @@ var zPostVariant = z__namespace.union([
1284
1287
  "media_processing",
1285
1288
  "media_upload_init_failed",
1286
1289
  "media_upload_incomplete",
1290
+ "media_upload_invalid_parts",
1287
1291
  "not_publishable",
1288
1292
  "invalid_connection",
1289
1293
  "invalid_media",
@@ -1464,6 +1468,7 @@ var zPostVariant = z__namespace.union([
1464
1468
  "media_processing",
1465
1469
  "media_upload_init_failed",
1466
1470
  "media_upload_incomplete",
1471
+ "media_upload_invalid_parts",
1467
1472
  "not_publishable",
1468
1473
  "invalid_connection",
1469
1474
  "invalid_media",
@@ -1628,6 +1633,7 @@ var zPostVariant = z__namespace.union([
1628
1633
  "media_processing",
1629
1634
  "media_upload_init_failed",
1630
1635
  "media_upload_incomplete",
1636
+ "media_upload_invalid_parts",
1631
1637
  "not_publishable",
1632
1638
  "invalid_connection",
1633
1639
  "invalid_media",
@@ -1793,6 +1799,7 @@ var zPostVariant = z__namespace.union([
1793
1799
  "media_processing",
1794
1800
  "media_upload_init_failed",
1795
1801
  "media_upload_incomplete",
1802
+ "media_upload_invalid_parts",
1796
1803
  "not_publishable",
1797
1804
  "invalid_connection",
1798
1805
  "invalid_media",
@@ -1962,6 +1969,7 @@ var zPostVariant = z__namespace.union([
1962
1969
  "media_processing",
1963
1970
  "media_upload_init_failed",
1964
1971
  "media_upload_incomplete",
1972
+ "media_upload_invalid_parts",
1965
1973
  "not_publishable",
1966
1974
  "invalid_connection",
1967
1975
  "invalid_media",
@@ -2975,6 +2983,7 @@ var zGoogleAdsConversionStatusReason = z__namespace.object({
2975
2983
  "media_processing",
2976
2984
  "media_upload_init_failed",
2977
2985
  "media_upload_incomplete",
2986
+ "media_upload_invalid_parts",
2978
2987
  "not_publishable",
2979
2988
  "invalid_connection",
2980
2989
  "invalid_media",
@@ -3640,6 +3649,7 @@ z__namespace.object({
3640
3649
  "media_processing",
3641
3650
  "media_upload_init_failed",
3642
3651
  "media_upload_incomplete",
3652
+ "media_upload_invalid_parts",
3643
3653
  "not_publishable",
3644
3654
  "invalid_connection",
3645
3655
  "invalid_media",
@@ -4831,6 +4841,8 @@ z__namespace.object({
4831
4841
  "ONE_PER_CLICK",
4832
4842
  "MANY_PER_CLICK"
4833
4843
  ]),
4844
+ click_through_lookback_window_days: z__namespace.number().nullable(),
4845
+ view_through_lookback_window_days: z__namespace.number().nullable(),
4834
4846
  value_settings: z__namespace.object({
4835
4847
  default_value: z__namespace.number().nullable(),
4836
4848
  default_currency_code: z__namespace.string().nullable(),
@@ -5010,6 +5022,8 @@ z__namespace.object({
5010
5022
  "ONE_PER_CLICK",
5011
5023
  "MANY_PER_CLICK"
5012
5024
  ]),
5025
+ click_through_lookback_window_days: z__namespace.number().nullable(),
5026
+ view_through_lookback_window_days: z__namespace.number().nullable(),
5013
5027
  value_settings: z__namespace.object({
5014
5028
  default_value: z__namespace.number().nullable(),
5015
5029
  default_currency_code: z__namespace.string().nullable(),
@@ -5034,6 +5048,61 @@ z__namespace.object({
5034
5048
  event_snippet: z__namespace.string().nullable()
5035
5049
  }))
5036
5050
  });
5051
+ z__namespace.object({
5052
+ name: z__namespace.string().min(1).max(255).optional(),
5053
+ category: z__namespace.enum([
5054
+ "DEFAULT",
5055
+ "PAGE_VIEW",
5056
+ "PURCHASE",
5057
+ "SIGNUP",
5058
+ "DOWNLOAD",
5059
+ "ADD_TO_CART",
5060
+ "BEGIN_CHECKOUT",
5061
+ "SUBSCRIBE_PAID",
5062
+ "PHONE_CALL_LEAD",
5063
+ "IMPORTED_LEAD",
5064
+ "SUBMIT_LEAD_FORM",
5065
+ "BOOK_APPOINTMENT",
5066
+ "REQUEST_QUOTE",
5067
+ "GET_DIRECTIONS",
5068
+ "OUTBOUND_CLICK",
5069
+ "CONTACT",
5070
+ "ENGAGEMENT",
5071
+ "STORE_VISIT",
5072
+ "STORE_SALE",
5073
+ "QUALIFIED_LEAD",
5074
+ "CONVERTED_LEAD",
5075
+ "YOUTUBE_FOLLOW_ON_VIEWS"
5076
+ ]).optional(),
5077
+ status: z__namespace.enum(["ENABLED"]).optional(),
5078
+ value_settings: z__namespace.object({
5079
+ default_value: z__namespace.number().gte(0).optional(),
5080
+ default_currency_code: z__namespace.string().length(3).optional(),
5081
+ always_use_default_value: z__namespace.boolean().optional()
5082
+ }).optional(),
5083
+ counting_type: z__namespace.enum(["ONE_PER_CLICK", "MANY_PER_CLICK"]).optional(),
5084
+ click_through_lookback_window_days: z__namespace.int().gt(0).lte(9007199254740991).optional(),
5085
+ view_through_lookback_window_days: z__namespace.int().gt(0).lte(9007199254740991).optional(),
5086
+ primary_for_goal: z__namespace.boolean().optional(),
5087
+ dry_run: z__namespace.boolean().optional().default(false)
5088
+ });
5089
+ z__namespace.object({
5090
+ "Idempotency-Key": z__namespace.string().min(1).max(255).optional()
5091
+ });
5092
+ z__namespace.object({
5093
+ connection_id: z__namespace.string(),
5094
+ id: z__namespace.string().regex(/^\d+$/)
5095
+ });
5096
+ z__namespace.object({
5097
+ dry_run: z__namespace.boolean().optional().default(false)
5098
+ });
5099
+ z__namespace.object({
5100
+ "Idempotency-Key": z__namespace.string().min(1).max(255).optional()
5101
+ });
5102
+ z__namespace.object({
5103
+ connection_id: z__namespace.string(),
5104
+ id: z__namespace.string().regex(/^\d+$/)
5105
+ });
5037
5106
  z__namespace.object({
5038
5107
  conversion_action_id: z__namespace.string().regex(/^\d+$/),
5039
5108
  conversions: z__namespace.array(zGoogleAdsConversionEvent).min(1).max(2e3),
@@ -5291,6 +5360,7 @@ z__namespace.object({
5291
5360
  "media_processing",
5292
5361
  "media_upload_init_failed",
5293
5362
  "media_upload_incomplete",
5363
+ "media_upload_invalid_parts",
5294
5364
  "not_publishable",
5295
5365
  "invalid_connection",
5296
5366
  "invalid_media",
@@ -5450,6 +5520,7 @@ z__namespace.object({
5450
5520
  "media_processing",
5451
5521
  "media_upload_init_failed",
5452
5522
  "media_upload_incomplete",
5523
+ "media_upload_invalid_parts",
5453
5524
  "not_publishable",
5454
5525
  "invalid_connection",
5455
5526
  "invalid_media",
@@ -5630,6 +5701,7 @@ z__namespace.object({
5630
5701
  "media_processing",
5631
5702
  "media_upload_init_failed",
5632
5703
  "media_upload_incomplete",
5704
+ "media_upload_invalid_parts",
5633
5705
  "not_publishable",
5634
5706
  "invalid_connection",
5635
5707
  "invalid_media",
@@ -5789,6 +5861,7 @@ z__namespace.object({
5789
5861
  "media_processing",
5790
5862
  "media_upload_init_failed",
5791
5863
  "media_upload_incomplete",
5864
+ "media_upload_invalid_parts",
5792
5865
  "not_publishable",
5793
5866
  "invalid_connection",
5794
5867
  "invalid_media",
@@ -6076,8 +6149,54 @@ var PostrunError = class extends Error {
6076
6149
  }
6077
6150
  };
6078
6151
 
6152
+ // src/token-cache.ts
6153
+ function createTokenCache(getToken) {
6154
+ let cached;
6155
+ let inFlight;
6156
+ const mint = () => {
6157
+ if (!inFlight) {
6158
+ inFlight = Promise.resolve().then(getToken).then((token) => {
6159
+ cached = token;
6160
+ return token;
6161
+ }).finally(() => {
6162
+ inFlight = void 0;
6163
+ });
6164
+ }
6165
+ return inFlight;
6166
+ };
6167
+ return {
6168
+ current() {
6169
+ return cached !== void 0 ? Promise.resolve(cached) : mint();
6170
+ },
6171
+ refresh() {
6172
+ cached = void 0;
6173
+ return mint();
6174
+ }
6175
+ };
6176
+ }
6177
+
6079
6178
  // src/client.ts
6080
6179
  var DEFAULT_BASE_URL = "https://api.postrun.ai/v1";
6180
+ var UNAUTHORIZED = 401;
6181
+ function createRetryingFetch(tokenCache) {
6182
+ const realFetch = (...args) => globalThis.fetch(...args);
6183
+ return async (input, init) => {
6184
+ const request = new Request(input, init);
6185
+ const retryable = request.clone();
6186
+ const response = await realFetch(request);
6187
+ if (response.status !== UNAUTHORIZED) {
6188
+ return response;
6189
+ }
6190
+ try {
6191
+ const token = await tokenCache.refresh();
6192
+ const headers = new Headers(retryable.headers);
6193
+ headers.set("Authorization", `Bearer ${token}`);
6194
+ return await realFetch(new Request(retryable, { headers }));
6195
+ } catch {
6196
+ return response;
6197
+ }
6198
+ };
6199
+ }
6081
6200
  function appendScalar(parts, key, value) {
6082
6201
  parts.push(
6083
6202
  `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`
@@ -6104,10 +6223,12 @@ function serializeQuery(query) {
6104
6223
  return parts.join("&");
6105
6224
  }
6106
6225
  function createPostrunClient(options) {
6226
+ const tokenCache = createTokenCache(options.getToken);
6107
6227
  const client2 = createClient(
6108
6228
  createConfig({
6109
6229
  baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
6110
- auth: () => options.getToken(),
6230
+ auth: () => tokenCache.current(),
6231
+ fetch: createRetryingFetch(tokenCache),
6111
6232
  querySerializer: serializeQuery,
6112
6233
  throwOnError: true
6113
6234
  })
@@ -7378,6 +7499,40 @@ var googleGetConversionAction = (options) => (options.client ?? client).get({
7378
7499
  url: "/google/{connection_id}/conversion-actions/{id}",
7379
7500
  ...options
7380
7501
  });
7502
+ var googleUpdateConversionAction = (options) => (options.client ?? client).patch({
7503
+ security: [{
7504
+ key: "secretKey",
7505
+ scheme: "bearer",
7506
+ type: "http"
7507
+ }, {
7508
+ key: "frontendToken",
7509
+ scheme: "bearer",
7510
+ type: "http"
7511
+ }],
7512
+ url: "/google/{connection_id}/conversion-actions/{id}",
7513
+ ...options,
7514
+ headers: {
7515
+ "Content-Type": "application/json",
7516
+ ...options.headers
7517
+ }
7518
+ });
7519
+ var googleRemoveConversionAction = (options) => (options.client ?? client).post({
7520
+ security: [{
7521
+ key: "secretKey",
7522
+ scheme: "bearer",
7523
+ type: "http"
7524
+ }, {
7525
+ key: "frontendToken",
7526
+ scheme: "bearer",
7527
+ type: "http"
7528
+ }],
7529
+ url: "/google/{connection_id}/conversion-actions/{id}/remove",
7530
+ ...options,
7531
+ headers: {
7532
+ "Content-Type": "application/json",
7533
+ ...options.headers
7534
+ }
7535
+ });
7381
7536
  var googleSendConversions = (options) => (options.client ?? client).post({
7382
7537
  security: [{
7383
7538
  key: "secretKey",
@@ -7706,6 +7861,33 @@ async function uploadFile(file, options) {
7706
7861
  function fileName(file) {
7707
7862
  return file instanceof File ? file.name : "upload";
7708
7863
  }
7864
+ var DEFAULT_POLL_INTERVAL_MS = 1500;
7865
+ var DEFAULT_POLL_TIMEOUT_MS = 30 * 60 * 1e3;
7866
+ async function waitForMedia(mediaId, options = {}) {
7867
+ const {
7868
+ client: client2,
7869
+ pollInterval = DEFAULT_POLL_INTERVAL_MS,
7870
+ timeout = DEFAULT_POLL_TIMEOUT_MS,
7871
+ signal,
7872
+ onPoll
7873
+ } = options;
7874
+ let latest;
7875
+ await pWaitFor__default.default(
7876
+ async () => {
7877
+ if (signal?.aborted) {
7878
+ throw new DOMException("Media wait aborted", "AbortError");
7879
+ }
7880
+ latest = (await mediaGet({ client: client2, path: { id: mediaId } })).data;
7881
+ onPoll?.(latest);
7882
+ return latest.status === "ready" || latest.status === "failed";
7883
+ },
7884
+ { interval: pollInterval, timeout }
7885
+ );
7886
+ if (!latest) {
7887
+ throw new Error("Media polling returned no result.");
7888
+ }
7889
+ return latest;
7890
+ }
7709
7891
 
7710
7892
  // src/tiktok.ts
7711
7893
  function tiktokPrivacyLabel(value) {
@@ -8107,6 +8289,7 @@ exports.googleRemoveAdGroupCriterion = googleRemoveAdGroupCriterion;
8107
8289
  exports.googleRemoveBudget = googleRemoveBudget;
8108
8290
  exports.googleRemoveCampaign = googleRemoveCampaign;
8109
8291
  exports.googleRemoveCampaignCriterion = googleRemoveCampaignCriterion;
8292
+ exports.googleRemoveConversionAction = googleRemoveConversionAction;
8110
8293
  exports.googleRemoveKeyword = googleRemoveKeyword;
8111
8294
  exports.googleRunGaql = googleRunGaql;
8112
8295
  exports.googleSearchGeoTargets = googleSearchGeoTargets;
@@ -8116,6 +8299,7 @@ exports.googleSetCampaignGeoSettings = googleSetCampaignGeoSettings;
8116
8299
  exports.googleSetCampaignTargetingSetting = googleSetCampaignTargetingSetting;
8117
8300
  exports.googleSetConversionGoal = googleSetConversionGoal;
8118
8301
  exports.googleSetKeywordBid = googleSetKeywordBid;
8302
+ exports.googleUpdateConversionAction = googleUpdateConversionAction;
8119
8303
  exports.googleUploadImageAsset = googleUploadImageAsset;
8120
8304
  exports.groupAdTree = groupAdTree;
8121
8305
  exports.interactionRows = interactionRows;
@@ -8165,6 +8349,7 @@ exports.tiktokSettings = tiktokSettings;
8165
8349
  exports.toggleInteraction = toggleInteraction;
8166
8350
  exports.tokensMint = tokensMint;
8167
8351
  exports.uploadFile = uploadFile;
8352
+ exports.waitForMedia = waitForMedia;
8168
8353
  exports.webhooksCreateEndpoint = webhooksCreateEndpoint;
8169
8354
  exports.webhooksCreatePortal = webhooksCreatePortal;
8170
8355
  exports.webhooksDeleteEndpoint = webhooksDeleteEndpoint;