Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: release #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cfg/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
"fullName": "io.restorecommerce.setting.SettingService",
"address": "localhost:50053"
},
"currency": {
"fullName": "io.restorecommerce.currency.CurrencyService",
"address": "localhost:50053"
},
"fulfillment_courier": {
"fullName": "io.restorecommerce.fulfillment_courierFulfillmentCourierService",
"address": "localhost:50067",
Expand Down
4 changes: 4 additions & 0 deletions cfg/config_production.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
"fullName": "io.restorecommerce.setting.SettingService",
"address": "resource-srv:50051"
},
"currency": {
"fullName": "io.restorecommerce.currency.CurrencyService",
"address": "resource-srv:50051"
},
"fulfillment_courier": {
"fullName": "io.restorecommerce.fulfillment_courierFulfillmentCourierService",
"address": "fulfillment-srv:50051",
Expand Down
13 changes: 13 additions & 0 deletions cfg/config_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@
]
}
}
},
"currency": {
"address": "localhost:50179",
"mock": {
"protoPath": "io/restorecommerce/currency.proto",
"packageName": "io.restorecommerce.currency",
"serviceName": "CurrencyService",
"protoLoadOptions": {
"includeDirs": [
"node_modules/@restorecommerce/protos/"
]
}
}
}
}
}
28 changes: 6 additions & 22 deletions src/services/invoice_srv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ import {
type AggregatedInvoiceList,
type ResolvedSetting,
DefaultSetting,
resolveInvoice,
parseSetting,
marshallProtobufAny,
packRenderData,
} from '../utils.js';


Expand Down Expand Up @@ -442,7 +442,7 @@ export class InvoiceService
};
}

protected async resolveProductBundles(
protected async aggregateProductBundles(
products: ResourceMap<Product>,
output?: ResourceMap<Product>,
): Promise<ResourceMap<Product>> {
Expand All @@ -465,7 +465,7 @@ export class InvoiceService
p => output.set(p.id, p)
);

await this.resolveProductBundles(
await this.aggregateProductBundles(
bundled_products,
output,
);
Expand Down Expand Up @@ -758,7 +758,7 @@ export class InvoiceService
context,
).then(
async aggregation => {
aggregation.products = await this.resolveProductBundles(
aggregation.products = await this.aggregateProductBundles(
aggregation.products
);
return aggregation;
Expand Down Expand Up @@ -928,22 +928,6 @@ export class InvoiceService
return aggregation;
}

protected packRenderData (
aggregation: AggregatedInvoiceList,
invoice: Invoice,
) {
const resolved = {
invoice: resolveInvoice(
aggregation,
invoice
),
statics: {},
l10n: {},
};
const buffer = marshallProtobufAny(resolved);
return buffer;
}

protected async loadDefaultTemplates(subject?: Subject, context?: CallContext) {
if(this.default_templates.length) {
return this.default_templates;
Expand All @@ -962,7 +946,7 @@ export class InvoiceService
this.default_templates.forEach(
template => Object.assign(
template,
resp_map.get(template.id, null) // null for ignore missing
resp_map.get(template.id, null)
)
)
}
Expand Down Expand Up @@ -1108,7 +1092,7 @@ export class InvoiceService
const payloads: Payload[] = templates.map(
(template, i) => ({
content_type: 'text/html',
data: this.packRenderData(
data: packRenderData(
aggregation,
item,
),
Expand Down
70 changes: 53 additions & 17 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,19 @@ import {
import {
Setting,
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/setting.js';
import {
Any
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/google/protobuf/any.js';
import {
Payload_Strategy
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rendering.js';
import {
type Aggregation,
resolve,
Resolver,
ArrayResolver,
ResourceMap,
} from './experimental/ResourceAggregator.js';
import { Any } from '@restorecommerce/rc-grpc-clients/dist/generated-server/google/protobuf/any.js';
import { Payload_Strategy } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rendering.js';

export const DefaultUrns = {
shop_default_bucket: 'urn:restorecommerce:shop:setting:invoice:bucket:default', // [string]: overrides default bucket for file storage - default: cfg -> 'invoice'
Expand Down Expand Up @@ -143,13 +147,13 @@ const SettingParser: { [key: string]: (value: string) => any } = {
shop_pdf_bucket_options: JSON.parse,
shop_pdf_render_options: JSON.parse,
shop_puppeteer_options: JSON.parse,
shop_email_render_options: JSON.parse,
shop_invoice_number_start: Number.parseInt,
shop_invoice_number_increment: Number.parseInt,
shop_email_render_options: JSON.parse,
shop_locales: parseList,
customer_locales: parseList,
shop_email_cc: parseList,
shop_email_bcc: parseList,
customer_locales: parseList,
customer_email_cc: parseList,
customer_email_bcc: parseList,
};
Expand Down Expand Up @@ -198,8 +202,15 @@ export type InvoiceNumber = {
invoice_number?: string;
};

const mergeProductVariantRecursive = (nature: ProductNature, variant_id: string): ProductVariant => {
const variant = nature?.variants?.find(v => v.id === variant_id);
const mergeProductVariantRecursive = (
nature: ProductNature,
variant_id: string
): ProductVariant => {
const variant = nature?.templates?.find(
v => v.id === variant_id
) ?? nature?.variants?.find(
v => v.id === variant_id
);
if (variant?.parent_variant_id) {
const template = mergeProductVariantRecursive(
nature, variant.parent_variant_id
Expand All @@ -214,12 +225,20 @@ const mergeProductVariantRecursive = (nature: ProductNature, variant_id: string)
}
};

const mergeProductVariant = (product: IndividualProduct, variant_id: string): ProductVariant => {
const nature = product.physical ?? product.virtual ?? product.service;
const mergeProductVariant = (
product: IndividualProduct,
variant_id: string
): IndividualProduct => {
const key = Object.keys(product).find(
key => ['physical', 'virtual', 'service'].includes(key)
) as 'physical' | 'virtual' | 'service';
const nature = product[key];
const variant = mergeProductVariantRecursive(nature, variant_id);
return {
...product,
...variant
[key]: {
variants: [variant]
}
}
};

Expand Down Expand Up @@ -284,12 +303,12 @@ export const resolveInvoice = (
const tax_resolver = Resolver('tax_id', aggregation.taxes, {
type: Resolver('type_id', aggregation.tax_types),
});
const amount_resolver = [{
const amount_resolver = {
currency: currency_resolver,
vats: [{
tax: tax_resolver
}]
}];
};
const fulfillment_product_resolver = {
product: Resolver(
'product_id',
Expand All @@ -309,7 +328,7 @@ export const resolveInvoice = (
currency: currency_resolver,
}
}],
amounts: amount_resolver,
amounts: [amount_resolver],
}];

const resolved = resolve(
Expand All @@ -335,10 +354,13 @@ export const resolveInvoice = (
(position: typeof section.positions[0]) => {
const product = position.product_item?.product;
if (product?.product) {
product.product = mergeProductVariant(
product.product,
position.product_item.variant_id
);
position.product_item.product = {
...product,
product: mergeProductVariant(
product.product,
position.product_item.variant_id
)
};
}
}
)
Expand All @@ -360,4 +382,18 @@ export const marshallProtobufAny = (

export const unmarshallProtobufAny = (payload: Any): any => JSON.parse(
payload.value!.toString()
);
);

export const packRenderData = (
aggregation: AggregatedInvoiceList,
invoice: Invoice,
) => {
const resolved = {
invoice: resolveInvoice(
aggregation,
invoice
),
};
const buffer = marshallProtobufAny(resolved);
return buffer;
};
Loading
Loading