@pixwel/pixwel-sdk 2.1.4 → 2.1.6

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.
Files changed (40) hide show
  1. package/.babelrc +2 -2
  2. package/coverage/clover.xml +4 -4
  3. package/coverage/coverage-final.json +2 -2
  4. package/coverage/lcov-report/Ass.js.html +1 -1
  5. package/coverage/lcov-report/Asset.js.html +1 -1
  6. package/coverage/lcov-report/AssetType.js.html +1 -1
  7. package/coverage/lcov-report/Encode.js.html +1 -1
  8. package/coverage/lcov-report/File.js.html +1 -1
  9. package/coverage/lcov-report/Filename.js.html +1 -1
  10. package/coverage/lcov-report/Ingest.js.html +2 -2
  11. package/coverage/lcov-report/IngestFile.js.html +1 -1
  12. package/coverage/lcov-report/Model.js.html +3 -3
  13. package/coverage/lcov-report/Order.js.html +1 -1
  14. package/coverage/lcov-report/Srt.js.html +1 -1
  15. package/coverage/lcov-report/Sub.js.html +1 -1
  16. package/coverage/lcov-report/Tag.js.html +1 -1
  17. package/coverage/lcov-report/TimeFormat.js.html +1 -1
  18. package/coverage/lcov-report/fileType.js.html +1 -1
  19. package/coverage/lcov-report/index.html +1 -1
  20. package/coverage/lcov.info +4 -4
  21. package/dist/Ass.js +206 -0
  22. package/dist/Asset.js +49 -0
  23. package/dist/AssetType.js +45 -0
  24. package/dist/Encode.js +45 -0
  25. package/dist/File.js +45 -0
  26. package/dist/Filename.js +23 -0
  27. package/dist/Ingest.js +734 -0
  28. package/dist/IngestFile.js +18 -0
  29. package/dist/Model.js +580 -0
  30. package/dist/Order.js +70 -0
  31. package/dist/Srt.js +97 -0
  32. package/dist/Sub.js +46 -0
  33. package/dist/Tag.js +45 -0
  34. package/dist/TimeFormat.js +53 -0
  35. package/dist/fileType.js +39 -0
  36. package/dist/index.js +77 -85
  37. package/dist/src/Ingest.js +1 -1
  38. package/package.json +7 -8
  39. package/src/Ingest.js +1 -1
  40. package/test/Ingest.spec.js +10 -7
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var IngestFile = function IngestFile(file, order) {
13
+ (0, _classCallCheck2["default"])(this, IngestFile);
14
+ this.file = file;
15
+ } // renderedName, ingest, options
16
+ ;
17
+
18
+ exports["default"] = IngestFile;
package/dist/Model.js ADDED
@@ -0,0 +1,580 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
+
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports["default"] = void 0;
11
+
12
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
+
14
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
+
16
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
17
+
18
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
19
+
20
+ var _lodash = _interopRequireWildcard(require("lodash"));
21
+
22
+ var _index = require("../index");
23
+
24
+ var _axios = _interopRequireDefault(require("axios"));
25
+
26
+ var _deepObjectDiff = require("deep-object-diff");
27
+
28
+ var _validate = _interopRequireDefault(require("validate.js"));
29
+
30
+ /**
31
+ * Model base class for reading and writing to an API
32
+ *
33
+ * - persistence
34
+ * - validation
35
+ * - schema / seal
36
+ * - API error response handling
37
+ * - API success response hanlding
38
+ * - throws Exceptions
39
+ *
40
+ */
41
+ var _bindings = {
42
+ find: [],
43
+ save: []
44
+ };
45
+ /**
46
+ * This exists outside the class, solely because I have not
47
+ * figured out how to reference a static class method from an instance
48
+ * and also from a static function.
49
+ */
50
+
51
+ function connection() {
52
+ return _axios["default"].create({
53
+ baseURL: _index.Pixwel.endpoint,
54
+ headers: {
55
+ Authorization: "Basic ".concat(_index.Pixwel.credentials.token),
56
+ Accept: "application/json",
57
+ "Content-Type": "application/json"
58
+ }
59
+ });
60
+ }
61
+
62
+ var Model =
63
+ /*#__PURE__*/
64
+ function () {
65
+ function Model(data) {
66
+ (0, _classCallCheck2["default"])(this, Model);
67
+ Object.assign(this, data);
68
+ this._endpoint = _index.Pixwel.endpoint;
69
+ this._api = connection();
70
+ this._lastState = {};
71
+ this._validationErrors = [];
72
+ this._constraints = {};
73
+ }
74
+ /**
75
+ * Adds a validation contraint
76
+ *
77
+ * @param {string} name
78
+ * @param {object} data
79
+ */
80
+
81
+
82
+ (0, _createClass2["default"])(Model, [{
83
+ key: "addConstraint",
84
+ value: function addConstraint(name, data) {
85
+ this._constraints[name] = data;
86
+ }
87
+ /**
88
+ * Validates models data against its contraints
89
+ */
90
+
91
+ }, {
92
+ key: "validates",
93
+ value: function validates() {
94
+ var res = (0, _validate["default"])(this.data(), this._constraints);
95
+
96
+ if (res == undefined) {
97
+ this._validationErrors = [];
98
+ } else {
99
+ this._validationErrors = res;
100
+ }
101
+
102
+ return res == undefined ? true : false;
103
+ }
104
+ }, {
105
+ key: "errors",
106
+ value: function errors() {
107
+ return this._validationErrors;
108
+ }
109
+ /**
110
+ * Makes a request to the API
111
+ *
112
+ * @param {object} config
113
+ */
114
+
115
+ }, {
116
+ key: "request",
117
+ value: function () {
118
+ var _request = (0, _asyncToGenerator2["default"])(
119
+ /*#__PURE__*/
120
+ _regenerator["default"].mark(function _callee(config) {
121
+ return _regenerator["default"].wrap(function _callee$(_context) {
122
+ while (1) {
123
+ switch (_context.prev = _context.next) {
124
+ case 0:
125
+ return _context.abrupt("return", this._api.request(config));
126
+
127
+ case 1:
128
+ case "end":
129
+ return _context.stop();
130
+ }
131
+ }
132
+ }, _callee, this);
133
+ }));
134
+
135
+ function request(_x) {
136
+ return _request.apply(this, arguments);
137
+ }
138
+
139
+ return request;
140
+ }()
141
+ /**
142
+ * Returns data
143
+ */
144
+
145
+ }, {
146
+ key: "data",
147
+ value: function data() {
148
+ var _this = this;
149
+
150
+ var keys = Object.keys(this).filter(function (key) {
151
+ // using underscore convention to not include private data
152
+ return key[0] != '_';
153
+ }); // deliberately adding _id back in even though it's "private"
154
+
155
+ keys.push('_id');
156
+ var data = {};
157
+ keys.forEach(function (key) {
158
+ data[key] = _this[key];
159
+ });
160
+ return data;
161
+ }
162
+ /**
163
+ * Register a callback to a model method
164
+ *
165
+ * @param {string} method
166
+ * @param {function} callback
167
+ */
168
+
169
+ }, {
170
+ key: "save",
171
+
172
+ /**
173
+ * Creates or updates a resource depennding on the presence
174
+ * of _id
175
+ *
176
+ * @param {object} data
177
+ */
178
+ value: function () {
179
+ var _save = (0, _asyncToGenerator2["default"])(
180
+ /*#__PURE__*/
181
+ _regenerator["default"].mark(function _callee2() {
182
+ var _this2 = this;
183
+
184
+ var data,
185
+ input,
186
+ inputDiff,
187
+ _args2 = arguments;
188
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
189
+ while (1) {
190
+ switch (_context2.prev = _context2.next) {
191
+ case 0:
192
+ data = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
193
+ input = data.length ? data : this.data();
194
+
195
+ if (!input._id) {
196
+ _context2.next = 9;
197
+ break;
198
+ }
199
+
200
+ inputDiff = (0, _deepObjectDiff.diff)(this._lastState, input);
201
+ _context2.next = 6;
202
+ return this.update(input._id, inputDiff);
203
+
204
+ case 6:
205
+ this._lastState = _context2.sent;
206
+ _context2.next = 12;
207
+ break;
208
+
209
+ case 9:
210
+ _context2.next = 11;
211
+ return this.create(input);
212
+
213
+ case 11:
214
+ this._lastState = _context2.sent;
215
+
216
+ case 12:
217
+ // fires events with the result
218
+ _bindings.save.forEach(function (callback) {
219
+ callback(_this2._lastState);
220
+ });
221
+
222
+ return _context2.abrupt("return", this._lastState);
223
+
224
+ case 14:
225
+ case "end":
226
+ return _context2.stop();
227
+ }
228
+ }
229
+ }, _callee2, this);
230
+ }));
231
+
232
+ function save() {
233
+ return _save.apply(this, arguments);
234
+ }
235
+
236
+ return save;
237
+ }()
238
+ /**
239
+ * Merges incoming data into the model data
240
+ *
241
+ * @param {object} data
242
+ */
243
+
244
+ }, {
245
+ key: "set",
246
+ value: function set(data) {
247
+ return _lodash["default"].merge(this, data);
248
+ }
249
+ /**
250
+ * Returns a deep clone of the current object
251
+ */
252
+
253
+ }, {
254
+ key: "clone",
255
+ value: function clone() {
256
+ return (0, _lodash.cloneDeep)(this);
257
+ }
258
+ /**
259
+ * Fetches all objects in a collection given params
260
+ *
261
+ * @param {object} params
262
+ */
263
+
264
+ }, {
265
+ key: "create",
266
+
267
+ /**
268
+ * Creates a resource
269
+ *
270
+ * @param {string} name
271
+ * @param {object} data
272
+ */
273
+ value: function () {
274
+ var _create = (0, _asyncToGenerator2["default"])(
275
+ /*#__PURE__*/
276
+ _regenerator["default"].mark(function _callee3(data) {
277
+ var url, res;
278
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
279
+ while (1) {
280
+ switch (_context3.prev = _context3.next) {
281
+ case 0:
282
+ url = "".concat(this._endpoint, "/").concat(this._resource);
283
+ _context3.next = 3;
284
+ return this._api.post(url, data, {
285
+ validateStatus: function validateStatus(status) {
286
+ return true;
287
+ }
288
+ });
289
+
290
+ case 3:
291
+ res = _context3.sent;
292
+ _context3.t0 = res.status;
293
+ _context3.next = _context3.t0 === 500 ? 7 : 8;
294
+ break;
295
+
296
+ case 7:
297
+ throw new Error("HTTP 500: POST ".concat(url, ": ").concat(res.data.type, " - ").concat(res.data.message));
298
+
299
+ case 8:
300
+ Object.assign(this, res.data);
301
+ return _context3.abrupt("return", res.data);
302
+
303
+ case 10:
304
+ case "end":
305
+ return _context3.stop();
306
+ }
307
+ }
308
+ }, _callee3, this);
309
+ }));
310
+
311
+ function create(_x2) {
312
+ return _create.apply(this, arguments);
313
+ }
314
+
315
+ return create;
316
+ }()
317
+ /**
318
+ * Updates a resource
319
+ *
320
+ * @param {string} name
321
+ * @param {object} data
322
+ */
323
+
324
+ }, {
325
+ key: "update",
326
+ value: function () {
327
+ var _update = (0, _asyncToGenerator2["default"])(
328
+ /*#__PURE__*/
329
+ _regenerator["default"].mark(function _callee4() {
330
+ var id,
331
+ data,
332
+ currentId,
333
+ url,
334
+ res,
335
+ _args4 = arguments;
336
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
337
+ while (1) {
338
+ switch (_context4.prev = _context4.next) {
339
+ case 0:
340
+ id = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : '';
341
+ data = _args4.length > 1 ? _args4[1] : undefined;
342
+ currentId = id || this._id;
343
+
344
+ if (currentId) {
345
+ _context4.next = 5;
346
+ break;
347
+ }
348
+
349
+ throw new Error("unable to update record without an _id");
350
+
351
+ case 5:
352
+ url = "".concat(this._endpoint, "/").concat(this._resource, "/").concat(currentId);
353
+ _context4.next = 8;
354
+ return this._api.patch(url, data, {
355
+ validateStatus: function validateStatus(status) {
356
+ return true;
357
+ }
358
+ });
359
+
360
+ case 8:
361
+ res = _context4.sent;
362
+ _context4.t0 = res.status;
363
+ _context4.next = _context4.t0 === 500 ? 12 : _context4.t0 === 400 ? 13 : 14;
364
+ break;
365
+
366
+ case 12:
367
+ throw new Error("HTTP 500: PATCH ".concat(url, ": ").concat(res.data.type, " - ").concat(res.data.message));
368
+
369
+ case 13:
370
+ throw new Error("HTTP 400: PATCH ".concat(url, ": ").concat(res.data.info.message, " - ").concat(JSON.stringify(data)));
371
+
372
+ case 14:
373
+ Object.assign(this, res.data);
374
+ return _context4.abrupt("return", res.data);
375
+
376
+ case 16:
377
+ case "end":
378
+ return _context4.stop();
379
+ }
380
+ }
381
+ }, _callee4, this);
382
+ }));
383
+
384
+ function update() {
385
+ return _update.apply(this, arguments);
386
+ }
387
+
388
+ return update;
389
+ }()
390
+ /**
391
+ * Reads a resource
392
+ *
393
+ * @param {string} name
394
+ * @param {object} opts
395
+ */
396
+
397
+ }, {
398
+ key: "read",
399
+ value: function () {
400
+ var _read = (0, _asyncToGenerator2["default"])(
401
+ /*#__PURE__*/
402
+ _regenerator["default"].mark(function _callee5() {
403
+ var id,
404
+ opts,
405
+ currentId,
406
+ url,
407
+ _args5 = arguments;
408
+ return _regenerator["default"].wrap(function _callee5$(_context5) {
409
+ while (1) {
410
+ switch (_context5.prev = _context5.next) {
411
+ case 0:
412
+ id = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : '';
413
+ opts = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
414
+ currentId = id || this._id;
415
+
416
+ if (currentId) {
417
+ _context5.next = 5;
418
+ break;
419
+ }
420
+
421
+ throw new Error("unable to read record without an _id");
422
+
423
+ case 5:
424
+ url = "".concat(this._endpoint, "/").concat(this._resource, "/").concat(currentId);
425
+ return _context5.abrupt("return", this._api.get(url, opts).then(function (res) {
426
+ return res.data;
427
+ }));
428
+
429
+ case 7:
430
+ case "end":
431
+ return _context5.stop();
432
+ }
433
+ }
434
+ }, _callee5, this);
435
+ }));
436
+
437
+ function read() {
438
+ return _read.apply(this, arguments);
439
+ }
440
+
441
+ return read;
442
+ }()
443
+ /**
444
+ * Deletes a resource
445
+ *
446
+ * @param {string} name
447
+ * @param {string} id
448
+ */
449
+
450
+ }, {
451
+ key: "delete",
452
+ value: function () {
453
+ var _delete2 = (0, _asyncToGenerator2["default"])(
454
+ /*#__PURE__*/
455
+ _regenerator["default"].mark(function _callee6() {
456
+ var id,
457
+ currentId,
458
+ url,
459
+ _args6 = arguments;
460
+ return _regenerator["default"].wrap(function _callee6$(_context6) {
461
+ while (1) {
462
+ switch (_context6.prev = _context6.next) {
463
+ case 0:
464
+ id = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : '';
465
+ currentId = id || this._id;
466
+
467
+ if (currentId) {
468
+ _context6.next = 4;
469
+ break;
470
+ }
471
+
472
+ throw new Error("unable to delete record without an _id");
473
+
474
+ case 4:
475
+ url = "".concat(this._endpoint, "/").concat(this._resource, "/").concat(id);
476
+ return _context6.abrupt("return", this._api["delete"](url).then(function (res) {
477
+ return res.data;
478
+ }));
479
+
480
+ case 6:
481
+ case "end":
482
+ return _context6.stop();
483
+ }
484
+ }
485
+ }, _callee6, this);
486
+ }));
487
+
488
+ function _delete() {
489
+ return _delete2.apply(this, arguments);
490
+ }
491
+
492
+ return _delete;
493
+ }()
494
+ }], [{
495
+ key: "registerCallback",
496
+ value: function registerCallback(method, callback) {
497
+ _bindings[method].push(callback);
498
+ }
499
+ }, {
500
+ key: "all",
501
+ value: function all() {
502
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
503
+ return this.find(params);
504
+ }
505
+ /**
506
+ * Finds an object or collection of objects
507
+ *
508
+ * @param {object} params
509
+ */
510
+
511
+ }, {
512
+ key: "find",
513
+ value: function () {
514
+ var _find = (0, _asyncToGenerator2["default"])(
515
+ /*#__PURE__*/
516
+ _regenerator["default"].mark(function _callee7() {
517
+ var params,
518
+ api,
519
+ url,
520
+ id,
521
+ res,
522
+ _args7 = arguments;
523
+ return _regenerator["default"].wrap(function _callee7$(_context7) {
524
+ while (1) {
525
+ switch (_context7.prev = _context7.next) {
526
+ case 0:
527
+ params = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
528
+ api = connection();
529
+
530
+ if (typeof params === 'string') {
531
+ id = params;
532
+ url = "".concat(this._resource, "/").concat(id);
533
+ params = {};
534
+ } else {
535
+ url = this._resource;
536
+ }
537
+
538
+ _context7.prev = 3;
539
+ _context7.next = 6;
540
+ return api.get(url, {
541
+ params: params
542
+ });
543
+
544
+ case 6:
545
+ res = _context7.sent;
546
+ _context7.next = 12;
547
+ break;
548
+
549
+ case 9:
550
+ _context7.prev = 9;
551
+ _context7.t0 = _context7["catch"](3);
552
+ throw new Error("".concat(_context7.t0.message, ": GET /").concat(url, " ").concat(JSON.stringify(params)));
553
+
554
+ case 12:
555
+ // fires events with the result
556
+ _bindings.find.forEach(function (callback) {
557
+ callback(res.data);
558
+ });
559
+
560
+ return _context7.abrupt("return", res.data);
561
+
562
+ case 14:
563
+ case "end":
564
+ return _context7.stop();
565
+ }
566
+ }
567
+ }, _callee7, this, [[3, 9]]);
568
+ }));
569
+
570
+ function find() {
571
+ return _find.apply(this, arguments);
572
+ }
573
+
574
+ return find;
575
+ }()
576
+ }]);
577
+ return Model;
578
+ }();
579
+
580
+ exports["default"] = Model;
package/dist/Order.js ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
14
+ var _lodash = _interopRequireDefault(require("lodash"));
15
+
16
+ var _Filename = _interopRequireDefault(require("./Filename.js"));
17
+
18
+ var Order =
19
+ /*#__PURE__*/
20
+ function () {
21
+ function Order(data) {
22
+ (0, _classCallCheck2["default"])(this, Order);
23
+ var schema = {
24
+ _id: null,
25
+ asset: null,
26
+ project: null,
27
+ assetType: null,
28
+ country: null,
29
+ language: null,
30
+ dng: null
31
+ };
32
+ Object.assign(this, schema, data);
33
+ }
34
+ /**
35
+ * Determines if an order should be classified as 'dubbed' based on its dng values
36
+ */
37
+
38
+
39
+ (0, _createClass2["default"])(Order, [{
40
+ key: "isDub",
41
+ value: function isDub() {
42
+ if (!this.dng) {
43
+ return null;
44
+ }
45
+
46
+ if (this.dng.graphics && this.dng.graphics.includes('Dedicated / Localized')) {
47
+ return false;
48
+ }
49
+
50
+ return _lodash["default"].flattenDeep(Object.entries(this.dng)).includes("Dedicated / Localized");
51
+ }
52
+ /**
53
+ * Determines in an order should be classified as 'subbed' based on its dng values
54
+ */
55
+
56
+ }, {
57
+ key: "isSub",
58
+ value: function isSub() {
59
+ if (!this.dng) {
60
+ return null;
61
+ }
62
+
63
+ if (this.dng === 'Graphics Only') return false;
64
+ return _lodash["default"].flattenDeep(Object.entries(this.dng)).includes("Subtitled");
65
+ }
66
+ }]);
67
+ return Order;
68
+ }();
69
+
70
+ exports["default"] = Order;