Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Companies and tax exemptions, Phase 9: regenerate the typed clients for the company surface

Łukasz Adamczykbe68a1cca613
diff --git a/packages/admin-sdk/src/types/generated/Company.ts b/packages/admin-sdk/src/types/generated/Company.ts
new file mode 100644
index 0000000000..5727206c60
--- /dev/null
+++ b/packages/admin-sdk/src/types/generated/Company.ts
@@ -0,0 +1,17 @@
+// Typelizer digest 3126522f6a67e0ca1b34d6662b3d0344
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+import type {CompanyLocation} from '@/types'
+
+interface Company {
+ id: string;
+ name: string;
+ external_id: string | null;
+ metadata: Record<string, unknown> | null;
+ created_at: string;
+ updated_at: string;
+ locations_count: number;
+ company_locations?: Array<CompanyLocation>;
+}
+
+export default Company;
diff --git a/packages/admin-sdk/src/types/generated/CompanyContact.ts b/packages/admin-sdk/src/types/generated/CompanyContact.ts
new file mode 100644
index 0000000000..298a0e8db5
--- /dev/null
+++ b/packages/admin-sdk/src/types/generated/CompanyContact.ts
@@ -0,0 +1,15 @@
+// Typelizer digest 21499b2e7d67af35ef2e3f66c61331f6
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+
+interface CompanyContact {
+ id: string;
+ role: string;
+ created_at: string;
+ updated_at: string;
+ company_location_id: string;
+ customer_id: string;
+ email: string | null;
+}
+
+export default CompanyContact;
diff --git a/packages/admin-sdk/src/types/generated/CompanyLocation.ts b/packages/admin-sdk/src/types/generated/CompanyLocation.ts
new file mode 100644
index 0000000000..6f5c5feec8
--- /dev/null
+++ b/packages/admin-sdk/src/types/generated/CompanyLocation.ts
@@ -0,0 +1,20 @@
+// Typelizer digest 360e7f05e35ee3a3de470756f97e5d12
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+import type {Address, CompanyContact} from '@/types'
+
+interface CompanyLocation {
+ id: string;
+ name: string;
+ external_id: string | null;
+ metadata: Record<string, unknown> | null;
+ created_at: string;
+ updated_at: string;
+ company_id: string;
+ contacts_count: number;
+ billing_address: Address;
+ shipping_address: Address;
+ company_contacts?: Array<CompanyContact>;
+}
+
+export default CompanyLocation;
diff --git a/packages/admin-sdk/src/types/generated/TaxExemptionCertificate.ts b/packages/admin-sdk/src/types/generated/TaxExemptionCertificate.ts
new file mode 100644
index 0000000000..23adc5b874
--- /dev/null
+++ b/packages/admin-sdk/src/types/generated/TaxExemptionCertificate.ts
@@ -0,0 +1,28 @@
+// Typelizer digest 1ccbae6c1fb791309d0dc15575065d17
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+
+interface TaxExemptionCertificate {
+ id: string;
+ certificate_number: string;
+ reason_code: string;
+ status: string;
+ issuing_authority: string | null;
+ metadata: Record<string, unknown> | null;
+ issued_at: string;
+ expires_at: string;
+ verified_at: string;
+ created_at: string;
+ updated_at: string;
+ company_id: string;
+ country_iso: string | null;
+ state_code: string | null;
+ active: boolean;
+ lapsed: boolean;
+ can_be_deleted: boolean;
+ document_filename: string | null;
+ document_byte_size: number | null;
+ document_url: string | null;
+}
+
+export default TaxExemptionCertificate;
diff --git a/packages/admin-sdk/src/types/generated/index.ts b/packages/admin-sdk/src/types/generated/index.ts
index 9dd8844b80..a85077bf1b 100644
--- a/packages/admin-sdk/src/types/generated/index.ts
+++ b/packages/admin-sdk/src/types/generated/index.ts
@@ -1,4 +1,4 @@
-// Typelizer digest ded9d8df931d6bedc6e1e3790dc19fdb
+// Typelizer digest 44bba369cb8612b6bc47f1f2e86fc75a
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
export type { default as Address } from './Address'
@@ -14,6 +14,9 @@ export type { default as ClaimReason } from './ClaimReason'
export type { default as Claim } from './Claim'
export type { default as CollectionRule } from './CollectionRule'
export type { default as Collection } from './Collection'
+export type { default as CompanyContact } from './CompanyContact'
+export type { default as CompanyLocation } from './CompanyLocation'
+export type { default as Company } from './Company'
export type { default as Country } from './Country'
export type { default as CouponCode } from './CouponCode'
export type { default as CreditCard } from './CreditCard'
@@ -78,6 +81,7 @@ export type { default as StoreCreditCategory } from './StoreCreditCategory'
export type { default as StoreCredit } from './StoreCredit'
export type { default as Store } from './Store'
export type { default as TaxCategory } from './TaxCategory'
+export type { default as TaxExemptionCertificate } from './TaxExemptionCertificate'
export type { default as TaxIdentifier } from './TaxIdentifier'
export type { default as TaxLine } from './TaxLine'
export type { default as TaxRate } from './TaxRate'
diff --git a/packages/sdk/src/types/generated/Company.ts b/packages/sdk/src/types/generated/Company.ts
new file mode 100644
index 0000000000..4d672d5da5
--- /dev/null
+++ b/packages/sdk/src/types/generated/Company.ts
@@ -0,0 +1,11 @@
+// Typelizer digest 988862bf42811a399a2e37bb7f1a82da
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+
+interface Company {
+ id: string;
+ name: string;
+ external_id: string | null;
+}
+
+export default Company;
diff --git a/packages/sdk/src/types/generated/index.ts b/packages/sdk/src/types/generated/index.ts
index 59e8582fb7..8fa0c9517c 100644
--- a/packages/sdk/src/types/generated/index.ts
+++ b/packages/sdk/src/types/generated/index.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 633530336b8aac863cf9cdd6fd46b204
+// Typelizer digest 246bdc538eebd383fd43515435f9040b
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
export type { default as Address } from './Address'
@@ -10,6 +10,7 @@ export type { default as Channel } from './Channel'
export type { default as ClaimLineItem } from './ClaimLineItem'
export type { default as Claim } from './Claim'
export type { default as Collection } from './Collection'
+export type { default as Company } from './Company'
export type { default as Country } from './Country'
export type { default as CreditCard } from './CreditCard'
export type { default as Currency } from './Currency'
diff --git a/packages/sdk/src/zod/generated/Company.ts b/packages/sdk/src/zod/generated/Company.ts
new file mode 100644
index 0000000000..b0a4aae171
--- /dev/null
+++ b/packages/sdk/src/zod/generated/Company.ts
@@ -0,0 +1,10 @@
+// This file is auto-generated. Do not edit directly.
+import { z } from 'zod';
+
+export const CompanySchema = z.object({
+ id: z.string(),
+ name: z.string(),
+ external_id: z.string().nullable(),
+});
+
+export type Company = z.infer<typeof CompanySchema>;
diff --git a/packages/sdk/src/zod/generated/index.ts b/packages/sdk/src/zod/generated/index.ts
index b0df2177c6..94f67ddbf8 100644
--- a/packages/sdk/src/zod/generated/index.ts
+++ b/packages/sdk/src/zod/generated/index.ts
@@ -8,6 +8,7 @@ export { ChannelSchema, type Channel } from './Channel';
export { ClaimSchema, type Claim } from './Claim';
export { ClaimLineItemSchema, type ClaimLineItem } from './ClaimLineItem';
export { CollectionSchema, type Collection } from './Collection';
+export { CompanySchema, type Company } from './Company';
export { CountrySchema, type Country } from './Country';
export { CreditCardSchema, type CreditCard } from './CreditCard';
export { CurrencySchema, type Currency } from './Currency';
diff --git a/spree/api/app/serializers/spree/api/v3/admin/company_location_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/company_location_serializer.rb
index cb51f26b62..37f396f717 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/company_location_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/company_location_serializer.rb
@@ -23,8 +23,8 @@ module Spree
location.company_contacts.size
end
- one :billing_address, resource: proc { Spree.api.address_serializer }
- one :shipping_address, resource: proc { Spree.api.address_serializer }
+ one :billing_address, resource: proc { Spree.api.admin_address_serializer }
+ one :shipping_address, resource: proc { Spree.api.admin_address_serializer }
many :company_contacts,
resource: proc { Spree.api.admin_company_contact_serializer },
diff --git a/spree/api/spec/integration/spree/api/v3/admin/companies_spec.rb b/spree/api/spec/integration/spree/api/v3/admin/companies_spec.rb
new file mode 100644
index 0000000000..647b60455f
--- /dev/null
+++ b/spree/api/spec/integration/spree/api/v3/admin/companies_spec.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+require 'swagger_helper'
+
+RSpec.describe 'Admin Companies API', type: :request, swagger_doc: 'api-reference/admin.yaml' do
+ include_context 'API v3 Admin'
+
+ let(:Authorization) { "Bearer #{admin_jwt_token}" }
+
+ let!(:company) { create(:company, store: store, name: 'Acme Industrial', external_id: 'ACME-1') }
+
+ path '/api/v3/admin/companies' do
+ get 'List companies' do
+ tags 'Companies'
+ produces 'application/json'
+ security [api_key: [], bearer_auth: []]
+ description 'Returns the business customers of the current store.'
+ admin_scope_note '`read_customers` — a company is a customer record.'
+
+ parameter name: 'x-spree-api-key', in: :header, type: :string, required: true
+ parameter name: :Authorization, in: :header, type: :string, required: true
+
+ response '200', 'companies found' do
+ let(:'x-spree-api-key') { secret_api_key.plaintext_token }
+
+ run_test! do |response|
+ data = JSON.parse(response.body)
+ expect(data['data'].pluck('id')).to include(company.prefixed_id)
+ end
+ end
+ end
+
+ post 'Create a company' do
+ tags 'Companies'
+ consumes 'application/json'
+ produces 'application/json'
+ security [api_key: [], bearer_auth: []]
+ description 'Creates a business customer. Exemption certificates and tax registrations hang off it.'
+ admin_scope_note '`write_customers`.'
+
+ parameter name: 'x-spree-api-key', in: :header, type: :string, required: true
+ parameter name: :Authorization, in: :header, type: :string, required: true
+ parameter name: :body, in: :body, schema: {
+ type: :object,
+ properties: {
+ name: { type: :string, example: 'Globex Corporation' },
+ external_id: { type: :string, nullable: true,
+ description: 'Your own reference for this business, unique within the store.',
+ example: 'GLBX-42' }
+ },
+ required: ['name']
+ }
+
+ let(:'x-spree-api-key') { secret_api_key.plaintext_token }
+
+ response '201', 'company created' do
+ let(:body) { { name: 'Globex Corporation', external_id: 'GLBX-42' } }
+
+ run_test! do |response|
+ expect(JSON.parse(response.body)['name']).to eq('Globex Corporation')
+ end
+ end
+
+ response '422', 'invalid request' do
+ let(:body) { { external_id: 'NO-NAME' } }
+
+ run_test!
+ end
+ end
+ end
+end