@bigbeakads/smartads-sdk-js 0.0.2 → 0.0.4

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 CHANGED
@@ -49,10 +49,10 @@ Reports an event to the SmartAds server. Returns a `Promise<Response>`. Supports
49
49
 
50
50
  #### Parameters
51
51
 
52
- | Parameter | Type | Required | Default | Description |
53
- | ----------- | ---------------------------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54
- | `eventName` | `EventName` | **Yes** | — | The event name to report. Supported values: `EVENT_ADD_TO_CART`, `EVENT_PURCHASE`, `EVENT_CONTENT_VIEW`, `EVENT_COMPLETE_REGISTRATION`, `EVENT_FIRST_DEPOSIT` |
55
- | `callback` | `(response, error?) => void` | No | — | Response-first callback |
52
+ | Parameter | Type | Required | Default | Description |
53
+ | ----------- | -------------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54
+ | `eventName` | `EventName` | **Yes** | — | The event name to report. Supported values: `EVENT_ADD_TO_CART`, `EVENT_PURCHASE`, `EVENT_CONTENT_VIEW`, `EVENT_COMPLETE_REGISTRATION`, `EVENT_FIRST_DEPOSIT`, `EVENT_INITIATE_CHECKOUT` |
55
+ | `callback` | `(response) => void` | No | — | Response callback |
56
56
 
57
57
  #### Promise Usage
58
58
 
@@ -68,11 +68,7 @@ console.log('Response:', response);
68
68
  ```js
69
69
  smartAds.report({
70
70
  eventName: 'EVENT_PURCHASE',
71
- callback: (response, error) => {
72
- if (error) {
73
- console.error('Report failed:', error.message);
74
- return;
75
- }
71
+ callback: (response) => {
76
72
  console.log('Response:', response);
77
73
  },
78
74
  });
@@ -1,24 +1,18 @@
1
- type EventName = 'EVENT_ADD_TO_CART' | 'EVENT_PURCHASE' | 'EVENT_CONTENT_VIEW' | 'EVENT_COMPLETE_REGISTRATION' | 'EVENT_FIRST_DEPOSIT';
1
+ type EventName = 'EVENT_ADD_TO_CART' | 'EVENT_PURCHASE' | 'EVENT_CONTENT_VIEW' | 'EVENT_COMPLETE_REGISTRATION' | 'EVENT_FIRST_DEPOSIT' | 'EVENT_INITIATE_CHECKOUT';
2
2
  interface SmartAdsOptions {
3
3
  accessToken: string;
4
4
  }
5
5
  interface ReportCallback {
6
6
  (response: Response | null, error?: Error): void;
7
7
  }
8
- interface KwaiReportOptions {
8
+ interface ReportOptions {
9
+ smartId: string;
9
10
  eventName: EventName;
10
11
  callback?: ReportCallback;
11
12
  }
12
- interface TTReportOptions {
13
- eventName: EventName;
14
- callback?: ReportCallback;
15
- }
16
- type ReportOptions = KwaiReportOptions | TTReportOptions;
17
13
  declare class SmartAds {
18
14
  private accessToken;
19
15
  constructor(options: SmartAdsOptions);
20
- private reportKwai;
21
- private reportTT;
22
16
  report(options: ReportOptions): Promise<Response>;
23
17
  }
24
18
  export { SmartAds, type EventName };
package/dist/esm/index.js CHANGED
@@ -8,15 +8,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
8
8
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
9
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
10
10
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
11
- var POSTBACK_URL = 'https://agent.ads-server-k.com/smartads/api/v1/postback/kwai';
12
- function getUrlParam(name) {
13
- try {
14
- var url = new URL(window.location.href);
15
- return url.searchParams.get(name) || '';
16
- } catch (_unused) {
17
- return '';
18
- }
19
- }
11
+ var POSTBACK_URL = 'https://agent.ads-server-k.com/smartads/api/v1/postback/smart';
20
12
  var SmartAds = /*#__PURE__*/function () {
21
13
  function SmartAds(options) {
22
14
  _classCallCheck(this, SmartAds);
@@ -27,118 +19,54 @@ var SmartAds = /*#__PURE__*/function () {
27
19
  this.accessToken = options.accessToken;
28
20
  }
29
21
  _createClass(SmartAds, [{
30
- key: "reportKwai",
31
- value: function reportKwai(options) {
32
- var eventName = options.eventName;
33
- if (!eventName) {
34
- throw new Error('eventName is required');
35
- }
36
- var clickid = getUrlParam('click_id');
37
- var pixelId = getUrlParam('pixel_id');
38
- if (!clickid) {
39
- throw new Error('click_id is required in URL parameters');
40
- }
41
- if (!pixelId) {
42
- throw new Error('pixel_id is required in URL parameters');
43
- }
44
- var payload = {
45
- access_token: this.accessToken,
46
- event_name: eventName,
47
- clickid: clickid,
48
- pixelId: pixelId,
49
- is_attributed: 1,
50
- mmpcode: 'PL',
51
- pixelSdkVersion: '9.9.9',
52
- testFlag: false,
53
- trackFlag: false,
54
- properties: '{}'
55
- };
56
- return fetch(POSTBACK_URL, {
57
- method: 'POST',
58
- headers: {
59
- 'Content-Type': 'application/json'
60
- },
61
- body: JSON.stringify(payload)
62
- }).then( /*#__PURE__*/function () {
63
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(response) {
64
- var json;
65
- return _regeneratorRuntime().wrap(function _callee$(_context) {
66
- while (1) switch (_context.prev = _context.next) {
67
- case 0:
68
- _context.next = 2;
69
- return response.json();
70
- case 2:
71
- json = _context.sent;
72
- if (!(json.result === 1)) {
73
- _context.next = 7;
74
- break;
75
- }
76
- return _context.abrupt("return", json);
77
- case 7:
78
- throw new Error(json);
79
- case 8:
80
- case "end":
81
- return _context.stop();
82
- }
83
- }, _callee);
84
- }));
85
- return function (_x) {
86
- return _ref.apply(this, arguments);
87
- };
88
- }()).catch(function (error) {
89
- console.error('Error reporting event:', error);
90
- throw error;
91
- });
92
- }
93
- }, {
94
- key: "reportTT",
95
- value: function reportTT(options) {
96
- // TODO: TT postback logic
97
- throw new Error('TT report not implemented');
98
- }
99
- }, {
100
22
  key: "report",
101
23
  value: function () {
102
- var _report = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
103
- var callback, isTT, _response, _error;
104
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
105
- while (1) switch (_context2.prev = _context2.next) {
24
+ var _report = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
25
+ var smartId, eventName, callback, payload, response, json;
26
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
27
+ while (1) switch (_context.prev = _context.next) {
106
28
  case 0:
107
- callback = options.callback;
108
- isTT = !!getUrlParam('ttclid');
109
- _context2.prev = 2;
110
- if (!isTT) {
111
- _context2.next = 9;
29
+ smartId = options.smartId, eventName = options.eventName, callback = options.callback;
30
+ if (smartId) {
31
+ _context.next = 3;
32
+ break;
33
+ }
34
+ throw new Error('smartId is required');
35
+ case 3:
36
+ if (eventName) {
37
+ _context.next = 5;
112
38
  break;
113
39
  }
114
- _context2.next = 6;
115
- return this.reportTT(options);
116
- case 6:
117
- _context2.t0 = _context2.sent;
118
- _context2.next = 12;
119
- break;
120
- case 9:
121
- _context2.next = 11;
122
- return this.reportKwai(options);
40
+ throw new Error('eventName is required');
41
+ case 5:
42
+ payload = {
43
+ access_token: this.accessToken,
44
+ smartId: smartId,
45
+ event_name: eventName
46
+ };
47
+ _context.next = 8;
48
+ return fetch(POSTBACK_URL, {
49
+ method: 'POST',
50
+ headers: {
51
+ 'Content-Type': 'application/json'
52
+ },
53
+ body: JSON.stringify(payload)
54
+ });
55
+ case 8:
56
+ response = _context.sent;
57
+ _context.next = 11;
58
+ return response.json();
123
59
  case 11:
124
- _context2.t0 = _context2.sent;
125
- case 12:
126
- _response = _context2.t0;
127
- callback === null || callback === void 0 || callback(_response, undefined);
128
- return _context2.abrupt("return", _response);
129
- case 17:
130
- _context2.prev = 17;
131
- _context2.t1 = _context2["catch"](2);
132
- _error = _context2.t1 instanceof Error ? _context2.t1 : new Error(String(_context2.t1));
133
- callback === null || callback === void 0 || callback(null, _error);
134
- throw _error;
135
- case 22:
60
+ json = _context.sent;
61
+ callback === null || callback === void 0 || callback(json);
62
+ return _context.abrupt("return", json);
63
+ case 14:
136
64
  case "end":
137
- return _context2.stop();
65
+ return _context.stop();
138
66
  }
139
- }, _callee2, this, [[2, 17]]);
67
+ }, _callee, this);
140
68
  }));
141
- function report(_x2) {
69
+ function report(_x) {
142
70
  return _report.apply(this, arguments);
143
71
  }
144
72
  return report;
@@ -1 +1 @@
1
- !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var n in r)("object"==typeof exports?exports:t)[n]=r[n]}}(self,(function(){return function(){var t={935:function(t){function e(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}t.exports=function(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function u(t){e(a,o,i,u,c,"next",t)}function c(t){e(a,o,i,u,c,"throw",t)}u(void 0)}))}},t.exports.__esModule=!0,t.exports.default=t.exports},76:function(t){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.__esModule=!0,t.exports.default=t.exports},81:function(t,e,r){var n=r(355);function o(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,n(o.key),o)}}t.exports=function(t,e,r){return e&&o(t.prototype,e),r&&o(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t},t.exports.__esModule=!0,t.exports.default=t.exports},951:function(t,e,r){var n=r(355);t.exports=function(t,e,r){return(e=n(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t},t.exports.__esModule=!0,t.exports.default=t.exports},958:function(t,e,r){var n=r(705).default;function o(){"use strict";t.exports=o=function(){return r},t.exports.__esModule=!0,t.exports.default=t.exports;var e,r={},i=Object.prototype,a=i.hasOwnProperty,u=Object.defineProperty||function(t,e,r){t[e]=r.value},c="function"==typeof Symbol?Symbol:{},s=c.iterator||"@@iterator",f=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function p(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{p({},"")}catch(e){p=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var o=e&&e.prototype instanceof w?e:w,i=Object.create(o.prototype),a=new N(n||[]);return u(i,"_invoke",{value:S(t,r,a)}),i}function d(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}r.wrap=h;var v="suspendedStart",y="executing",m="completed",x={};function w(){}function g(){}function b(){}var _={};p(_,s,(function(){return this}));var E=Object.getPrototypeOf,k=E&&E(E(G([])));k&&k!==i&&a.call(k,s)&&(_=k);var L=b.prototype=w.prototype=Object.create(_);function j(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function r(o,i,u,c){var s=d(t[o],t,i);if("throw"!==s.type){var f=s.arg,l=f.value;return l&&"object"==n(l)&&a.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,u,c)}),(function(t){r("throw",t,u,c)})):e.resolve(l).then((function(t){f.value=t,u(f)}),(function(t){return r("throw",t,u,c)}))}c(s.arg)}var o;u(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}})}function S(t,r,n){var o=v;return function(i,a){if(o===y)throw new Error("Generator is already running");if(o===m){if("throw"===i)throw a;return{value:e,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=T(u,n);if(c){if(c===x)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===v)throw o=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=y;var s=d(t,r,n);if("normal"===s.type){if(o=n.done?m:"suspendedYield",s.arg===x)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=m,n.method="throw",n.arg=s.arg)}}}function T(t,r){var n=r.method,o=t.iterator[n];if(o===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,T(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),x;var i=d(o,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,x;var a=i.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,x):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,x)}function P(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function M(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function G(t){if(t||""===t){var r=t[s];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(a.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(n(t)+" is not iterable")}return g.prototype=b,u(L,"constructor",{value:b,configurable:!0}),u(b,"constructor",{value:g,configurable:!0}),g.displayName=p(b,l,"GeneratorFunction"),r.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,p(t,l,"GeneratorFunction")),t.prototype=Object.create(L),t},r.awrap=function(t){return{__await:t}},j(O.prototype),p(O.prototype,f,(function(){return this})),r.AsyncIterator=O,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new O(h(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},j(L),p(L,l,"Generator"),p(L,s,(function(){return this})),p(L,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=G,N.prototype={constructor:N,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(M),!t)for(var r in this)"t"===r.charAt(0)&&a.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(n,o){return u.type="throw",u.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=a.call(i,"catchLoc"),s=a.call(i,"finallyLoc");if(c&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&a.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,x):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),x},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),M(r),x}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;M(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:G(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),x}},r}t.exports=o,t.exports.__esModule=!0,t.exports.default=t.exports},388:function(t,e,r){var n=r(705).default;t.exports=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)},t.exports.__esModule=!0,t.exports.default=t.exports},355:function(t,e,r){var n=r(705).default,o=r(388);t.exports=function(t){var e=o(t,"string");return"symbol"==n(e)?e:String(e)},t.exports.__esModule=!0,t.exports.default=t.exports},705:function(t){function e(r){return t.exports=e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,{a:e}),e},r.d=function(t,e){for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return function(){"use strict";r.r(n),r.d(n,{SmartAds:function(){return h}});var t=r(958),e=r.n(t),o=r(935),i=r.n(o),a=r(76),u=r.n(a),c=r(81),s=r.n(c),f=r(951),l=r.n(f);function p(t){try{return new URL(window.location.href).searchParams.get(t)||""}catch(t){return""}}var h=function(){function t(e){if(u()(this,t),l()(this,"accessToken",void 0),!e.accessToken)throw new Error("accessToken is required");this.accessToken=e.accessToken}var r;return s()(t,[{key:"reportKwai",value:function(t){var r=t.eventName;if(!r)throw new Error("eventName is required");var n=p("click_id"),o=p("pixel_id");if(!n)throw new Error("click_id is required in URL parameters");if(!o)throw new Error("pixel_id is required in URL parameters");var a={access_token:this.accessToken,event_name:r,clickid:n,pixelId:o,is_attributed:1,mmpcode:"PL",pixelSdkVersion:"9.9.9",testFlag:!1,trackFlag:!1,properties:"{}"};return fetch("https://agent.ads-server-k.com/smartads/api/v1/postback/kwai",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}).then(function(){var t=i()(e()().mark((function t(r){var n;return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,r.json();case 2:if(1!==(n=t.sent).result){t.next=7;break}return t.abrupt("return",n);case 7:throw new Error(n);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()).catch((function(t){throw console.error("Error reporting event:",t),t}))}},{key:"reportTT",value:function(t){throw new Error("TT report not implemented")}},{key:"report",value:(r=i()(e()().mark((function t(r){var n,o,i,a;return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=r.callback,o=!!p("ttclid"),t.prev=2,!o){t.next=9;break}return t.next=6,this.reportTT(r);case 6:t.t0=t.sent,t.next=12;break;case 9:return t.next=11,this.reportKwai(r);case 11:t.t0=t.sent;case 12:return i=t.t0,null==n||n(i,void 0),t.abrupt("return",i);case 17:throw t.prev=17,t.t1=t.catch(2),a=t.t1 instanceof Error?t.t1:new Error(String(t.t1)),null==n||n(null,a),a;case 22:case"end":return t.stop()}}),t,this,[[2,17]])}))),function(t){return r.apply(this,arguments)})}]),t}();n.default=h}(),n}()}));
1
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var n in r)("object"==typeof exports?exports:t)[n]=r[n]}}(self,(function(){return function(){var t={935:function(t){function e(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}t.exports=function(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function u(t){e(a,o,i,u,c,"next",t)}function c(t){e(a,o,i,u,c,"throw",t)}u(void 0)}))}},t.exports.__esModule=!0,t.exports.default=t.exports},76:function(t){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.__esModule=!0,t.exports.default=t.exports},81:function(t,e,r){var n=r(355);function o(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,n(o.key),o)}}t.exports=function(t,e,r){return e&&o(t.prototype,e),r&&o(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t},t.exports.__esModule=!0,t.exports.default=t.exports},951:function(t,e,r){var n=r(355);t.exports=function(t,e,r){return(e=n(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t},t.exports.__esModule=!0,t.exports.default=t.exports},958:function(t,e,r){var n=r(705).default;function o(){"use strict";t.exports=o=function(){return r},t.exports.__esModule=!0,t.exports.default=t.exports;var e,r={},i=Object.prototype,a=i.hasOwnProperty,u=Object.defineProperty||function(t,e,r){t[e]=r.value},c="function"==typeof Symbol?Symbol:{},s=c.iterator||"@@iterator",f=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function p(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{p({},"")}catch(e){p=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var o=e&&e.prototype instanceof g?e:g,i=Object.create(o.prototype),a=new N(n||[]);return u(i,"_invoke",{value:S(t,r,a)}),i}function d(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}r.wrap=h;var y="suspendedStart",v="executing",m="completed",x={};function g(){}function b(){}function w(){}var _={};p(_,s,(function(){return this}));var E=Object.getPrototypeOf,L=E&&E(E(G([])));L&&L!==i&&a.call(L,s)&&(_=L);var j=w.prototype=g.prototype=Object.create(_);function O(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){function r(o,i,u,c){var s=d(t[o],t,i);if("throw"!==s.type){var f=s.arg,l=f.value;return l&&"object"==n(l)&&a.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,u,c)}),(function(t){r("throw",t,u,c)})):e.resolve(l).then((function(t){f.value=t,u(f)}),(function(t){return r("throw",t,u,c)}))}c(s.arg)}var o;u(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}})}function S(t,r,n){var o=y;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===m){if("throw"===i)throw a;return{value:e,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=P(u,n);if(c){if(c===x)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===y)throw o=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var s=d(t,r,n);if("normal"===s.type){if(o=n.done?m:"suspendedYield",s.arg===x)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=m,n.method="throw",n.arg=s.arg)}}}function P(t,r){var n=r.method,o=t.iterator[n];if(o===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,P(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),x;var i=d(o,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,x;var a=i.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,x):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,x)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function M(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function G(t){if(t||""===t){var r=t[s];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(a.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(n(t)+" is not iterable")}return b.prototype=w,u(j,"constructor",{value:w,configurable:!0}),u(w,"constructor",{value:b,configurable:!0}),b.displayName=p(w,l,"GeneratorFunction"),r.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,p(t,l,"GeneratorFunction")),t.prototype=Object.create(j),t},r.awrap=function(t){return{__await:t}},O(k.prototype),p(k.prototype,f,(function(){return this})),r.AsyncIterator=k,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new k(h(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},O(j),p(j,l,"Generator"),p(j,s,(function(){return this})),p(j,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=G,N.prototype={constructor:N,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(M),!t)for(var r in this)"t"===r.charAt(0)&&a.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(n,o){return u.type="throw",u.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=a.call(i,"catchLoc"),s=a.call(i,"finallyLoc");if(c&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&a.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,x):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),x},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),M(r),x}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;M(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:G(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),x}},r}t.exports=o,t.exports.__esModule=!0,t.exports.default=t.exports},388:function(t,e,r){var n=r(705).default;t.exports=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)},t.exports.__esModule=!0,t.exports.default=t.exports},355:function(t,e,r){var n=r(705).default,o=r(388);t.exports=function(t){var e=o(t,"string");return"symbol"==n(e)?e:String(e)},t.exports.__esModule=!0,t.exports.default=t.exports},705:function(t){function e(r){return t.exports=e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,{a:e}),e},r.d=function(t,e){for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return function(){"use strict";r.r(n),r.d(n,{SmartAds:function(){return p}});var t=r(958),e=r.n(t),o=r(935),i=r.n(o),a=r(76),u=r.n(a),c=r(81),s=r.n(c),f=r(951),l=r.n(f),p=function(){function t(e){if(u()(this,t),l()(this,"accessToken",void 0),!e.accessToken)throw new Error("accessToken is required");this.accessToken=e.accessToken}var r;return s()(t,[{key:"report",value:(r=i()(e()().mark((function t(r){var n,o,i,a,u,c;return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=r.smartId,o=r.eventName,i=r.callback,n){t.next=3;break}throw new Error("smartId is required");case 3:if(o){t.next=5;break}throw new Error("eventName is required");case 5:return a={access_token:this.accessToken,smartId:n,event_name:o},t.next=8,fetch("https://agent.ads-server-k.com/smartads/api/v1/postback/smart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});case 8:return u=t.sent,t.next=11,u.json();case 11:return c=t.sent,null==i||i(c),t.abrupt("return",c);case 14:case"end":return t.stop()}}),t,this)}))),function(t){return r.apply(this,arguments)})}]),t}();n.default=p}(),n}()}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbeakads/smartads-sdk-js",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "BigBeak Smart Ads SDK for JavaScript",
5
5
  "module": "dist/esm/index.js",
6
6
  "main": "dist/umd/smartads-sdk-js.min.js",