merchi_sdk_ts 0.0.1
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/.babelrc +13 -0
- package/.eslintrc.cjs +43 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/jest.config.js +17 -0
- package/package.json +44 -0
- package/src/constants/auto_assign_production_on_actions.ts +6 -0
- package/src/constants/call_to_actions.test.ts +5 -0
- package/src/constants/call_to_actions.ts +14 -0
- package/src/constants/discount_types.test.ts +5 -0
- package/src/constants/discount_types.ts +3 -0
- package/src/constants/domain_types.test.ts +5 -0
- package/src/constants/domain_types.ts +12 -0
- package/src/constants/errors.ts +32 -0
- package/src/constants/event_types.test.ts +5 -0
- package/src/constants/event_types.ts +5 -0
- package/src/constants/field_types.test.ts +5 -0
- package/src/constants/field_types.ts +13 -0
- package/src/constants/input_types.test.ts +5 -0
- package/src/constants/input_types.ts +13 -0
- package/src/constants/inventory_status.test.ts +5 -0
- package/src/constants/inventory_statuses.ts +6 -0
- package/src/constants/invoice_types.test.ts +5 -0
- package/src/constants/invoice_types.ts +5 -0
- package/src/constants/item_types.test.ts +5 -0
- package/src/constants/item_types.ts +5 -0
- package/src/constants/job/drafting_status.test.ts +5 -0
- package/src/constants/job/drafting_status.ts +7 -0
- package/src/constants/job/payment_status.test.ts +5 -0
- package/src/constants/job/payment_status.ts +7 -0
- package/src/constants/job/production_status.test.ts +5 -0
- package/src/constants/job/production_status.ts +12 -0
- package/src/constants/job/shipment_status.test.ts +5 -0
- package/src/constants/job/shipment_status.ts +11 -0
- package/src/constants/job/supply_chain_request_status.test.ts +5 -0
- package/src/constants/job/supply_chain_request_status.ts +6 -0
- package/src/constants/job_priorities.test.ts +5 -0
- package/src/constants/job_priorities.ts +6 -0
- package/src/constants/job_status.test.ts +5 -0
- package/src/constants/job_status.ts +49 -0
- package/src/constants/job_types.test.ts +5 -0
- package/src/constants/job_types.ts +15 -0
- package/src/constants/notification_sections.test.ts +5 -0
- package/src/constants/notification_sections.ts +13 -0
- package/src/constants/notification_types.test.ts +5 -0
- package/src/constants/notification_types.ts +97 -0
- package/src/constants/notification_urgencies.test.ts +5 -0
- package/src/constants/notification_urgencies.ts +7 -0
- package/src/constants/payment_types.test.ts +5 -0
- package/src/constants/payment_types.ts +10 -0
- package/src/constants/platform.test.ts +15 -0
- package/src/constants/platform.ts +6 -0
- package/src/constants/product_types.test.ts +6 -0
- package/src/constants/product_types.ts +25 -0
- package/src/constants/rights.test.ts +5 -0
- package/src/constants/rights.ts +5 -0
- package/src/constants/robots_meta_directives.test.ts +5 -0
- package/src/constants/robots_meta_directives.ts +11 -0
- package/src/constants/roles.test.ts +5 -0
- package/src/constants/roles.ts +38 -0
- package/src/constants/shipment_companies.test.ts +5 -0
- package/src/constants/shipment_companies.ts +18 -0
- package/src/constants/shipment_services.test.ts +5 -0
- package/src/constants/shipment_services.ts +3 -0
- package/src/constants/system_roles.test.ts +5 -0
- package/src/constants/system_roles.ts +3 -0
- package/src/constants/theme_foundations.test.ts +5 -0
- package/src/constants/theme_foundations.ts +6 -0
- package/src/constants/theme_status.test.ts +5 -0
- package/src/constants/theme_status.ts +5 -0
- package/src/constants/user_types.test.ts +5 -0
- package/src/constants/user_types.ts +17 -0
- package/src/constants/white_label_accessibilities.test.ts +5 -0
- package/src/constants/white_label_accessibilities.ts +6 -0
- package/src/cookie.test.ts +11 -0
- package/src/cookie.ts +16 -0
- package/src/entities/address.test.ts +7 -0
- package/src/entities/address.ts +65 -0
- package/src/entities/assignment.test.ts +39 -0
- package/src/entities/assignment.ts +92 -0
- package/src/entities/automatic_payment_relationship.test.ts +8 -0
- package/src/entities/automatic_payment_relationship.ts +26 -0
- package/src/entities/backup.test.ts +7 -0
- package/src/entities/backup.ts +14 -0
- package/src/entities/bank.test.ts +7 -0
- package/src/entities/bank.ts +45 -0
- package/src/entities/cart.test.ts +50 -0
- package/src/entities/cart.ts +89 -0
- package/src/entities/cart_item.test.ts +33 -0
- package/src/entities/cart_item.ts +77 -0
- package/src/entities/cart_shipment_group.ts +21 -0
- package/src/entities/cart_shipment_quote.ts +33 -0
- package/src/entities/category.test.ts +57 -0
- package/src/entities/category.ts +37 -0
- package/src/entities/company.test.ts +7 -0
- package/src/entities/company.ts +275 -0
- package/src/entities/company_invitation.test.ts +7 -0
- package/src/entities/company_invitation.ts +33 -0
- package/src/entities/component.test.ts +14 -0
- package/src/entities/component.ts +92 -0
- package/src/entities/component_tag.test.ts +7 -0
- package/src/entities/component_tag.ts +17 -0
- package/src/entities/component_version.test.ts +7 -0
- package/src/entities/component_version.ts +30 -0
- package/src/entities/country_tax.test.ts +13 -0
- package/src/entities/country_tax.ts +46 -0
- package/src/entities/discount.test.ts +18 -0
- package/src/entities/discount.ts +34 -0
- package/src/entities/discount_group.test.ts +7 -0
- package/src/entities/discount_group.ts +28 -0
- package/src/entities/domain.test.ts +79 -0
- package/src/entities/domain.ts +246 -0
- package/src/entities/domain_invitation.test.ts +7 -0
- package/src/entities/domain_invitation.ts +36 -0
- package/src/entities/domain_tag.test.ts +7 -0
- package/src/entities/domain_tag.ts +42 -0
- package/src/entities/draft.test.ts +43 -0
- package/src/entities/draft.ts +88 -0
- package/src/entities/draft_comment.test.ts +7 -0
- package/src/entities/draft_comment.ts +54 -0
- package/src/entities/draft_template.test.ts +7 -0
- package/src/entities/draft_template.ts +40 -0
- package/src/entities/email_address.test.ts +7 -0
- package/src/entities/email_address.ts +24 -0
- package/src/entities/email_counter.test.ts +7 -0
- package/src/entities/email_counter.ts +20 -0
- package/src/entities/enrolled_domain.test.ts +7 -0
- package/src/entities/enrolled_domain.ts +40 -0
- package/src/entities/exchange_rate.test.ts +7 -0
- package/src/entities/exchange_rate.ts +22 -0
- package/src/entities/file.test.ts +43 -0
- package/src/entities/file.ts +172 -0
- package/src/entities/internal_tag.test.ts +7 -0
- package/src/entities/internal_tag.ts +51 -0
- package/src/entities/inventory.test.ts +28 -0
- package/src/entities/inventory.ts +56 -0
- package/src/entities/inventory_unit_variation.test.ts +7 -0
- package/src/entities/inventory_unit_variation.ts +29 -0
- package/src/entities/invoice.test.ts +43 -0
- package/src/entities/invoice.ts +179 -0
- package/src/entities/item.test.ts +19 -0
- package/src/entities/item.ts +44 -0
- package/src/entities/job.test.ts +95 -0
- package/src/entities/job.ts +349 -0
- package/src/entities/job_comment.test.ts +7 -0
- package/src/entities/job_comment.ts +50 -0
- package/src/entities/matching_inventory.ts +29 -0
- package/src/entities/menu.test.ts +7 -0
- package/src/entities/menu.ts +30 -0
- package/src/entities/menu_item.test.ts +7 -0
- package/src/entities/menu_item.ts +29 -0
- package/src/entities/notification.test.ts +7 -0
- package/src/entities/notification.ts +99 -0
- package/src/entities/page.test.ts +7 -0
- package/src/entities/page.ts +32 -0
- package/src/entities/payment.test.ts +19 -0
- package/src/entities/payment.ts +65 -0
- package/src/entities/payment_device.test.ts +7 -0
- package/src/entities/payment_device.ts +30 -0
- package/src/entities/phone_number.test.ts +7 -0
- package/src/entities/phone_number.ts +36 -0
- package/src/entities/product.test.ts +750 -0
- package/src/entities/product.ts +427 -0
- package/src/entities/production_comment.test.ts +7 -0
- package/src/entities/production_comment.ts +50 -0
- package/src/entities/quote.test.ts +98 -0
- package/src/entities/quote.ts +140 -0
- package/src/entities/quote_item.test.ts +50 -0
- package/src/entities/quote_item.ts +71 -0
- package/src/entities/seo_domain_page.test.ts +7 -0
- package/src/entities/seo_domain_page.ts +33 -0
- package/src/entities/session.test.ts +7 -0
- package/src/entities/session.ts +28 -0
- package/src/entities/shipment.test.ts +24 -0
- package/src/entities/shipment.ts +185 -0
- package/src/entities/shipment_item.test.ts +7 -0
- package/src/entities/shipment_item.ts +15 -0
- package/src/entities/shipment_item_fulfillment.test.ts +8 -0
- package/src/entities/shipment_item_fulfillment.ts +15 -0
- package/src/entities/shipment_method.test.ts +7 -0
- package/src/entities/shipment_method.ts +61 -0
- package/src/entities/shipment_method_variation.test.ts +7 -0
- package/src/entities/shipment_method_variation.ts +39 -0
- package/src/entities/short_url.test.ts +7 -0
- package/src/entities/short_url.ts +36 -0
- package/src/entities/subscription_plan.test.ts +7 -0
- package/src/entities/subscription_plan.ts +73 -0
- package/src/entities/supply_domain.test.ts +7 -0
- package/src/entities/supply_domain.ts +27 -0
- package/src/entities/system_role.test.ts +7 -0
- package/src/entities/system_role.ts +17 -0
- package/src/entities/theme.test.ts +38 -0
- package/src/entities/theme.ts +267 -0
- package/src/entities/theme_css_setting.test.ts +7 -0
- package/src/entities/theme_css_setting.ts +23 -0
- package/src/entities/user.test.ts +154 -0
- package/src/entities/user.ts +394 -0
- package/src/entities/user_company.test.ts +7 -0
- package/src/entities/user_company.ts +27 -0
- package/src/entities/variation.test.ts +7 -0
- package/src/entities/variation.ts +61 -0
- package/src/entities/variation_field.test.ts +76 -0
- package/src/entities/variation_field.ts +169 -0
- package/src/entities/variation_fields_option.test.ts +46 -0
- package/src/entities/variation_fields_option.ts +95 -0
- package/src/entities/variation_option.test.ts +7 -0
- package/src/entities/variation_option.ts +52 -0
- package/src/entities/variations_group.test.ts +7 -0
- package/src/entities/variations_group.ts +41 -0
- package/src/entity.ts +1002 -0
- package/src/merchi.test.ts +25 -0
- package/src/merchi.ts +379 -0
- package/src/request.test.ts +43 -0
- package/src/request.ts +124 -0
- package/src/test_util.ts +18 -0
- package/src/toasts.test.ts +38 -0
- package/src/toasts.ts +34 -0
- package/src/util/float.ts +12 -0
- package/src/util/query_string.test.ts +7 -0
- package/src/util/query_string.ts +11 -0
- package/src/util/validation.test.ts +16 -0
- package/src/util/validation.ts +2 -0
- package/src/uuid.test.ts +15 -0
- package/src/uuid.ts +8 -0
- package/tsconfig.json +23 -0
- package/webpack.config.cjs +27 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
platformName,
|
|
3
|
+
platformCopyright,
|
|
4
|
+
platformDomain,
|
|
5
|
+
platformSellerDomain,
|
|
6
|
+
platformSellerDomainPlus
|
|
7
|
+
} from './platform';
|
|
8
|
+
|
|
9
|
+
test('platform variables all there', () => {
|
|
10
|
+
expect(platformName).toBe('Merchi');
|
|
11
|
+
expect(platformCopyright).toBe(2021);
|
|
12
|
+
expect(platformDomain).toBe('merchi.co');
|
|
13
|
+
expect(platformSellerDomain).toBe('merchi.co');
|
|
14
|
+
expect(platformSellerDomainPlus).toBe('merchi.co');
|
|
15
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export enum ProductType {
|
|
2
|
+
SUPPLIER_MOD = 0,
|
|
3
|
+
SUPPLIER = 1,
|
|
4
|
+
SELLER = 2,
|
|
5
|
+
SELLER_MOD = 3,
|
|
6
|
+
CLONED_SUPPLIER_MOD = 4,
|
|
7
|
+
CLONED_SELLER_MOD = 5,
|
|
8
|
+
PRODUCTION_MOD = 6,
|
|
9
|
+
CLONED_SUPPLIER = 7,
|
|
10
|
+
INVENTORY_SELLER = 8,
|
|
11
|
+
INVENTORY_SUPPLIER = 9,
|
|
12
|
+
SELLER_GROUP_BUY = 10,
|
|
13
|
+
SUPPLIER_RESELL_MOD = 11,
|
|
14
|
+
SUPPLIER_RESELL = 12,
|
|
15
|
+
SUPPLIER_GROUP_BUY_INVENTORY = 13,
|
|
16
|
+
CLONED_INVENTORY_SELLER = 14,
|
|
17
|
+
CLONED_SELLER_GROUP_BUY_INVENTORY = 15,
|
|
18
|
+
CLONED_SUPPLIER_RESELL_MOD = 16,
|
|
19
|
+
SUPPLIER_TO_SUPPLIER_RESELL_MOD = 17,
|
|
20
|
+
CLONED_SUPPLIER_RESELL = 18,
|
|
21
|
+
SUPPLY_DOMAIN_REFERENCE = 19,
|
|
22
|
+
SELLER_FILE_DOWNLOAD = 20,
|
|
23
|
+
SUPPLIER_MOD_SUPPLY_CHAIN_REQUEST = 21,
|
|
24
|
+
SUPPLIER_SUPPLY_CHAIN_REQUEST = 22,
|
|
25
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export enum Role {
|
|
2
|
+
PUBLIC = 0,
|
|
3
|
+
ADMIN = 1,
|
|
4
|
+
SALES = 2,
|
|
5
|
+
DESIGNER = 3,
|
|
6
|
+
SUPPLIER = 4,
|
|
7
|
+
CLIENT = 5,
|
|
8
|
+
MANAGER = 6,
|
|
9
|
+
ACCOUNTANT = 7,
|
|
10
|
+
THEME_EDITOR = 8,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const DOMAIN_MANAGERS = [Role.ADMIN, Role.MANAGER];
|
|
14
|
+
|
|
15
|
+
export const MANAGEMENT_TEAM = [
|
|
16
|
+
...DOMAIN_MANAGERS,
|
|
17
|
+
Role.SALES,
|
|
18
|
+
Role.DESIGNER,
|
|
19
|
+
Role.ACCOUNTANT,
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export const BUSINESS_ACCOUNTS = [...MANAGEMENT_TEAM, Role.SUPPLIER];
|
|
23
|
+
|
|
24
|
+
export const MANAGEMENT_ROLES = [Role.ADMIN, Role.MANAGER];
|
|
25
|
+
|
|
26
|
+
export const THEME_ROLES = [...MANAGEMENT_ROLES, Role.THEME_EDITOR];
|
|
27
|
+
export const ROLES_RANK = [
|
|
28
|
+
Role.PUBLIC,
|
|
29
|
+
Role.CLIENT,
|
|
30
|
+
Role.ACCOUNTANT,
|
|
31
|
+
Role.SALES,
|
|
32
|
+
Role.DESIGNER,
|
|
33
|
+
Role.SUPPLIER,
|
|
34
|
+
Role.MANAGER,
|
|
35
|
+
Role.ADMIN,
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
export const ALL_ROLES = ROLES_RANK;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export enum ShipmentCompany {
|
|
2
|
+
DHL = 0,
|
|
3
|
+
UPS = 1,
|
|
4
|
+
EMS = 2,
|
|
5
|
+
FED_EX = 3,
|
|
6
|
+
AUSTRALIA_POST = 4,
|
|
7
|
+
STAR_TRACK = 5,
|
|
8
|
+
TOLL = 6,
|
|
9
|
+
TNT = 7,
|
|
10
|
+
CUSTOM_TRACK_LINK = 8,
|
|
11
|
+
ARAMEX = 9,
|
|
12
|
+
REALTIME_EXPRESS = 10,
|
|
13
|
+
UBER = 11,
|
|
14
|
+
CIVIC_TRANSPORT_COURIERS = 12,
|
|
15
|
+
NZ_POST = 13,
|
|
16
|
+
SENDLE = 14,
|
|
17
|
+
USPS = 15,
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export enum UserType {
|
|
2
|
+
PUBLIC = 0,
|
|
3
|
+
CLIENT_GUEST = 1, // A user who has not oppted in for a user account
|
|
4
|
+
CLIENT_DOMAIN = 2, // A user who is a client of one domain
|
|
5
|
+
CLIENT_MULTIPLE_DOMAINS = 3, // A user who is a client of multiple domains
|
|
6
|
+
CLIENT_MERCHI = 4, // A user has a client profile with Merchi
|
|
7
|
+
SELLER_FREE_MERCHI = 5, // A user who has opened a seller store through Merchi
|
|
8
|
+
SELLER_FREE_DOMAIN = 6, // A user who has opened a seller store through a domain/supplier
|
|
9
|
+
SELLER_PAID = 7, // A user who is paying for a seller store
|
|
10
|
+
SELLER_PAID_MULTIPLE_DOMAINS = 8, // A user who is paying for multiple seller stores
|
|
11
|
+
SUPPLIER_THIRD_PARTY = 9, // A user who has a "domain supplier" domain
|
|
12
|
+
SUPPLIER_RESTRICTED = 10, // A user who has a restricted supply domain
|
|
13
|
+
SUPPLIER_MERCHI = 11, // A user who has a supply domain which has been verified by Merchi
|
|
14
|
+
UNRESTRICTED = 12, // A user who has a domain which is unrestricted
|
|
15
|
+
SHOPIFY_REFERENCE = 13, // A user who makes order from shopify and linked to our system
|
|
16
|
+
RESERVED_FROM_SOCIAL = 14, // A user crawled from Social network
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getCookie } from './cookie';
|
|
2
|
+
|
|
3
|
+
test('can get cookie', () => {
|
|
4
|
+
const token = 'IMiF7rpT$5ciUJ38QY';
|
|
5
|
+
const cookie = `session_token=${token}`;
|
|
6
|
+
Object.defineProperty(document, 'cookie', {
|
|
7
|
+
get: jest.fn().mockImplementation(() => { return cookie; }),
|
|
8
|
+
set: jest.fn().mockImplementation(() => {}),
|
|
9
|
+
});
|
|
10
|
+
expect(getCookie('session_token')).toBe('IMiF7rpT$5ciUJ38QY');
|
|
11
|
+
});
|
package/src/cookie.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function getCookie(name: string) {
|
|
2
|
+
// code might be executed during SSR
|
|
3
|
+
// istanbul ignore next
|
|
4
|
+
if (typeof document !== 'undefined') {
|
|
5
|
+
const searchPrefix = name + '=',
|
|
6
|
+
cookies = document.cookie.split(';');
|
|
7
|
+
for (let i = 0; i < cookies.length; ++i) {
|
|
8
|
+
let cookie = cookies[i];
|
|
9
|
+
cookie = cookie.replace(/^\s*/, '');
|
|
10
|
+
if (cookie.indexOf(searchPrefix) === 0) {
|
|
11
|
+
return cookie.substring(searchPrefix.length, cookie.length);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Bank } from './bank';
|
|
2
|
+
import { Company } from './company';
|
|
3
|
+
import { Entity } from '../entity';
|
|
4
|
+
import { Inventory } from './inventory';
|
|
5
|
+
import { Invoice } from './invoice';
|
|
6
|
+
import { Job } from './job';
|
|
7
|
+
import { Shipment } from './shipment';
|
|
8
|
+
import { User } from './user';
|
|
9
|
+
|
|
10
|
+
export class Address extends Entity {
|
|
11
|
+
protected static resourceName = 'addresses';
|
|
12
|
+
protected static singularName = 'address';
|
|
13
|
+
protected static pluralName = 'addresses';
|
|
14
|
+
|
|
15
|
+
@Address.property({type: Date})
|
|
16
|
+
public archived?: Date | null;
|
|
17
|
+
|
|
18
|
+
@Address.property()
|
|
19
|
+
public id?: number;
|
|
20
|
+
|
|
21
|
+
@Address.property({type: String})
|
|
22
|
+
public lineOne?: string | null;
|
|
23
|
+
|
|
24
|
+
@Address.property({type: String})
|
|
25
|
+
public lineTwo?: string | null;
|
|
26
|
+
|
|
27
|
+
@Address.property({type: String})
|
|
28
|
+
public city?: string | null;
|
|
29
|
+
|
|
30
|
+
@Address.property({type: String})
|
|
31
|
+
public state?: string | null;
|
|
32
|
+
|
|
33
|
+
@Address.property({type: String})
|
|
34
|
+
public country?: string | null;
|
|
35
|
+
|
|
36
|
+
@Address.property({type: String})
|
|
37
|
+
public postcode?: string | null;
|
|
38
|
+
|
|
39
|
+
@Address.property({arrayType: 'Shipment'})
|
|
40
|
+
public shipmentAsSenderAddress?: Shipment[];
|
|
41
|
+
|
|
42
|
+
@Address.property({arrayType: 'Shipment'})
|
|
43
|
+
public shipmentsAsReceiverAddress?: Shipment[];
|
|
44
|
+
|
|
45
|
+
@Address.property({arrayType: 'Bank'})
|
|
46
|
+
public banks?: Bank[];
|
|
47
|
+
|
|
48
|
+
@Address.property({arrayType: 'User'})
|
|
49
|
+
public users?: User[];
|
|
50
|
+
|
|
51
|
+
@Address.property({arrayType: 'Inventory'})
|
|
52
|
+
public inventories?: Inventory[];
|
|
53
|
+
|
|
54
|
+
@Address.property({arrayType: 'Job'})
|
|
55
|
+
public jobs?: Job[];
|
|
56
|
+
|
|
57
|
+
@Address.property({arrayType: 'Job'})
|
|
58
|
+
public productedJobs?: Job[];
|
|
59
|
+
|
|
60
|
+
@Address.property({arrayType: 'Invoice'})
|
|
61
|
+
public shippingTo?: Invoice[];
|
|
62
|
+
|
|
63
|
+
@Address.property({arrayType: 'Company'})
|
|
64
|
+
public companies?: Company[];
|
|
65
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Merchi } from '../merchi';
|
|
2
|
+
import { setup, mockFetch } from '../test_util';
|
|
3
|
+
|
|
4
|
+
setup();
|
|
5
|
+
|
|
6
|
+
test('can make Assignment', () => {
|
|
7
|
+
const merchi = new Merchi();
|
|
8
|
+
const assignment = new merchi.Assignment();
|
|
9
|
+
expect(assignment).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('can generate new invoice', () => {
|
|
13
|
+
mockFetch(true, {'id': 1, 'totalCost': 100}, 200);
|
|
14
|
+
|
|
15
|
+
const merchi = new Merchi();
|
|
16
|
+
const assignment = new merchi.Assignment();
|
|
17
|
+
assignment.id = 1;
|
|
18
|
+
assignment.generateInvoice().then(invoice => {
|
|
19
|
+
expect(invoice.totalCost).toEqual(100);
|
|
20
|
+
expect(invoice.id).toEqual(1);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('can add to invoice', () => {
|
|
25
|
+
const fetch = mockFetch(true, {'id': 2, 'totalCost': 100}, 200);
|
|
26
|
+
const merchi = new Merchi();
|
|
27
|
+
const assignment = new merchi.Assignment();
|
|
28
|
+
assignment.id = 1;
|
|
29
|
+
assignment.generateInvoice({addToInvoice: 2}).then(invoice => {
|
|
30
|
+
expect(invoice.totalCost).toEqual(100);
|
|
31
|
+
expect(invoice.id).toEqual(2);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const correct = [['add_to_invoice', '2']];
|
|
35
|
+
expect(
|
|
36
|
+
Array.from(fetch.mock.calls[0][1]['query'])
|
|
37
|
+
).toEqual(correct);
|
|
38
|
+
});
|
|
39
|
+
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Entity } from '../entity';
|
|
2
|
+
import { Quote } from './quote';
|
|
3
|
+
import { MerchiFile } from './file';
|
|
4
|
+
import { Job } from './job';
|
|
5
|
+
import { Notification } from './notification';
|
|
6
|
+
import { ProductionComment } from './production_comment';
|
|
7
|
+
import { Shipment } from './shipment';
|
|
8
|
+
import { SupplyDomain } from './supply_domain';
|
|
9
|
+
import { User } from './user';
|
|
10
|
+
import { RequestOptions } from '../request';
|
|
11
|
+
|
|
12
|
+
interface GenerateInvoiceProps {
|
|
13
|
+
addToInvoice? : number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class Assignment extends Entity {
|
|
17
|
+
protected static resourceName = 'assignments';
|
|
18
|
+
protected static singularName = 'assignment';
|
|
19
|
+
protected static pluralName = 'assignments';
|
|
20
|
+
|
|
21
|
+
@Assignment.property({type: Date})
|
|
22
|
+
public archived?: Date | null;
|
|
23
|
+
|
|
24
|
+
@Assignment.property()
|
|
25
|
+
public id?: number;
|
|
26
|
+
|
|
27
|
+
@Assignment.property({type: Date})
|
|
28
|
+
public managerAccepts?: Date | null;
|
|
29
|
+
|
|
30
|
+
@Assignment.property({type: Date})
|
|
31
|
+
public supplierRefused?: Date | null;
|
|
32
|
+
|
|
33
|
+
@Assignment.property()
|
|
34
|
+
public needsDrafting?: boolean;
|
|
35
|
+
|
|
36
|
+
@Assignment.property()
|
|
37
|
+
public needsShipping?: boolean;
|
|
38
|
+
|
|
39
|
+
@Assignment.property()
|
|
40
|
+
public productionDeadline?: Date;
|
|
41
|
+
|
|
42
|
+
@Assignment.property()
|
|
43
|
+
public assignmentDeadline?: Date;
|
|
44
|
+
|
|
45
|
+
@Assignment.property({type: String})
|
|
46
|
+
public notes?: string | null;
|
|
47
|
+
|
|
48
|
+
@Assignment.property({type: 'Job'})
|
|
49
|
+
public job?: Job | null;
|
|
50
|
+
|
|
51
|
+
@Assignment.property({type: 'Job'})
|
|
52
|
+
public supplyJob?: Job | null;
|
|
53
|
+
|
|
54
|
+
@Assignment.property({type: User})
|
|
55
|
+
public supplier?: User | null;
|
|
56
|
+
|
|
57
|
+
@Assignment.property({type: Quote})
|
|
58
|
+
public quote?: Quote | null;
|
|
59
|
+
|
|
60
|
+
@Assignment.property({arrayType: 'ProductionComment'})
|
|
61
|
+
public comments?: ProductionComment[];
|
|
62
|
+
|
|
63
|
+
@Assignment.property({type: Shipment})
|
|
64
|
+
public shipment?: Shipment | null;
|
|
65
|
+
|
|
66
|
+
@Assignment.property({type: SupplyDomain})
|
|
67
|
+
public supplyDomain?: SupplyDomain | null;
|
|
68
|
+
|
|
69
|
+
@Assignment.property({arrayType: 'Notification'})
|
|
70
|
+
public notifications?: Notification[];
|
|
71
|
+
|
|
72
|
+
@Assignment.property({arrayType: 'MerchiFile'})
|
|
73
|
+
public productionFiles?: MerchiFile[];
|
|
74
|
+
|
|
75
|
+
public generateInvoice = (props?: GenerateInvoiceProps) => {
|
|
76
|
+
const resource = `/generate-invoice-for-assignment/${this.id}/`;
|
|
77
|
+
const fetchOptions: RequestOptions = {method: 'POST'};
|
|
78
|
+
fetchOptions.query = [];
|
|
79
|
+
|
|
80
|
+
if (props && props.addToInvoice) {
|
|
81
|
+
fetchOptions.query.push(['add_to_invoice', String(props.addToInvoice!)]);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return this.merchi.authenticatedFetch(resource, fetchOptions).
|
|
85
|
+
then((data: any) => {
|
|
86
|
+
const invoice = new this.merchi.Invoice();
|
|
87
|
+
invoice.fromJson(data);
|
|
88
|
+
return invoice;
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Merchi } from '../merchi';
|
|
2
|
+
|
|
3
|
+
test('can make AutomaticPaymentRelationship', () => {
|
|
4
|
+
const merchi = new Merchi();
|
|
5
|
+
const automaticPaymentRelationship =
|
|
6
|
+
new merchi.AutomaticPaymentRelationship();
|
|
7
|
+
expect(automaticPaymentRelationship).toBeTruthy();
|
|
8
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Company } from './company';
|
|
2
|
+
import { Entity } from '../entity';
|
|
3
|
+
|
|
4
|
+
export class AutomaticPaymentRelationship extends Entity {
|
|
5
|
+
protected static resourceName = 'automatic_payment_relationships';
|
|
6
|
+
protected static singularName = 'automaticPaymentRelationship';
|
|
7
|
+
protected static pluralName = 'automaticPaymentRelationships';
|
|
8
|
+
|
|
9
|
+
@AutomaticPaymentRelationship.property({type: Date})
|
|
10
|
+
public archived?: Date | null;
|
|
11
|
+
|
|
12
|
+
@AutomaticPaymentRelationship.property()
|
|
13
|
+
public id?: number;
|
|
14
|
+
|
|
15
|
+
@AutomaticPaymentRelationship.property()
|
|
16
|
+
public creationDate?: Date;
|
|
17
|
+
|
|
18
|
+
@AutomaticPaymentRelationship.property({type: Company})
|
|
19
|
+
public companyCustomer?: Company;
|
|
20
|
+
|
|
21
|
+
@AutomaticPaymentRelationship.property({type: Company})
|
|
22
|
+
public companySupplier?: Company;
|
|
23
|
+
|
|
24
|
+
@AutomaticPaymentRelationship.property({type: String})
|
|
25
|
+
public stripeCustomerId?: string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Entity } from '../entity';
|
|
2
|
+
import { MerchiFile } from './file';
|
|
3
|
+
|
|
4
|
+
export class Backup extends Entity {
|
|
5
|
+
protected static resourceName = 'backups';
|
|
6
|
+
protected static singularName = 'backup';
|
|
7
|
+
protected static pluralName = 'backups';
|
|
8
|
+
|
|
9
|
+
@Backup.property()
|
|
10
|
+
public id?: number;
|
|
11
|
+
|
|
12
|
+
@Backup.property()
|
|
13
|
+
public file?: MerchiFile;
|
|
14
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Address } from './address';
|
|
2
|
+
import { Company } from './company';
|
|
3
|
+
import { Entity } from '../entity';
|
|
4
|
+
|
|
5
|
+
export class Bank extends Entity {
|
|
6
|
+
protected static resourceName = 'banks';
|
|
7
|
+
protected static singularName = 'bank';
|
|
8
|
+
protected static pluralName = 'banks';
|
|
9
|
+
|
|
10
|
+
@Bank.property({type: Date})
|
|
11
|
+
public archived?: Date | null;
|
|
12
|
+
|
|
13
|
+
@Bank.property()
|
|
14
|
+
public id?: number;
|
|
15
|
+
|
|
16
|
+
@Bank.property()
|
|
17
|
+
public default?: boolean;
|
|
18
|
+
|
|
19
|
+
@Bank.property()
|
|
20
|
+
public bankName?: string;
|
|
21
|
+
|
|
22
|
+
@Bank.property()
|
|
23
|
+
public accountNumber?: string;
|
|
24
|
+
|
|
25
|
+
@Bank.property()
|
|
26
|
+
public accountName?: string;
|
|
27
|
+
|
|
28
|
+
@Bank.property({type: String})
|
|
29
|
+
public bsb?: string | null;
|
|
30
|
+
|
|
31
|
+
@Bank.property({type: String})
|
|
32
|
+
public swiftCode?: string | null;
|
|
33
|
+
|
|
34
|
+
@Bank.property({type: String})
|
|
35
|
+
public iban?: string | null;
|
|
36
|
+
|
|
37
|
+
@Bank.property({type: String})
|
|
38
|
+
public bankCode?: string | null;
|
|
39
|
+
|
|
40
|
+
@Bank.property({type: 'Address'})
|
|
41
|
+
public bankAddress?: Address | null;
|
|
42
|
+
|
|
43
|
+
@Bank.property()
|
|
44
|
+
public company?: Company;
|
|
45
|
+
}
|