@chatarmin/os 0.3.3 → 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.
package/dist/index.d.ts CHANGED
@@ -31,6 +31,8 @@ export interface CreateCompanyInput {
31
31
  contactEmail?: string;
32
32
  /** Primary contact name */
33
33
  contactName?: string;
34
+ /** Optional: Set a historical created_at timestamp (ISO 8601 format) */
35
+ createdAt?: string;
34
36
  }
35
37
  /**
36
38
  * Input for smart linking a company.
@@ -164,6 +166,50 @@ export interface ApplyTierInput {
164
166
  /** Feature overrides (key: feature code, value: config overrides) */
165
167
  features?: Record<string, Record<string, unknown>>;
166
168
  }
169
+ /**
170
+ * Contact data for creating or updating a contact.
171
+ */
172
+ export interface ContactInput {
173
+ /** Contact email address (required, unique per company) */
174
+ email: string;
175
+ /** Contact name */
176
+ name?: string;
177
+ /** Contact role (e.g., "CEO", "Marketing Manager") */
178
+ role?: string;
179
+ /** Whether this is the primary contact */
180
+ isPrimary?: boolean;
181
+ /** Avatar URL */
182
+ avatarUrl?: string;
183
+ /** Additional metadata */
184
+ metadata?: Record<string, unknown>;
185
+ }
186
+ /**
187
+ * Result from creating a single contact.
188
+ */
189
+ export interface ContactResult {
190
+ id: string;
191
+ email: string;
192
+ name: string | null;
193
+ role: string | null;
194
+ is_primary: boolean;
195
+ avatar_url: string | null;
196
+ isNew: boolean;
197
+ }
198
+ /**
199
+ * Result from bulk contact upsert.
200
+ */
201
+ export interface BulkContactResult {
202
+ /** Number of contacts created */
203
+ created: number;
204
+ /** Number of contacts updated */
205
+ updated: number;
206
+ /** Individual contact results */
207
+ contacts: Array<{
208
+ email: string;
209
+ id: string;
210
+ isNew: boolean;
211
+ }>;
212
+ }
167
213
  /**
168
214
  * Input for the unified onboarding flow.
169
215
  */
@@ -210,6 +256,12 @@ export interface OnboardInput {
210
256
  contactEmail?: string;
211
257
  /** Primary contact name for new companies */
212
258
  contactName?: string;
259
+ /**
260
+ * Historical created_at timestamp for the company.
261
+ * Only used when creating new companies (not for existing matches).
262
+ * @example "2024-01-15T10:30:00.000Z"
263
+ */
264
+ createdAt?: string;
213
265
  }
214
266
  /**
215
267
  * Result from the onboarding flow.
@@ -236,6 +288,8 @@ export interface OnboardResult {
236
288
  linked?: boolean;
237
289
  /** True if tier features were applied */
238
290
  tierApplied?: boolean;
291
+ /** Error message if billing failed (company still linked) */
292
+ error?: string;
239
293
  };
240
294
  }
241
295
  /**
@@ -382,6 +436,28 @@ export declare class ChatarminOS {
382
436
  name: string;
383
437
  externalOrgId: string;
384
438
  }>;
439
+ /**
440
+ * Update company metadata.
441
+ *
442
+ * Used for backfilling data like historical created_at dates.
443
+ *
444
+ * @param input - Update parameters
445
+ * @returns Whether the update was applied
446
+ *
447
+ * @example
448
+ * ```typescript
449
+ * await os.companies.update({
450
+ * companyId: 'uuid-here',
451
+ * createdAt: '2023-01-15T10:30:00.000Z'
452
+ * })
453
+ * ```
454
+ */
455
+ update: (input: {
456
+ companyId: string;
457
+ createdAt?: string;
458
+ }) => Promise<{
459
+ updated: boolean;
460
+ }>;
385
461
  /**
386
462
  * Smart link - intelligently find and link a company using hints.
387
463
  *
@@ -420,6 +496,134 @@ export declare class ChatarminOS {
420
496
  */
421
497
  smartLink: (input: SmartLinkInput) => Promise<SmartLinkResult>;
422
498
  };
499
+ /**
500
+ * Contact management operations.
501
+ *
502
+ * Contacts are people associated with companies. Each contact has an email
503
+ * (unique per company), optional name and role, and one contact can be
504
+ * marked as primary.
505
+ *
506
+ * @example
507
+ * ```typescript
508
+ * // Create a single contact
509
+ * const contact = await os.contacts.create({
510
+ * companyId: company.id,
511
+ * email: 'john@acme.com',
512
+ * name: 'John Doe',
513
+ * role: 'CEO',
514
+ * isPrimary: true
515
+ * })
516
+ *
517
+ * // Bulk create/update contacts
518
+ * const result = await os.contacts.bulkUpsert({
519
+ * companyId: company.id,
520
+ * contacts: [
521
+ * { email: 'john@acme.com', name: 'John', role: 'CEO', isPrimary: true },
522
+ * { email: 'jane@acme.com', name: 'Jane', role: 'CTO' }
523
+ * ]
524
+ * })
525
+ * ```
526
+ */
527
+ get contacts(): {
528
+ /**
529
+ * Create or update a single contact for a company.
530
+ *
531
+ * If a contact with the same email exists, it will be updated.
532
+ * Otherwise, a new contact is created.
533
+ *
534
+ * @param input - Contact creation parameters
535
+ * @returns The created/updated contact
536
+ *
537
+ * @example
538
+ * ```typescript
539
+ * const contact = await os.contacts.create({
540
+ * companyId: 'comp_xxx',
541
+ * email: 'john@acme.com',
542
+ * name: 'John Doe',
543
+ * role: 'CEO',
544
+ * isPrimary: true
545
+ * })
546
+ *
547
+ * if (contact.isNew) {
548
+ * console.log('Created new contact')
549
+ * } else {
550
+ * console.log('Updated existing contact')
551
+ * }
552
+ * ```
553
+ */
554
+ create: (input: {
555
+ companyId: string;
556
+ } & ContactInput) => Promise<{
557
+ isNew: boolean;
558
+ name: string | null;
559
+ id: string;
560
+ metadata: unknown;
561
+ role: string | null;
562
+ email: string;
563
+ created_at: Date;
564
+ updated_at: Date;
565
+ company_id: string | null;
566
+ short_id: string | null;
567
+ is_primary: boolean;
568
+ avatar_url: string | null;
569
+ }>;
570
+ /**
571
+ * Bulk create or update multiple contacts for a company.
572
+ *
573
+ * This is the recommended way to sync contacts during onboarding.
574
+ * Existing contacts (matched by email) are updated, new ones are created.
575
+ *
576
+ * @param input - Bulk upsert parameters
577
+ * @returns Summary with created/updated counts
578
+ *
579
+ * @example
580
+ * ```typescript
581
+ * const result = await os.contacts.bulkUpsert({
582
+ * companyId: 'comp_xxx',
583
+ * contacts: [
584
+ * { email: 'ceo@acme.com', name: 'CEO', role: 'CEO', isPrimary: true },
585
+ * { email: 'cto@acme.com', name: 'CTO', role: 'CTO' },
586
+ * { email: 'dev@acme.com', name: 'Developer', role: 'Engineer' }
587
+ * ]
588
+ * })
589
+ *
590
+ * console.log(`Created: ${result.created}, Updated: ${result.updated}`)
591
+ * ```
592
+ */
593
+ bulkUpsert: (input: {
594
+ companyId: string;
595
+ contacts: ContactInput[];
596
+ }) => Promise<BulkContactResult>;
597
+ /**
598
+ * List all contacts for a company.
599
+ *
600
+ * @param companyId - Company ID to list contacts for
601
+ * @param primaryOnly - If true, only return the primary contact
602
+ * @returns Array of contacts
603
+ *
604
+ * @example
605
+ * ```typescript
606
+ * // Get all contacts
607
+ * const contacts = await os.contacts.list('comp_xxx')
608
+ *
609
+ * // Get only primary contact
610
+ * const primary = await os.contacts.list('comp_xxx', true)
611
+ * ```
612
+ */
613
+ list: (companyId: string, primaryOnly?: boolean) => Promise<{
614
+ name: string | null;
615
+ id: string;
616
+ metadata: unknown;
617
+ role: string | null;
618
+ email: string;
619
+ created_at: Date;
620
+ updated_at: Date;
621
+ company_id: string | null;
622
+ short_id: string | null;
623
+ is_primary: boolean;
624
+ avatar_url: string | null;
625
+ }[]>;
626
+ };
423
627
  /**
424
628
  * Feature access and entitlement operations.
425
629
  *
@@ -869,6 +1073,7 @@ export declare class ChatarminOS {
869
1073
  * const link = await os.links.create({
870
1074
  * companyId: 'comp_xxx',
871
1075
  * externalOrgId: 'org_abc123',
1076
+ * label: 'Store Vienna', // Optional: display label
872
1077
  * externalUserId: 'user_xyz' // Optional: user who created the link
873
1078
  * })
874
1079
  * ```
@@ -876,10 +1081,12 @@ export declare class ChatarminOS {
876
1081
  create: (input: {
877
1082
  companyId: string;
878
1083
  externalOrgId: string;
1084
+ label?: string;
879
1085
  externalUserId?: string;
880
1086
  }) => Promise<{
881
1087
  id: string;
882
1088
  metadata: unknown;
1089
+ label: string | null;
883
1090
  confidence: number | null;
884
1091
  created_at: Date;
885
1092
  updated_at: Date;
@@ -890,6 +1097,41 @@ export declare class ChatarminOS {
890
1097
  link_type: string;
891
1098
  sync_status: string;
892
1099
  } | undefined>;
1100
+ /**
1101
+ * Delete all product links for this product.
1102
+ *
1103
+ * Use this before re-importing to clean up old links.
1104
+ * This only affects links for YOUR product (identified by API key).
1105
+ *
1106
+ * **Options:**
1107
+ * - `deleteContacts`: Also delete contacts from linked companies
1108
+ * - `resetMrr`: Also reset MRR to 0 for linked companies
1109
+ *
1110
+ * @returns Counts of deleted/reset items
1111
+ *
1112
+ * @example Basic reset (links only)
1113
+ * ```typescript
1114
+ * const result = await os.links.reset()
1115
+ * console.log(`Deleted ${result.linksDeleted} links`)
1116
+ * ```
1117
+ *
1118
+ * @example Full reset (links + contacts + MRR)
1119
+ * ```typescript
1120
+ * const result = await os.links.reset({
1121
+ * deleteContacts: true,
1122
+ * resetMrr: true
1123
+ * })
1124
+ * console.log(`Deleted ${result.linksDeleted} links, ${result.contactsDeleted} contacts`)
1125
+ * ```
1126
+ */
1127
+ reset: (options?: {
1128
+ deleteContacts?: boolean;
1129
+ resetMrr?: boolean;
1130
+ }) => Promise<{
1131
+ linksDeleted: number;
1132
+ contactsDeleted: number;
1133
+ companiesMrrReset: number;
1134
+ }>;
893
1135
  };
894
1136
  /**
895
1137
  * Subscription and tier management.
@@ -978,8 +1220,8 @@ export declare class ChatarminOS {
978
1220
  name: string;
979
1221
  id: string;
980
1222
  metadata: unknown;
981
- code: string;
982
1223
  description: string | null;
1224
+ code: string;
983
1225
  is_active: boolean;
984
1226
  display_order: number;
985
1227
  created_at: Date;
@@ -1096,8 +1338,8 @@ export declare class ChatarminOS {
1096
1338
  name: string;
1097
1339
  id: string;
1098
1340
  metadata: unknown;
1099
- code: string;
1100
1341
  description: string | null;
1342
+ code: string;
1101
1343
  is_active: boolean;
1102
1344
  display_order: number;
1103
1345
  created_at: Date;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAQ/C;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC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AQD;;;;;;;;;;;;;;;;;;;;;;;;;;WA0BG;0BACe;YAAE,cAAc,CAAC,EAAE,OAAO,CAAC;YAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;;;;;MAGrE;IAMD;;;;;;;;;;;;;;;;;;;OAmBG;IACH,IAAI,aAAa;QAGb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA6BG;2BACgB,MAAM,WAAW,cAAc;;;;;QAOlD;;;;;;;;;;;;;;;;;;;WAmBG;;;;;;;;;;;;;;;;;;;;QAIH;;;;;;;;;;;;;;;;;;;;;;;WAuBG;4BACiB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAG7B;IAMD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,IAAI,KAAK;QAGL;;;;;;;;;;;WAWG;;;;;;;;;;;;;;;;;;;;QAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAsCG;wBACa,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAGtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA8BG;0BACe,MAAM,WAAW,cAAc;;;;;MAOpD;IAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuFG;IACG,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CAoF3D;AAGD,YAAY,EAAE,SAAS,EAAE,CAAA;AAGzB,eAAe,WAAW,CAAA"}
package/dist/index.js CHANGED
@@ -152,6 +152,23 @@ export class ChatarminOS {
152
152
  * ```
153
153
  */
154
154
  create: (input) => client.companies.createWithLink.mutate(input),
155
+ /**
156
+ * Update company metadata.
157
+ *
158
+ * Used for backfilling data like historical created_at dates.
159
+ *
160
+ * @param input - Update parameters
161
+ * @returns Whether the update was applied
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * await os.companies.update({
166
+ * companyId: 'uuid-here',
167
+ * createdAt: '2023-01-15T10:30:00.000Z'
168
+ * })
169
+ * ```
170
+ */
171
+ update: (input) => client.companies.updateCompany.mutate(input),
155
172
  /**
156
173
  * Smart link - intelligently find and link a company using hints.
157
174
  *
@@ -192,6 +209,110 @@ export class ChatarminOS {
192
209
  };
193
210
  }
194
211
  // ==========================================================================
212
+ // Contacts
213
+ // ==========================================================================
214
+ /**
215
+ * Contact management operations.
216
+ *
217
+ * Contacts are people associated with companies. Each contact has an email
218
+ * (unique per company), optional name and role, and one contact can be
219
+ * marked as primary.
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * // Create a single contact
224
+ * const contact = await os.contacts.create({
225
+ * companyId: company.id,
226
+ * email: 'john@acme.com',
227
+ * name: 'John Doe',
228
+ * role: 'CEO',
229
+ * isPrimary: true
230
+ * })
231
+ *
232
+ * // Bulk create/update contacts
233
+ * const result = await os.contacts.bulkUpsert({
234
+ * companyId: company.id,
235
+ * contacts: [
236
+ * { email: 'john@acme.com', name: 'John', role: 'CEO', isPrimary: true },
237
+ * { email: 'jane@acme.com', name: 'Jane', role: 'CTO' }
238
+ * ]
239
+ * })
240
+ * ```
241
+ */
242
+ get contacts() {
243
+ const client = this.client;
244
+ return {
245
+ /**
246
+ * Create or update a single contact for a company.
247
+ *
248
+ * If a contact with the same email exists, it will be updated.
249
+ * Otherwise, a new contact is created.
250
+ *
251
+ * @param input - Contact creation parameters
252
+ * @returns The created/updated contact
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * const contact = await os.contacts.create({
257
+ * companyId: 'comp_xxx',
258
+ * email: 'john@acme.com',
259
+ * name: 'John Doe',
260
+ * role: 'CEO',
261
+ * isPrimary: true
262
+ * })
263
+ *
264
+ * if (contact.isNew) {
265
+ * console.log('Created new contact')
266
+ * } else {
267
+ * console.log('Updated existing contact')
268
+ * }
269
+ * ```
270
+ */
271
+ create: (input) => client.contacts.createForCompany.mutate(input),
272
+ /**
273
+ * Bulk create or update multiple contacts for a company.
274
+ *
275
+ * This is the recommended way to sync contacts during onboarding.
276
+ * Existing contacts (matched by email) are updated, new ones are created.
277
+ *
278
+ * @param input - Bulk upsert parameters
279
+ * @returns Summary with created/updated counts
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * const result = await os.contacts.bulkUpsert({
284
+ * companyId: 'comp_xxx',
285
+ * contacts: [
286
+ * { email: 'ceo@acme.com', name: 'CEO', role: 'CEO', isPrimary: true },
287
+ * { email: 'cto@acme.com', name: 'CTO', role: 'CTO' },
288
+ * { email: 'dev@acme.com', name: 'Developer', role: 'Engineer' }
289
+ * ]
290
+ * })
291
+ *
292
+ * console.log(`Created: ${result.created}, Updated: ${result.updated}`)
293
+ * ```
294
+ */
295
+ bulkUpsert: (input) => client.contacts.bulkUpsert.mutate(input),
296
+ /**
297
+ * List all contacts for a company.
298
+ *
299
+ * @param companyId - Company ID to list contacts for
300
+ * @param primaryOnly - If true, only return the primary contact
301
+ * @returns Array of contacts
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * // Get all contacts
306
+ * const contacts = await os.contacts.list('comp_xxx')
307
+ *
308
+ * // Get only primary contact
309
+ * const primary = await os.contacts.list('comp_xxx', true)
310
+ * ```
311
+ */
312
+ list: (companyId, primaryOnly = false) => client.contacts.listForCompany.query({ companyId, primaryOnly }),
313
+ };
314
+ }
315
+ // ==========================================================================
195
316
  // Features
196
317
  // ==========================================================================
197
318
  /**
@@ -551,17 +672,45 @@ export class ChatarminOS {
551
672
  * const link = await os.links.create({
552
673
  * companyId: 'comp_xxx',
553
674
  * externalOrgId: 'org_abc123',
675
+ * label: 'Store Vienna', // Optional: display label
554
676
  * externalUserId: 'user_xyz' // Optional: user who created the link
555
677
  * })
556
678
  * ```
557
679
  */
558
- create: (input) => client.companies.linkToProduct.mutate({
559
- customerId: input.companyId,
560
- productCode: "", // Uses product from API key
680
+ create: (input) => client.companies.upsertProductLink.mutate({
681
+ companyId: input.companyId,
561
682
  externalOrgId: input.externalOrgId,
562
683
  externalUserId: input.externalUserId,
563
- linkType: "identified",
684
+ label: input.label,
564
685
  }),
686
+ /**
687
+ * Delete all product links for this product.
688
+ *
689
+ * Use this before re-importing to clean up old links.
690
+ * This only affects links for YOUR product (identified by API key).
691
+ *
692
+ * **Options:**
693
+ * - `deleteContacts`: Also delete contacts from linked companies
694
+ * - `resetMrr`: Also reset MRR to 0 for linked companies
695
+ *
696
+ * @returns Counts of deleted/reset items
697
+ *
698
+ * @example Basic reset (links only)
699
+ * ```typescript
700
+ * const result = await os.links.reset()
701
+ * console.log(`Deleted ${result.linksDeleted} links`)
702
+ * ```
703
+ *
704
+ * @example Full reset (links + contacts + MRR)
705
+ * ```typescript
706
+ * const result = await os.links.reset({
707
+ * deleteContacts: true,
708
+ * resetMrr: true
709
+ * })
710
+ * console.log(`Deleted ${result.linksDeleted} links, ${result.contactsDeleted} contacts`)
711
+ * ```
712
+ */
713
+ reset: (options) => client.companies.resetProductLinks.mutate(options),
565
714
  };
566
715
  }
567
716
  // ==========================================================================
@@ -912,43 +1061,54 @@ export class ChatarminOS {
912
1061
  externalOrgId: input.externalOrgId,
913
1062
  contactEmail: input.contactEmail,
914
1063
  contactName: input.contactName,
1064
+ createdAt: input.createdAt,
915
1065
  });
916
1066
  companyId = newCompany.id;
917
1067
  companyName = newCompany.name;
918
1068
  linkStatus = "created";
919
1069
  }
920
- // Step 2: Handle billing
1070
+ // Step 2: Handle billing (non-fatal - don't block company linking)
921
1071
  let billingStatus;
922
- if (input.checkoutSessionId) {
923
- // Claim subscription from checkout
924
- const claimResult = await this.billing.claimCheckout({
925
- companyId,
926
- checkoutSessionId: input.checkoutSessionId,
927
- });
928
- billingStatus = {
929
- subscriptionId: claimResult.subscriptionId,
930
- claimed: !claimResult.alreadyClaimed,
931
- };
932
- }
933
- else if (input.stripeSubscriptionId) {
934
- // Link existing subscription
935
- const linkResult = await this.billing.linkSubscription({
936
- companyId,
937
- stripeSubscriptionId: input.stripeSubscriptionId,
938
- stripeCustomerId: input.stripeCustomerId,
939
- tierCode: input.tierCode,
940
- });
941
- billingStatus = {
942
- subscriptionId: linkResult.subscriptionId,
943
- linked: !linkResult.alreadyLinked,
944
- tierApplied: linkResult.tierApplied,
945
- };
1072
+ try {
1073
+ if (input.checkoutSessionId) {
1074
+ // Claim subscription from checkout
1075
+ const claimResult = await this.billing.claimCheckout({
1076
+ companyId,
1077
+ checkoutSessionId: input.checkoutSessionId,
1078
+ });
1079
+ billingStatus = {
1080
+ subscriptionId: claimResult.subscriptionId,
1081
+ claimed: !claimResult.alreadyClaimed,
1082
+ };
1083
+ }
1084
+ else if (input.stripeSubscriptionId) {
1085
+ // Link existing subscription
1086
+ const linkResult = await this.billing.linkSubscription({
1087
+ companyId,
1088
+ stripeSubscriptionId: input.stripeSubscriptionId,
1089
+ stripeCustomerId: input.stripeCustomerId,
1090
+ tierCode: input.tierCode,
1091
+ });
1092
+ billingStatus = {
1093
+ subscriptionId: linkResult.subscriptionId,
1094
+ linked: !linkResult.alreadyLinked,
1095
+ tierApplied: linkResult.tierApplied,
1096
+ };
1097
+ }
1098
+ else if (input.tierCode) {
1099
+ // Just apply tier features (no Stripe)
1100
+ const applyResult = await this.tiers.apply(input.tierCode, {
1101
+ companyId,
1102
+ });
1103
+ billingStatus = {
1104
+ tierApplied: applyResult.featuresApplied > 0,
1105
+ };
1106
+ }
946
1107
  }
947
- else if (input.tierCode) {
948
- // Just apply tier features (no Stripe)
949
- const applyResult = await this.tiers.apply(input.tierCode, { companyId });
1108
+ catch (err) {
1109
+ // Billing failed but company is still linked - capture error
950
1110
  billingStatus = {
951
- tierApplied: applyResult.featuresApplied > 0,
1111
+ error: err instanceof Error ? err.message : String(err),
952
1112
  };
953
1113
  }
954
1114
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatarmin/os",
3
- "version": "0.3.3",
3
+ "version": "1.0.0",
4
4
  "description": "Type-safe SDK for ChatarminOS - Customer & Subscription Management",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -11,7 +11,8 @@
11
11
  "exports": {
12
12
  ".": {
13
13
  "types": "./dist/index.d.ts",
14
- "import": "./dist/index.js"
14
+ "import": "./dist/index.js",
15
+ "default": "./dist/index.js"
15
16
  }
16
17
  },
17
18
  "files": [
@@ -23,6 +24,8 @@
23
24
  "dev": "tsc --watch --skipLibCheck",
24
25
  "typecheck": "tsc --noEmit --skipLibCheck",
25
26
  "test": "tsx test-sdk.ts",
27
+ "sync": "tsx scripts/sync-orgs.ts",
28
+ "sync:example": "tsx scripts/sync-orgs.ts ./scripts/data/orgs.example.json --dry-run --verbose",
26
29
  "prepublishOnly": "pnpm build",
27
30
  "release": "./scripts/publish.sh",
28
31
  "release:patch": "./scripts/publish.sh patch",
@@ -31,12 +34,7 @@
31
34
  "release:dry": "npm publish --dry-run"
32
35
  },
33
36
  "keywords": [
34
- "chatarmin",
35
- "sdk",
36
- "billing",
37
- "subscriptions",
38
- "customer-management",
39
- "trpc"
37
+ "chatarmin"
40
38
  ],
41
39
  "author": "Chatarmin GmbH",
42
40
  "license": "MIT",