@super-protocol/sdk-js 0.7.1-beta.1 → 0.7.1-beta.2

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.
@@ -34,6 +34,15 @@ declare class OrdersFactory {
34
34
  */
35
35
  static createOrder(orderInfo: OrderInfo, holdDeposit?: string, suspended?: boolean, externalId?: string, transactionOptions?: TransactionOptions): Promise<void>;
36
36
  static getOrder(consumer: string, externalId: string): Promise<OrderCreatedEvent>;
37
+ /**
38
+ * Function for create workflow
39
+ * @param parentOrderInfo - order info for new order
40
+ * @param subOrdersInfo - array of sub orders infos
41
+ * @param externalId - external id
42
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
43
+ * @returns {Promise<void>} - Does not return id of created order!
44
+ */
45
+ static createWorkflow(perentOrderInfo: OrderInfo, subOrdersInfo: OrderInfo[], externalId?: string, transactionOptions?: TransactionOptions): Promise<void>;
37
46
  /**
38
47
  * Function for refilling order deposit
39
48
  * @param orderId - order id
@@ -41,6 +50,12 @@ declare class OrdersFactory {
41
50
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
42
51
  */
43
52
  static refillOrderDeposit(orderId: string, amount: string, transactionOptions?: TransactionOptions): Promise<void>;
53
+ /**
54
+ * Function for adding event listeners on order created event in orders factory contract
55
+ * @param callback - function for processing created order
56
+ * @returns unsubscribe - unsubscribe function from event
57
+ */
58
+ static onWorkflowCreated(callback: onWorkflowCreatedCallback): () => void;
44
59
  /**
45
60
  * Function for adding event listeners on order created event in orders factory contract
46
61
  * @param callback - function for processing created order
@@ -134,4 +149,5 @@ export declare type onOrderProfitWithdrawnCallback = (orderId: string, tokenRece
134
149
  export declare type onOrderDepositSpentChangedCallback = (orderId: string, consumer: string, spent: string) => void;
135
150
  export declare type onOrderAwaitingPaymentChangedCallback = (orderId: string, consumer: string, awaitingPaymentFlag: boolean) => void;
136
151
  export declare type onOrderEncryptedResultUpdatedCallback = (orderId: string, consumer: string, encryptedResult: string) => void;
152
+ export declare type onWorkflowCreatedCallback = (consumer: string, externalId: string, offerId: string, orderId: string) => void;
137
153
  export default OrdersFactory;
@@ -187,6 +187,34 @@ var OrdersFactory = /** @class */ (function () {
187
187
  });
188
188
  });
189
189
  };
190
+ /**
191
+ * Function for create workflow
192
+ * @param parentOrderInfo - order info for new order
193
+ * @param subOrdersInfo - array of sub orders infos
194
+ * @param externalId - external id
195
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
196
+ * @returns {Promise<void>} - Does not return id of created order!
197
+ */
198
+ OrdersFactory.createWorkflow = function (perentOrderInfo, subOrdersInfo, externalId, transactionOptions) {
199
+ if (externalId === void 0) { externalId = "default"; }
200
+ return __awaiter(this, void 0, void 0, function () {
201
+ var contract, perentOrderInfoArgs, formattedExternalId, subOrdersInfoArgs;
202
+ return __generator(this, function (_a) {
203
+ switch (_a.label) {
204
+ case 0:
205
+ contract = this.checkInit(transactionOptions);
206
+ (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
207
+ perentOrderInfoArgs = (0, utils_1.objectToTuple)(perentOrderInfo, Order_1.OrderInfoStructure);
208
+ formattedExternalId = (0, utils_2.formatBytes32String)(externalId);
209
+ subOrdersInfoArgs = (0, utils_1.objectToTuple)(subOrdersInfo, Order_1.OrderInfoStructureArray);
210
+ return [4 /*yield*/, TxManager_1.default.execute(contract.methods.createWorkflow, [perentOrderInfoArgs, formattedExternalId, subOrdersInfoArgs], transactionOptions)];
211
+ case 1:
212
+ _a.sent();
213
+ return [2 /*return*/];
214
+ }
215
+ });
216
+ });
217
+ };
190
218
  /**
191
219
  * Function for refilling order deposit
192
220
  * @param orderId - order id
@@ -209,6 +237,31 @@ var OrdersFactory = /** @class */ (function () {
209
237
  });
210
238
  });
211
239
  };
240
+ /**
241
+ * Function for adding event listeners on order created event in orders factory contract
242
+ * @param callback - function for processing created order
243
+ * @returns unsubscribe - unsubscribe function from event
244
+ */
245
+ OrdersFactory.onWorkflowCreated = function (callback) {
246
+ var _this = this;
247
+ this.checkInit();
248
+ var logger = this.logger.child({ method: "onWorkflowCreated" });
249
+ var subscription = this.contract.events
250
+ .WorkflowCreated()
251
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
252
+ return __generator(this, function (_a) {
253
+ //consumer: string, externalId: string, offerId: string, orderId: string
254
+ callback(event.returnValues.consumer, (0, utils_2.parseBytes32String)(event.returnValues.externalId), event.returnValues.offerId, event.returnValues.orderId);
255
+ return [2 /*return*/];
256
+ });
257
+ }); })
258
+ .on("error", function (error, receipt) {
259
+ if (receipt)
260
+ return; // Used to avoid logging of transaction rejected
261
+ logger.warn(error);
262
+ });
263
+ return function () { return subscription.unsubscribe(); };
264
+ };
212
265
  /**
213
266
  * Function for adding event listeners on order created event in orders factory contract
214
267
  * @param callback - function for processing created order
@@ -16,3 +16,9 @@ export declare type SubOrderCreatedEvent = {
16
16
  subOrderId: string;
17
17
  parentOrderId: string;
18
18
  };
19
+ export declare type WorkflowCreatedEvent = {
20
+ consumer: string;
21
+ externalId: string;
22
+ offerId: string;
23
+ orderId: string;
24
+ };
@@ -44,6 +44,7 @@ export declare type ExtendedOrderInfo = OrderInfo & {
44
44
  externalId: string;
45
45
  holdSum: string;
46
46
  };
47
+ export declare const OrderInfoStructureArray: never[];
47
48
  export declare const OrderResultStructure: {
48
49
  encryptedResult: StringConstructor;
49
50
  encryptedError: StringConstructor;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OrderResultStructure = exports.OrderInfoStructure = exports.OrderArgsStructure = exports.OrderStatus = void 0;
3
+ exports.OrderResultStructure = exports.OrderInfoStructureArray = exports.OrderInfoStructure = exports.OrderArgsStructure = exports.OrderStatus = void 0;
4
4
  var OrderStatus;
5
5
  (function (OrderStatus) {
6
6
  OrderStatus["New"] = "0";
@@ -28,6 +28,8 @@ exports.OrderInfoStructure = {
28
28
  status: OrderStatus,
29
29
  args: exports.OrderArgsStructure,
30
30
  };
31
+ // Array of order info structures
32
+ exports.OrderInfoStructureArray = [];
31
33
  // Order of keys and type conversion functions for this object in blockchain contract
32
34
  exports.OrderResultStructure = {
33
35
  encryptedResult: String,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-protocol/sdk-js",
3
- "version": "0.7.1-beta.1",
3
+ "version": "0.7.1-beta.2",
4
4
  "main": "build/index.js",
5
5
  "license": "MIT",
6
6
  "files": [