@bytexbyte/ike-app-api 1.0.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.
Files changed (42) hide show
  1. package/README.md +17 -0
  2. package/lib/App.d.ts +23 -0
  3. package/lib/App.js +126 -0
  4. package/lib/Auth/index.d.ts +156 -0
  5. package/lib/Auth/index.js +392 -0
  6. package/lib/Auth/type.d.ts +73 -0
  7. package/lib/Auth/type.js +2 -0
  8. package/lib/Batch/index.d.ts +26 -0
  9. package/lib/Batch/index.js +136 -0
  10. package/lib/Contract/index.d.ts +26 -0
  11. package/lib/Contract/index.js +109 -0
  12. package/lib/DigitalCustomization/index.d.ts +34 -0
  13. package/lib/DigitalCustomization/index.js +128 -0
  14. package/lib/DigitalCustomization/shopifyType.d.ts +72 -0
  15. package/lib/DigitalCustomization/shopifyType.js +2 -0
  16. package/lib/File/UploadFileType.d.ts +5 -0
  17. package/lib/File/UploadFileType.js +16 -0
  18. package/lib/File/index.d.ts +34 -0
  19. package/lib/File/index.js +131 -0
  20. package/lib/InAppNotification/index.d.ts +23 -0
  21. package/lib/InAppNotification/index.js +89 -0
  22. package/lib/InAppNotification/type.d.ts +1 -0
  23. package/lib/InAppNotification/type.js +2 -0
  24. package/lib/Mfa/index.d.ts +47 -0
  25. package/lib/Mfa/index.js +139 -0
  26. package/lib/Redeem/index.d.ts +23 -0
  27. package/lib/Redeem/index.js +90 -0
  28. package/lib/RegisterDeviceCode/index.d.ts +18 -0
  29. package/lib/RegisterDeviceCode/index.js +88 -0
  30. package/lib/Scan/index.d.ts +39 -0
  31. package/lib/Scan/index.js +121 -0
  32. package/lib/Tags/index.d.ts +75 -0
  33. package/lib/Tags/index.js +264 -0
  34. package/lib/User/index.d.ts +140 -0
  35. package/lib/User/index.js +478 -0
  36. package/lib/config.d.ts +3 -0
  37. package/lib/config.js +8 -0
  38. package/lib/index.d.ts +42 -0
  39. package/lib/index.js +98 -0
  40. package/lib/types.d.ts +587 -0
  41. package/lib/types.js +64 -0
  42. package/package.json +79 -0
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ /* eslint-disable no-undef */
3
+ var __extends = (this && this.__extends) || (function () {
4
+ var extendStatics = function (d, b) {
5
+ extendStatics = Object.setPrototypeOf ||
6
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
+ return extendStatics(d, b);
9
+ };
10
+ return function (d, b) {
11
+ if (typeof b !== "function" && b !== null)
12
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
+ extendStatics(d, b);
14
+ function __() { this.constructor = d; }
15
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
+ };
17
+ })();
18
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
19
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
20
+ return new (P || (P = Promise))(function (resolve, reject) {
21
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
22
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
23
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
24
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
25
+ });
26
+ };
27
+ var __generator = (this && this.__generator) || function (thisArg, body) {
28
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
29
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
30
+ function verb(n) { return function (v) { return step([n, v]); }; }
31
+ function step(op) {
32
+ if (f) throw new TypeError("Generator is already executing.");
33
+ while (_) try {
34
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
35
+ if (y = 0, t) op = [op[0] & 2, t.value];
36
+ switch (op[0]) {
37
+ case 0: case 1: t = op; break;
38
+ case 4: _.label++; return { value: op[1], done: false };
39
+ case 5: _.label++; y = op[1]; op = [0]; continue;
40
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
41
+ default:
42
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
43
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
44
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
45
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
46
+ if (t[2]) _.ops.pop();
47
+ _.trys.pop(); continue;
48
+ }
49
+ op = body.call(thisArg, _);
50
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
51
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
52
+ }
53
+ };
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ var bxb_api_1 = require("@bytexbyte/bxb-api");
56
+ var config_1 = require("../config");
57
+ var IKEAppContractApi = /** @class */ (function (_super) {
58
+ __extends(IKEAppContractApi, _super);
59
+ function IKEAppContractApi(_a) {
60
+ var host = _a.host, onSuccess = _a.onSuccess, onError = _a.onError;
61
+ return _super.call(this, {
62
+ host: host,
63
+ secretKey: config_1.localSecretKey,
64
+ secret: '',
65
+ moduleName: 'contract',
66
+ onSuccess: onSuccess,
67
+ onError: onError
68
+ }) || this;
69
+ }
70
+ IKEAppContractApi.prototype.getAddresses = function () {
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ var response;
73
+ return __generator(this, function (_a) {
74
+ switch (_a.label) {
75
+ case 0: return [4 /*yield*/, this.bxbFetch({
76
+ method: 'Get',
77
+ headers: {
78
+ 'Content-Type': 'application/json',
79
+ },
80
+ })];
81
+ case 1:
82
+ response = _a.sent();
83
+ return [2 /*return*/, response.json()];
84
+ }
85
+ });
86
+ });
87
+ };
88
+ IKEAppContractApi.prototype.getNftImage = function (form) {
89
+ return __awaiter(this, void 0, void 0, function () {
90
+ var response;
91
+ return __generator(this, function (_a) {
92
+ switch (_a.label) {
93
+ case 0: return [4 /*yield*/, this.bxbFetch({
94
+ method: 'POST',
95
+ headers: {
96
+ 'Content-Type': 'application/json',
97
+ },
98
+ body: JSON.stringify(form)
99
+ }, 'nft')];
100
+ case 1:
101
+ response = _a.sent();
102
+ return [2 /*return*/, response.json()];
103
+ }
104
+ });
105
+ });
106
+ };
107
+ return IKEAppContractApi;
108
+ }(bxb_api_1.default));
109
+ exports.default = IKEAppContractApi;
@@ -0,0 +1,34 @@
1
+ import BxBApi from '@bytexbyte/bxb-api';
2
+ import { ShopifyProductType } from './shopifyType';
3
+ declare type GetShopifyResult = {
4
+ shopifyStore: {
5
+ name: string;
6
+ };
7
+ shopifyProducts: ShopifyProductType[];
8
+ } | null;
9
+ declare type CreateDraftOrderResult = {
10
+ invoice_url?: string;
11
+ error?: 'Digital customization id is missing.' | 'Store access token not found.' | 'Draft order id not found.' | 'Unkown error.';
12
+ };
13
+ declare type PayReferralPointResult = {
14
+ success: boolean;
15
+ error?: 'pay point failed.' | 'Missing digitalCustomizationId.';
16
+ };
17
+ declare class IKEAppDigitalCustomizationApi extends BxBApi {
18
+ constructor({ host, onSuccess, onError }: {
19
+ host: string;
20
+ onSuccess?: () => void;
21
+ onError?: (error: any) => void;
22
+ });
23
+ getShopifyProducts(digitalCustomizationId: number): Promise<GetShopifyResult>;
24
+ createDraftOrder(form: {
25
+ digitalCustomizationId: number;
26
+ userId: string;
27
+ variantId: number;
28
+ }): Promise<CreateDraftOrderResult>;
29
+ payReferralPoint(form: {
30
+ digitalCustomizationId: number;
31
+ userId: string;
32
+ }): Promise<PayReferralPointResult>;
33
+ }
34
+ export default IKEAppDigitalCustomizationApi;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ /* eslint-disable no-undef */
55
+ var bxb_api_1 = require("@bytexbyte/bxb-api");
56
+ var config_1 = require("../config");
57
+ var IKEAppDigitalCustomizationApi = /** @class */ (function (_super) {
58
+ __extends(IKEAppDigitalCustomizationApi, _super);
59
+ function IKEAppDigitalCustomizationApi(_a) {
60
+ var host = _a.host, onSuccess = _a.onSuccess, onError = _a.onError;
61
+ return _super.call(this, {
62
+ host: host,
63
+ secretKey: config_1.localSecretKey,
64
+ secret: '',
65
+ moduleName: 'digitalCustomizations',
66
+ onSuccess: onSuccess,
67
+ onError: onError
68
+ }) || this;
69
+ }
70
+ IKEAppDigitalCustomizationApi.prototype.getShopifyProducts = function (digitalCustomizationId) {
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ var response;
73
+ return __generator(this, function (_a) {
74
+ switch (_a.label) {
75
+ case 0: return [4 /*yield*/, this.bxbFetch({
76
+ method: 'GET',
77
+ headers: {
78
+ 'Content-Type': 'application/json'
79
+ },
80
+ }, "".concat(digitalCustomizationId, "/shopify-product"))];
81
+ case 1:
82
+ response = _a.sent();
83
+ return [2 /*return*/, response.json()];
84
+ }
85
+ });
86
+ });
87
+ };
88
+ IKEAppDigitalCustomizationApi.prototype.createDraftOrder = function (form) {
89
+ return __awaiter(this, void 0, void 0, function () {
90
+ var response;
91
+ return __generator(this, function (_a) {
92
+ switch (_a.label) {
93
+ case 0: return [4 /*yield*/, this.bxbFetch({
94
+ method: 'POST',
95
+ headers: {
96
+ 'Content-Type': 'application/json'
97
+ },
98
+ body: JSON.stringify(form)
99
+ }, "".concat(form.digitalCustomizationId, "/shopify-order"))];
100
+ case 1:
101
+ response = _a.sent();
102
+ return [2 /*return*/, response.json()];
103
+ }
104
+ });
105
+ });
106
+ };
107
+ IKEAppDigitalCustomizationApi.prototype.payReferralPoint = function (form) {
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ var response;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0: return [4 /*yield*/, this.bxbFetch({
113
+ method: 'POST',
114
+ headers: {
115
+ 'Content-Type': 'application/json'
116
+ },
117
+ body: JSON.stringify(form)
118
+ }, "".concat(form.digitalCustomizationId, "/shopify-order/pay-referral-point"))];
119
+ case 1:
120
+ response = _a.sent();
121
+ return [2 /*return*/, response.json()];
122
+ }
123
+ });
124
+ });
125
+ };
126
+ return IKEAppDigitalCustomizationApi;
127
+ }(bxb_api_1.default));
128
+ exports.default = IKEAppDigitalCustomizationApi;
@@ -0,0 +1,72 @@
1
+ export interface ShopifyProductType {
2
+ product: ProductType;
3
+ }
4
+ interface ProductType {
5
+ id: number;
6
+ title: string;
7
+ body_html: string;
8
+ vendor: string;
9
+ product_type: string;
10
+ created_at: Date;
11
+ handle: string;
12
+ updated_at: Date;
13
+ published_at: Date;
14
+ template_suffix: string;
15
+ published_scope: string;
16
+ tags: string;
17
+ status: string;
18
+ admin_graphql_api_id: string;
19
+ variants: Variant[];
20
+ options: Option[];
21
+ images: Image[];
22
+ image: Image;
23
+ }
24
+ interface Image {
25
+ id: number;
26
+ alt: null;
27
+ position: number;
28
+ product_id: number;
29
+ created_at: Date;
30
+ updated_at: Date;
31
+ admin_graphql_api_id: string;
32
+ width: number;
33
+ height: number;
34
+ src: string;
35
+ variant_ids: any[];
36
+ }
37
+ interface Option {
38
+ id: number;
39
+ product_id: number;
40
+ name: string;
41
+ position: number;
42
+ values: string[];
43
+ }
44
+ interface Variant {
45
+ id: number;
46
+ product_id: number;
47
+ title: string;
48
+ price: string;
49
+ sku: string;
50
+ position: number;
51
+ inventory_policy: string;
52
+ compare_at_price: string;
53
+ fulfillment_service: string;
54
+ inventory_management: string;
55
+ option1: string;
56
+ option2: null;
57
+ option3: null;
58
+ created_at: Date;
59
+ updated_at: Date;
60
+ taxable: boolean;
61
+ barcode: string;
62
+ grams: number;
63
+ image_id: null;
64
+ weight: number;
65
+ weight_unit: string;
66
+ inventory_item_id: number;
67
+ inventory_quantity: number;
68
+ old_inventory_quantity: number;
69
+ requires_shipping: boolean;
70
+ admin_graphql_api_id: string;
71
+ }
72
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export declare enum UPLOAD_FILE_TYPE {
2
+ GENERAL_USER_IMAGE = 0
3
+ }
4
+ export declare const getUploadFileStr: (type: UPLOAD_FILE_TYPE) => string;
5
+ export default UPLOAD_FILE_TYPE;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUploadFileStr = exports.UPLOAD_FILE_TYPE = void 0;
4
+ var UPLOAD_FILE_TYPE;
5
+ (function (UPLOAD_FILE_TYPE) {
6
+ UPLOAD_FILE_TYPE[UPLOAD_FILE_TYPE["GENERAL_USER_IMAGE"] = 0] = "GENERAL_USER_IMAGE";
7
+ })(UPLOAD_FILE_TYPE = exports.UPLOAD_FILE_TYPE || (exports.UPLOAD_FILE_TYPE = {}));
8
+ var getUploadFileStr = function (type) {
9
+ var GENERAL_USER_IMAGE = UPLOAD_FILE_TYPE.GENERAL_USER_IMAGE;
10
+ switch (type) {
11
+ case GENERAL_USER_IMAGE:
12
+ return 'generalUserImage';
13
+ }
14
+ };
15
+ exports.getUploadFileStr = getUploadFileStr;
16
+ exports.default = UPLOAD_FILE_TYPE;
@@ -0,0 +1,34 @@
1
+ import BxBApi from '@bytexbyte/bxb-api';
2
+ declare type S3UploadBody = {
3
+ name: string;
4
+ };
5
+ declare type S3UploadResult = {
6
+ downloadUrl: string;
7
+ url: string;
8
+ error?: undefined;
9
+ } | {
10
+ downloadUrl?: undefined;
11
+ url?: undefined;
12
+ error: 'session not found.';
13
+ };
14
+ declare type UploadToS3Result = {
15
+ status: number;
16
+ };
17
+ declare type UploadResult = {
18
+ url: string;
19
+ error?: undefined;
20
+ } | {
21
+ url?: undefined;
22
+ error: 'fail to upload';
23
+ };
24
+ declare class IKEAppFileApi extends BxBApi {
25
+ constructor({ host, onSuccess, onError }: {
26
+ host: string;
27
+ onSuccess?: () => void;
28
+ onError?: (error: any) => void;
29
+ });
30
+ getS3UploadUrl({ name }: S3UploadBody): Promise<S3UploadResult>;
31
+ uploadToS3(uploadUrl: string, uri: string): Promise<UploadToS3Result>;
32
+ upload(fileName: string, uri: string): Promise<UploadResult>;
33
+ }
34
+ export default IKEAppFileApi;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ var bxb_api_1 = require("@bytexbyte/bxb-api");
55
+ var config_1 = require("../config");
56
+ var UploadFileType_1 = require("./UploadFileType");
57
+ var IKEAppFileApi = /** @class */ (function (_super) {
58
+ __extends(IKEAppFileApi, _super);
59
+ function IKEAppFileApi(_a) {
60
+ var host = _a.host, onSuccess = _a.onSuccess, onError = _a.onError;
61
+ return _super.call(this, {
62
+ host: host,
63
+ secretKey: config_1.localSecretKey, secret: '',
64
+ moduleName: 'file',
65
+ onSuccess: onSuccess,
66
+ onError: onError
67
+ }) || this;
68
+ }
69
+ IKEAppFileApi.prototype.getS3UploadUrl = function (_a) {
70
+ var name = _a.name;
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ var response;
73
+ return __generator(this, function (_b) {
74
+ switch (_b.label) {
75
+ case 0: return [4 /*yield*/, this.bxbFetch({
76
+ method: 'POST',
77
+ headers: {
78
+ 'Content-Type': 'application/json'
79
+ },
80
+ body: JSON.stringify({ name: "".concat((0, UploadFileType_1.getUploadFileStr)(UploadFileType_1.default.GENERAL_USER_IMAGE), "/").concat(new Date().getTime(), "/").concat(name) })
81
+ })];
82
+ case 1:
83
+ response = _b.sent();
84
+ return [2 /*return*/, response.json()];
85
+ }
86
+ });
87
+ });
88
+ };
89
+ IKEAppFileApi.prototype.uploadToS3 = function (uploadUrl, uri) {
90
+ return __awaiter(this, void 0, void 0, function () {
91
+ var result;
92
+ return __generator(this, function (_a) {
93
+ switch (_a.label) {
94
+ case 0: return [4 /*yield*/, fetch(uploadUrl, {
95
+ method: 'PUT',
96
+ headers: {
97
+ 'Content-Type': 'application/json',
98
+ 'Access-Control-Allow-Origin': '*'
99
+ },
100
+ body: { uri: uri, type: 'image/jpg' }
101
+ })];
102
+ case 1:
103
+ result = _a.sent();
104
+ return [2 /*return*/, result];
105
+ }
106
+ });
107
+ });
108
+ };
109
+ IKEAppFileApi.prototype.upload = function (fileName, uri) {
110
+ return __awaiter(this, void 0, void 0, function () {
111
+ var uploadUrlResult, result;
112
+ return __generator(this, function (_a) {
113
+ switch (_a.label) {
114
+ case 0: return [4 /*yield*/, this.getS3UploadUrl({ name: fileName })];
115
+ case 1:
116
+ uploadUrlResult = _a.sent();
117
+ if (!uploadUrlResult.url) return [3 /*break*/, 3];
118
+ return [4 /*yield*/, this.uploadToS3(uploadUrlResult.url, uri)];
119
+ case 2:
120
+ result = _a.sent();
121
+ if (result.status === 200)
122
+ return [2 /*return*/, { url: uploadUrlResult.downloadUrl }];
123
+ return [2 /*return*/, { error: 'fail to upload' }];
124
+ case 3: return [2 /*return*/, { error: 'fail to upload' }];
125
+ }
126
+ });
127
+ });
128
+ };
129
+ return IKEAppFileApi;
130
+ }(bxb_api_1.default));
131
+ exports.default = IKEAppFileApi;
@@ -0,0 +1,23 @@
1
+ import BxBApi from "@bytexbyte/bxb-api";
2
+ import { InAppNotificationType } from "./type";
3
+ declare class IKEApInAppNotificationApi extends BxBApi {
4
+ constructor({ host, secretKey, secret, onSuccess, onError }: {
5
+ host: string;
6
+ secretKey?: string;
7
+ secret?: string;
8
+ onSuccess?: () => void;
9
+ onError?: (error: any) => void;
10
+ });
11
+ createInAppNotification(body: {
12
+ receiverId: string;
13
+ userId?: string;
14
+ raffleId?: number;
15
+ type: InAppNotificationType;
16
+ sendPushNotification: boolean;
17
+ }): Promise<{
18
+ success: 'ok';
19
+ } | {
20
+ error: 'You are not authorized to call this API.' | 'Type is required.' | 'UserId is required.' | 'RaffleId is required.';
21
+ }>;
22
+ }
23
+ export default IKEApInAppNotificationApi;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ var bxb_api_1 = require("@bytexbyte/bxb-api");
55
+ var IKEApInAppNotificationApi = /** @class */ (function (_super) {
56
+ __extends(IKEApInAppNotificationApi, _super);
57
+ function IKEApInAppNotificationApi(_a) {
58
+ var host = _a.host, secretKey = _a.secretKey, secret = _a.secret, onSuccess = _a.onSuccess, onError = _a.onError;
59
+ return _super.call(this, {
60
+ host: host,
61
+ secretKey: secretKey !== null && secretKey !== void 0 ? secretKey : '',
62
+ secret: secret !== null && secret !== void 0 ? secret : '',
63
+ moduleName: 'in-app-notification',
64
+ onSuccess: onSuccess,
65
+ onError: onError
66
+ }) || this;
67
+ }
68
+ IKEApInAppNotificationApi.prototype.createInAppNotification = function (body) {
69
+ return __awaiter(this, void 0, void 0, function () {
70
+ var response;
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0: return [4 /*yield*/, this.bxbFetch({
74
+ method: 'POST',
75
+ headers: {
76
+ 'Content-Type': 'application/json',
77
+ },
78
+ body: JSON.stringify(body),
79
+ })];
80
+ case 1:
81
+ response = _a.sent();
82
+ return [2 /*return*/, response.json()];
83
+ }
84
+ });
85
+ });
86
+ };
87
+ return IKEApInAppNotificationApi;
88
+ }(bxb_api_1.default));
89
+ exports.default = IKEApInAppNotificationApi;
@@ -0,0 +1 @@
1
+ export declare type InAppNotificationType = "raffleStart" | "raffleWinner";
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });