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,33 @@
|
|
|
1
|
+
import { Company } from './company';
|
|
2
|
+
import { Entity } from '../entity';
|
|
3
|
+
import { User } from './user';
|
|
4
|
+
|
|
5
|
+
export class CompanyInvitation extends Entity {
|
|
6
|
+
protected static resourceName = 'company_invitations';
|
|
7
|
+
protected static singularName = 'companyInvitation';
|
|
8
|
+
protected static pluralName = 'companyInvitations';
|
|
9
|
+
|
|
10
|
+
@CompanyInvitation.property({type: Date})
|
|
11
|
+
public archived?: Date | null;
|
|
12
|
+
|
|
13
|
+
@CompanyInvitation.property()
|
|
14
|
+
public id?: number;
|
|
15
|
+
|
|
16
|
+
@CompanyInvitation.property()
|
|
17
|
+
public userName?: string;
|
|
18
|
+
|
|
19
|
+
@CompanyInvitation.property()
|
|
20
|
+
public userEmail?: string;
|
|
21
|
+
|
|
22
|
+
@CompanyInvitation.property()
|
|
23
|
+
public inviteAsAdmin?: boolean;
|
|
24
|
+
|
|
25
|
+
@CompanyInvitation.property()
|
|
26
|
+
public token?: string;
|
|
27
|
+
|
|
28
|
+
@CompanyInvitation.property()
|
|
29
|
+
public company?: Company;
|
|
30
|
+
|
|
31
|
+
@CompanyInvitation.property()
|
|
32
|
+
public sender?: User;
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Merchi } from '../merchi';
|
|
2
|
+
|
|
3
|
+
test('can make Component', () => {
|
|
4
|
+
const merchi = new Merchi();
|
|
5
|
+
const component = new merchi.Component();
|
|
6
|
+
expect(component).toBeTruthy();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test('can convert to react component', () => {
|
|
10
|
+
const merchi = new Merchi();
|
|
11
|
+
const component = new merchi.Component();
|
|
12
|
+
component.compiled = 'return 1;';
|
|
13
|
+
component.toReact({});
|
|
14
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ComponentTag } from './component_tag';
|
|
2
|
+
import { ComponentVersion } from './component_version';
|
|
3
|
+
import { Entity } from '../entity';
|
|
4
|
+
import { MerchiFile } from './file';
|
|
5
|
+
import { User } from './user';
|
|
6
|
+
|
|
7
|
+
export class Component extends Entity {
|
|
8
|
+
protected static resourceName = 'components';
|
|
9
|
+
protected static singularName = 'component';
|
|
10
|
+
protected static pluralName = 'components';
|
|
11
|
+
|
|
12
|
+
@Component.property({type: Date})
|
|
13
|
+
public archived?: Date | null;
|
|
14
|
+
|
|
15
|
+
@Component.property({type: Date})
|
|
16
|
+
public created?: Date;
|
|
17
|
+
|
|
18
|
+
@Component.property({type: Date})
|
|
19
|
+
public updated?: Date;
|
|
20
|
+
|
|
21
|
+
@Component.property()
|
|
22
|
+
public id?: number;
|
|
23
|
+
|
|
24
|
+
@Component.property()
|
|
25
|
+
public isClassBased?: boolean;
|
|
26
|
+
|
|
27
|
+
@Component.property()
|
|
28
|
+
public outOfSyncWithOriginal?: boolean;
|
|
29
|
+
|
|
30
|
+
@Component.property()
|
|
31
|
+
public needsUpdate?: boolean;
|
|
32
|
+
|
|
33
|
+
@Component.property()
|
|
34
|
+
public hasImports?: number;
|
|
35
|
+
|
|
36
|
+
@Component.property()
|
|
37
|
+
public isClone?: boolean;
|
|
38
|
+
|
|
39
|
+
@Component.property()
|
|
40
|
+
public warnings?: boolean;
|
|
41
|
+
|
|
42
|
+
@Component.property()
|
|
43
|
+
public name?: string;
|
|
44
|
+
|
|
45
|
+
@Component.property()
|
|
46
|
+
public body?: string;
|
|
47
|
+
|
|
48
|
+
@Component.property()
|
|
49
|
+
public description?: string;
|
|
50
|
+
|
|
51
|
+
@Component.property()
|
|
52
|
+
public compiled?: string;
|
|
53
|
+
|
|
54
|
+
@Component.property({type: 'Component'})
|
|
55
|
+
public componentExport?: Component;
|
|
56
|
+
|
|
57
|
+
@Component.property({arrayType: 'Component'})
|
|
58
|
+
public componentExports?: Component[];
|
|
59
|
+
|
|
60
|
+
@Component.property({arrayType: 'Component'})
|
|
61
|
+
public componentImports?: Component[];
|
|
62
|
+
|
|
63
|
+
@Component.property({type: 'Component'})
|
|
64
|
+
public originalComponent?: Component;
|
|
65
|
+
|
|
66
|
+
@Component.property({arrayType: 'MerchiFile'})
|
|
67
|
+
public images?: MerchiFile[];
|
|
68
|
+
|
|
69
|
+
@Component.property({type: MerchiFile})
|
|
70
|
+
public featureImage?: MerchiFile | null;
|
|
71
|
+
|
|
72
|
+
@Component.property({arrayType: 'ComponentTag'})
|
|
73
|
+
public tags?: ComponentTag[];
|
|
74
|
+
|
|
75
|
+
@Component.property({type: 'User'})
|
|
76
|
+
public createdBy?: User | null;
|
|
77
|
+
|
|
78
|
+
@Component.property({type: 'User'})
|
|
79
|
+
public updatedBy?: User | null;
|
|
80
|
+
|
|
81
|
+
@Component.property({arrayType: 'ComponentVersion'})
|
|
82
|
+
public versions?: ComponentVersion[];
|
|
83
|
+
|
|
84
|
+
public toReact = (context: any) => {
|
|
85
|
+
const componentCode = 'with (this) { ' + this.compiled + ' return ' +
|
|
86
|
+
this.name + ';}';
|
|
87
|
+
const proxy = new Proxy(context, {});
|
|
88
|
+
const callable = new Function(componentCode);
|
|
89
|
+
return callable.call(proxy);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Component } from './component';
|
|
2
|
+
import { Entity } from '../entity';
|
|
3
|
+
|
|
4
|
+
export class ComponentTag extends Entity {
|
|
5
|
+
protected static resourceName = 'component_tags';
|
|
6
|
+
protected static singularName = 'componentTag';
|
|
7
|
+
protected static pluralName = 'componentTags';
|
|
8
|
+
|
|
9
|
+
@ComponentTag.property()
|
|
10
|
+
public id?: number;
|
|
11
|
+
|
|
12
|
+
@ComponentTag.property()
|
|
13
|
+
public name?: string;
|
|
14
|
+
|
|
15
|
+
@ComponentTag.property()
|
|
16
|
+
public component?: Component;
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Component } from './component';
|
|
2
|
+
import { Entity } from '../entity';
|
|
3
|
+
|
|
4
|
+
export class ComponentVersion extends Entity {
|
|
5
|
+
protected static resourceName = 'component_versions';
|
|
6
|
+
protected static singularName = 'componentVersion';
|
|
7
|
+
protected static pluralName = 'componentVersions';
|
|
8
|
+
|
|
9
|
+
@ComponentVersion.property({type: Date})
|
|
10
|
+
public archived?: Date | null;
|
|
11
|
+
|
|
12
|
+
@ComponentVersion.property({type: Date})
|
|
13
|
+
public created?: Date | null;
|
|
14
|
+
|
|
15
|
+
@ComponentVersion.property()
|
|
16
|
+
public id?: number;
|
|
17
|
+
|
|
18
|
+
@ComponentVersion.property()
|
|
19
|
+
public body?: string;
|
|
20
|
+
|
|
21
|
+
@ComponentVersion.property()
|
|
22
|
+
public description?: string;
|
|
23
|
+
|
|
24
|
+
@ComponentVersion.property()
|
|
25
|
+
public isClassBased?: boolean;
|
|
26
|
+
|
|
27
|
+
@ComponentVersion.property({type: 'Component'})
|
|
28
|
+
public component?: Component;
|
|
29
|
+
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Merchi } from '../merchi';
|
|
2
|
+
|
|
3
|
+
test('can make CountryTax', () => {
|
|
4
|
+
const merchi = new Merchi();
|
|
5
|
+
const countryTax = new merchi.CountryTax();
|
|
6
|
+
expect(countryTax).toBeTruthy();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test('getNoTax', () => {
|
|
10
|
+
const merchi = new Merchi();
|
|
11
|
+
const noTax = merchi.CountryTax.getNoTax();
|
|
12
|
+
expect(noTax.id).toBe(3);
|
|
13
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Company } from './company';
|
|
2
|
+
import { Entity } from '../entity';
|
|
3
|
+
import { Item } from './item';
|
|
4
|
+
import { Job } from './job';
|
|
5
|
+
import { Shipment } from './shipment';
|
|
6
|
+
|
|
7
|
+
export class CountryTax extends Entity {
|
|
8
|
+
protected static resourceName = 'country_taxes';
|
|
9
|
+
protected static singularName = 'countryTax';
|
|
10
|
+
protected static pluralName = 'countryTaxes';
|
|
11
|
+
|
|
12
|
+
@CountryTax.property({type: Date})
|
|
13
|
+
public archived?: Date | null;
|
|
14
|
+
|
|
15
|
+
@CountryTax.property()
|
|
16
|
+
public id?: number;
|
|
17
|
+
|
|
18
|
+
@CountryTax.property({type: String})
|
|
19
|
+
public country?: string | null;
|
|
20
|
+
|
|
21
|
+
@CountryTax.property()
|
|
22
|
+
public taxName?: string;
|
|
23
|
+
|
|
24
|
+
@CountryTax.property({type: Number})
|
|
25
|
+
public taxPercent?: number | null;
|
|
26
|
+
|
|
27
|
+
@CountryTax.property({arrayType: 'Shipment'})
|
|
28
|
+
public shipments?: Shipment[];
|
|
29
|
+
|
|
30
|
+
@CountryTax.property({type: 'Company'})
|
|
31
|
+
public company?: Company;
|
|
32
|
+
|
|
33
|
+
@CountryTax.property({arrayType: 'Job'})
|
|
34
|
+
public jobs?: Job[];
|
|
35
|
+
|
|
36
|
+
@CountryTax.property({arrayType: 'Item'})
|
|
37
|
+
public items?: Item[];
|
|
38
|
+
|
|
39
|
+
public static getNoTax() {
|
|
40
|
+
const result = new this.merchi.CountryTax();
|
|
41
|
+
result.id = 3; // 3 is a reserved id for 'no tax' by the backend
|
|
42
|
+
result.taxName = 'No tax';
|
|
43
|
+
result.taxPercent = 0;
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Merchi } from '../merchi';
|
|
2
|
+
|
|
3
|
+
test('can make Discount', () => {
|
|
4
|
+
const merchi = new Merchi();
|
|
5
|
+
const discount = new merchi.Discount();
|
|
6
|
+
expect(discount).toBeTruthy();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test('discountedUnitCost', () => {
|
|
10
|
+
const merchi = new Merchi();
|
|
11
|
+
const discount = new merchi.Discount();
|
|
12
|
+
const product = new merchi.Product();
|
|
13
|
+
expect(() => discount.discountedUnitCost(product.unitPrice)).toThrow();
|
|
14
|
+
product.unitPrice = 200.8;
|
|
15
|
+
expect(() => discount.discountedUnitCost(product.unitPrice)).toThrow();
|
|
16
|
+
discount.amount = 94.6;
|
|
17
|
+
expect(discount.discountedUnitCost(product.unitPrice)).toEqual('10.843');
|
|
18
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Entity } from '../entity';
|
|
2
|
+
import { DiscountGroup } from './discount_group';
|
|
3
|
+
|
|
4
|
+
export class Discount extends Entity {
|
|
5
|
+
protected static resourceName = 'discounts';
|
|
6
|
+
protected static singularName = 'discount';
|
|
7
|
+
protected static pluralName = 'discounts';
|
|
8
|
+
|
|
9
|
+
@Discount.property({type: Date})
|
|
10
|
+
public archived?: Date | null;
|
|
11
|
+
|
|
12
|
+
@Discount.property()
|
|
13
|
+
public id?: number;
|
|
14
|
+
|
|
15
|
+
@Discount.property()
|
|
16
|
+
public lowerLimit?: number;
|
|
17
|
+
|
|
18
|
+
@Discount.property()
|
|
19
|
+
public amount?: number;
|
|
20
|
+
|
|
21
|
+
@Discount.property({type: DiscountGroup})
|
|
22
|
+
public discountGroup?: DiscountGroup | null;
|
|
23
|
+
|
|
24
|
+
public discountedUnitCost = (unitPrice: number | undefined) => {
|
|
25
|
+
if (unitPrice === undefined) {
|
|
26
|
+
throw 'unitPrice is undefined, did you forget to embed it?';
|
|
27
|
+
}
|
|
28
|
+
if (this.amount === undefined) {
|
|
29
|
+
throw 'amount is undefined, did you forget to embed it?';
|
|
30
|
+
}
|
|
31
|
+
const discount = 100 - this.amount;
|
|
32
|
+
return (unitPrice * discount / 100).toFixed(3);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Entity } from '../entity';
|
|
2
|
+
import { Product } from './product';
|
|
3
|
+
import { Discount } from './discount';
|
|
4
|
+
|
|
5
|
+
export class DiscountGroup extends Entity {
|
|
6
|
+
protected static resourceName = 'discount_groups';
|
|
7
|
+
protected static singularName = 'discountGroup';
|
|
8
|
+
protected static pluralName = 'discountGroups';
|
|
9
|
+
|
|
10
|
+
@DiscountGroup.property({type: Date})
|
|
11
|
+
public archived?: Date | null;
|
|
12
|
+
|
|
13
|
+
@DiscountGroup.property()
|
|
14
|
+
public id?: number;
|
|
15
|
+
|
|
16
|
+
@DiscountGroup.property()
|
|
17
|
+
public discountType?: number;
|
|
18
|
+
|
|
19
|
+
@DiscountGroup.property({arrayType: 'Discount'})
|
|
20
|
+
public discounts?: Discount[];
|
|
21
|
+
|
|
22
|
+
@DiscountGroup.property()
|
|
23
|
+
public name?: string;
|
|
24
|
+
|
|
25
|
+
@DiscountGroup.property({type: 'Product'})
|
|
26
|
+
public product?: Product | null;
|
|
27
|
+
|
|
28
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Merchi } from '../merchi';
|
|
2
|
+
import { setup, mockFetch } from '../test_util';
|
|
3
|
+
|
|
4
|
+
setup();
|
|
5
|
+
|
|
6
|
+
test('can make domain', () => {
|
|
7
|
+
const merchi = new Merchi();
|
|
8
|
+
const domain = new merchi.Domain();
|
|
9
|
+
expect(domain).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('can get and set id', () => {
|
|
13
|
+
const merchi = new Merchi();
|
|
14
|
+
const domain = new merchi.Domain();
|
|
15
|
+
domain.id = 2;
|
|
16
|
+
expect(domain.id).toBe(2);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('can get and set domain', () => {
|
|
20
|
+
const merchi = new Merchi();
|
|
21
|
+
const domain = new merchi.Domain();
|
|
22
|
+
domain.domain = 'example.com';
|
|
23
|
+
expect(domain.domain).toBe('example.com');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('can create domain on server', () => {
|
|
27
|
+
const merchi = new Merchi();
|
|
28
|
+
const domain = new merchi.Domain();
|
|
29
|
+
domain.domain = 'example.com';
|
|
30
|
+
const data = Array.from((domain.toFormData() as any).entries());
|
|
31
|
+
const fetch = mockFetch(true, {}, 201);
|
|
32
|
+
domain.create();
|
|
33
|
+
const sentToServer = Array.from(fetch.mock.calls[0][1]['body'].entries());
|
|
34
|
+
expect(sentToServer).toEqual(data);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('can delete domain', () => {
|
|
38
|
+
const merchi = new Merchi();
|
|
39
|
+
const domain = new merchi.Domain();
|
|
40
|
+
domain.id = 1;
|
|
41
|
+
const fetch = mockFetch(true, {}, 204);
|
|
42
|
+
domain.delete();
|
|
43
|
+
expect(fetch.mock.calls[0][1].method).toBe('DELETE');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('taxType', () => {
|
|
47
|
+
const merchi = new Merchi();
|
|
48
|
+
const domain = new merchi.Domain();
|
|
49
|
+
expect(domain.defaultTaxType).toThrow();
|
|
50
|
+
domain.company = new merchi.Company();
|
|
51
|
+
expect(domain.defaultTaxType).toThrow();
|
|
52
|
+
const tax = new merchi.CountryTax();
|
|
53
|
+
domain.company.defaultTaxType = tax;
|
|
54
|
+
expect(domain.defaultTaxType()).toBe(tax);
|
|
55
|
+
domain.company.defaultTaxType = null;
|
|
56
|
+
expect(domain.defaultTaxType()).toBe(null);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('can get domain active theme', () => {
|
|
60
|
+
const merchi = new Merchi();
|
|
61
|
+
const domain = new merchi.Domain();
|
|
62
|
+
|
|
63
|
+
// throw error if active theme is undefined which seems to be an embed issue
|
|
64
|
+
expect(() => {domain.getActiveTheme();}).toThrow(Error);
|
|
65
|
+
|
|
66
|
+
const theme = new merchi.Theme();
|
|
67
|
+
domain.activeTheme = theme;
|
|
68
|
+
expect(domain.getActiveTheme()).toEqual(theme);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('fail to delete non-existant domain', () => {
|
|
72
|
+
const merchi = new Merchi('YrDwzmh8&QGtAfg9quh(4QfSlE^RPXWl');
|
|
73
|
+
const domain = new merchi.Domain();
|
|
74
|
+
domain.id = -1;
|
|
75
|
+
const fetch = mockFetch(true, {statusCode: 404}, 404);
|
|
76
|
+
const invocation = domain.delete();
|
|
77
|
+
expect(fetch.mock.calls[0][1].method).toBe('DELETE');
|
|
78
|
+
return invocation.catch(e => expect(e.statusCode).toEqual(404));
|
|
79
|
+
});
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { Cart } from './cart';
|
|
2
|
+
import { Category } from './category';
|
|
3
|
+
import { Company } from './company';
|
|
4
|
+
import { DomainInvitation } from './domain_invitation';
|
|
5
|
+
import { DomainTag } from './domain_tag';
|
|
6
|
+
import { EnrolledDomain } from './enrolled_domain';
|
|
7
|
+
import { Entity } from '../entity';
|
|
8
|
+
import { MerchiFile } from './file';
|
|
9
|
+
import { InternalTag } from './internal_tag';
|
|
10
|
+
import { Invoice } from './invoice';
|
|
11
|
+
import { Job } from './job';
|
|
12
|
+
import { Menu } from './menu';
|
|
13
|
+
import { User } from './user';
|
|
14
|
+
import { Notification } from './notification';
|
|
15
|
+
import { Product } from './product';
|
|
16
|
+
import { Session } from './session';
|
|
17
|
+
import { SupplyDomain } from './supply_domain';
|
|
18
|
+
import { SeoDomainPage } from './seo_domain_page';
|
|
19
|
+
import { Theme } from './theme';
|
|
20
|
+
import { DomainType } from '../constants/domain_types';
|
|
21
|
+
|
|
22
|
+
export class Domain extends Entity {
|
|
23
|
+
protected static resourceName = 'domains';
|
|
24
|
+
protected static singularName = 'domain';
|
|
25
|
+
protected static pluralName = 'domains';
|
|
26
|
+
|
|
27
|
+
@Domain.property({type: Date})
|
|
28
|
+
public archived?: Date | null;
|
|
29
|
+
|
|
30
|
+
@Domain.property()
|
|
31
|
+
public id?: number;
|
|
32
|
+
|
|
33
|
+
@Domain.property()
|
|
34
|
+
public domain?: string;
|
|
35
|
+
|
|
36
|
+
@Domain.property()
|
|
37
|
+
public country?: string;
|
|
38
|
+
|
|
39
|
+
@Domain.property()
|
|
40
|
+
public currency?: string;
|
|
41
|
+
|
|
42
|
+
@Domain.property()
|
|
43
|
+
public callToActions?: string;
|
|
44
|
+
|
|
45
|
+
@Domain.property()
|
|
46
|
+
public callToActionDetails?: any[];
|
|
47
|
+
|
|
48
|
+
@Domain.property()
|
|
49
|
+
public isMaster?: boolean;
|
|
50
|
+
|
|
51
|
+
@Domain.property()
|
|
52
|
+
public internalUseNotes?: string;
|
|
53
|
+
|
|
54
|
+
@Domain.property()
|
|
55
|
+
public internalUseAiContext?: string;
|
|
56
|
+
|
|
57
|
+
@Domain.property()
|
|
58
|
+
public aiContext?: string;
|
|
59
|
+
|
|
60
|
+
@Domain.property()
|
|
61
|
+
public domainType?: DomainType;
|
|
62
|
+
|
|
63
|
+
@Domain.property()
|
|
64
|
+
public subDomain?: string;
|
|
65
|
+
|
|
66
|
+
@Domain.property()
|
|
67
|
+
public emailDomain?: string;
|
|
68
|
+
|
|
69
|
+
@Domain.property()
|
|
70
|
+
public smsName?: string;
|
|
71
|
+
|
|
72
|
+
@Domain.property()
|
|
73
|
+
public showDomainPublicly?: boolean;
|
|
74
|
+
|
|
75
|
+
@Domain.property()
|
|
76
|
+
public publicAccessRestricted?: boolean;
|
|
77
|
+
|
|
78
|
+
@Domain.property()
|
|
79
|
+
public showDomainToAccessibleEntitiesOnly?: boolean;
|
|
80
|
+
|
|
81
|
+
@Domain.property()
|
|
82
|
+
public enableEmailNotifications?: boolean;
|
|
83
|
+
|
|
84
|
+
@Domain.property()
|
|
85
|
+
public enableSmsNotifications?: boolean;
|
|
86
|
+
|
|
87
|
+
@Domain.property()
|
|
88
|
+
public mailgunRecords?: any[];
|
|
89
|
+
|
|
90
|
+
@Domain.property()
|
|
91
|
+
public enableNotifications?: boolean;
|
|
92
|
+
|
|
93
|
+
@Domain.property({type: String})
|
|
94
|
+
public trackingCodeGoogleConversion?: string | null;
|
|
95
|
+
|
|
96
|
+
@Domain.property({type: String})
|
|
97
|
+
public trackingCodeGoogleGlobal?: string | null;
|
|
98
|
+
|
|
99
|
+
@Domain.property({type: String})
|
|
100
|
+
public apiSecret?: string | null;
|
|
101
|
+
|
|
102
|
+
@Domain.property({type: String})
|
|
103
|
+
public webflowApiKey?: string | null;
|
|
104
|
+
|
|
105
|
+
@Domain.property({type: String})
|
|
106
|
+
public shopifyShopUrl?: string | null;
|
|
107
|
+
|
|
108
|
+
@Domain.property()
|
|
109
|
+
public shopifyIsActive?: boolean;
|
|
110
|
+
|
|
111
|
+
@Domain.property({type: String})
|
|
112
|
+
public qrShopQrCode?: string | null;
|
|
113
|
+
|
|
114
|
+
@Domain.property({type: String})
|
|
115
|
+
public unltdAiApiOrganizationId?: string;
|
|
116
|
+
|
|
117
|
+
@Domain.property({type: String})
|
|
118
|
+
public unltdAiApiSecretKey?: string;
|
|
119
|
+
|
|
120
|
+
@Domain.property({type: String})
|
|
121
|
+
public socialBitchute?: string | null;
|
|
122
|
+
|
|
123
|
+
@Domain.property({type: String})
|
|
124
|
+
public socialDiscord?: string | null;
|
|
125
|
+
|
|
126
|
+
@Domain.property({type: String})
|
|
127
|
+
public socialFacebook?: string | null;
|
|
128
|
+
|
|
129
|
+
@Domain.property({type: String})
|
|
130
|
+
public socialGoogle?: string | null;
|
|
131
|
+
|
|
132
|
+
@Domain.property({type: String})
|
|
133
|
+
public socialInstagram?: string | null;
|
|
134
|
+
|
|
135
|
+
@Domain.property({type: String})
|
|
136
|
+
public socialLinkedin?: string | null;
|
|
137
|
+
|
|
138
|
+
@Domain.property({type: String})
|
|
139
|
+
public socialRumble?: string | null;
|
|
140
|
+
|
|
141
|
+
@Domain.property({type: String})
|
|
142
|
+
public socialTelegram?: string | null;
|
|
143
|
+
|
|
144
|
+
@Domain.property({type: String})
|
|
145
|
+
public socialTiktok?: string | null;
|
|
146
|
+
|
|
147
|
+
@Domain.property({type: String})
|
|
148
|
+
public socialX?: string | null;
|
|
149
|
+
|
|
150
|
+
@Domain.property({type: String})
|
|
151
|
+
public socialYoutube?: string | null;
|
|
152
|
+
|
|
153
|
+
@Domain.property()
|
|
154
|
+
public ownedBy?: Company;
|
|
155
|
+
|
|
156
|
+
@Domain.property()
|
|
157
|
+
public company?: Company;
|
|
158
|
+
|
|
159
|
+
@Domain.property({type: MerchiFile})
|
|
160
|
+
public logo?: MerchiFile | null;
|
|
161
|
+
|
|
162
|
+
@Domain.property({type: MerchiFile})
|
|
163
|
+
public favicon?: MerchiFile | null;
|
|
164
|
+
|
|
165
|
+
@Domain.property()
|
|
166
|
+
public activeTheme?: Theme;
|
|
167
|
+
|
|
168
|
+
@Domain.property({arrayType: 'InternalTag'})
|
|
169
|
+
public internalTags?: InternalTag[];
|
|
170
|
+
|
|
171
|
+
@Domain.property({arrayType: 'DomainTag'})
|
|
172
|
+
public tags?: DomainTag[];
|
|
173
|
+
|
|
174
|
+
@Domain.property({arrayType: 'Domain'})
|
|
175
|
+
public canSupply?: Domain[];
|
|
176
|
+
|
|
177
|
+
@Domain.property({arrayType: 'Domain'})
|
|
178
|
+
public suppliedBy?: Domain[];
|
|
179
|
+
|
|
180
|
+
@Domain.property({arrayType: 'User'})
|
|
181
|
+
public accessibleClients?: User[];
|
|
182
|
+
|
|
183
|
+
@Domain.property({arrayType: 'Company'})
|
|
184
|
+
public accessibleClientCompanies?: Company[];
|
|
185
|
+
|
|
186
|
+
@Domain.property({arrayType: 'Menu'})
|
|
187
|
+
public menus?: Menu[];
|
|
188
|
+
|
|
189
|
+
@Domain.property({arrayType: 'Session'})
|
|
190
|
+
public sessions?: Session[];
|
|
191
|
+
|
|
192
|
+
@Domain.property({arrayType: 'Category'})
|
|
193
|
+
public categories?: Category[];
|
|
194
|
+
|
|
195
|
+
@Domain.property({arrayType: 'Notification'})
|
|
196
|
+
public notifications?: Notification[];
|
|
197
|
+
|
|
198
|
+
@Domain.property({arrayType: 'Product'})
|
|
199
|
+
public products?: Product[];
|
|
200
|
+
|
|
201
|
+
@Domain.property({arrayType: 'SupplyDomain'})
|
|
202
|
+
public supplyProducts?: SupplyDomain[];
|
|
203
|
+
|
|
204
|
+
@Domain.property({arrayType: 'Job'})
|
|
205
|
+
public jobs?: Job[];
|
|
206
|
+
|
|
207
|
+
@Domain.property({arrayType: 'User'})
|
|
208
|
+
public jobsAssignees?: User[];
|
|
209
|
+
|
|
210
|
+
@Domain.property({arrayType: 'Cart'})
|
|
211
|
+
public carts?: Cart[];
|
|
212
|
+
|
|
213
|
+
@Domain.property({arrayType: 'EnrolledDomain'})
|
|
214
|
+
public enrollments?: EnrolledDomain[];
|
|
215
|
+
|
|
216
|
+
@Domain.property({arrayType: 'Invoice'})
|
|
217
|
+
public invoices?: Invoice[];
|
|
218
|
+
|
|
219
|
+
@Domain.property({arrayType: 'DomainInvitation'})
|
|
220
|
+
public domainInvitations?: DomainInvitation[];
|
|
221
|
+
|
|
222
|
+
@Domain.property({arrayType: 'SeoDomainPage'})
|
|
223
|
+
public seoDomainPages?: SeoDomainPage[];
|
|
224
|
+
|
|
225
|
+
@Domain.property({arrayType: 'Theme'})
|
|
226
|
+
public themes?: Theme[];
|
|
227
|
+
|
|
228
|
+
public defaultTaxType = () => {
|
|
229
|
+
if (this.company === undefined) {
|
|
230
|
+
throw new Error('company is undefined, did you forget to embed it?');
|
|
231
|
+
}
|
|
232
|
+
if (this.company.defaultTaxType === undefined) {
|
|
233
|
+
const err = 'company.defaultTaxType is undefined, did you forget to' +
|
|
234
|
+
' embed it?';
|
|
235
|
+
throw new Error(err);
|
|
236
|
+
}
|
|
237
|
+
return this.company.defaultTaxType;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
public getActiveTheme = (): Theme => {
|
|
241
|
+
if (this.activeTheme === undefined) {
|
|
242
|
+
throw new Error('activeTheme is undefined, did you forget to embed it?');
|
|
243
|
+
}
|
|
244
|
+
return this.activeTheme!;
|
|
245
|
+
};
|
|
246
|
+
}
|