@back23/promptly-sdk 2.0.1 → 2.2.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.mjs CHANGED
@@ -184,8 +184,8 @@ var HttpClient = class {
184
184
  /**
185
185
  * DELETE request
186
186
  */
187
- delete(endpoint) {
188
- return this.request(endpoint, { method: "DELETE" });
187
+ delete(endpoint, params) {
188
+ return this.request(endpoint, { method: "DELETE", params });
189
189
  }
190
190
  /**
191
191
  * Upload file
@@ -351,29 +351,29 @@ var BoardsResource = class {
351
351
  * @returns ListResponse with data array (always defined) and pagination meta
352
352
  */
353
353
  async list(params) {
354
- return this.http.getList("/public/boards", params);
354
+ return this.http.getList("/boards", params);
355
355
  }
356
356
  /**
357
357
  * Get board by ID or slug
358
358
  */
359
359
  async get(idOrSlug) {
360
- return this.http.get(`/public/boards/${idOrSlug}`);
360
+ return this.http.get(`/boards/${idOrSlug}`);
361
361
  }
362
362
  // ============================================
363
- // Posts (Public)
363
+ // Posts
364
364
  // ============================================
365
365
  /**
366
366
  * List posts in a board
367
367
  * @returns ListResponse with data array and pagination meta
368
368
  */
369
369
  async listPosts(boardIdOrSlug, params) {
370
- return this.http.getList(`/public/boards/${boardIdOrSlug}/posts`, params);
370
+ return this.http.getList(`/boards/${boardIdOrSlug}/posts`, params);
371
371
  }
372
372
  /**
373
373
  * Get post by ID
374
374
  */
375
375
  async getPost(postId) {
376
- return this.http.get(`/public/posts/${postId}`);
376
+ return this.http.get(`/posts/${postId}`);
377
377
  }
378
378
  // ============================================
379
379
  // Posts (Protected - requires auth)
@@ -404,7 +404,7 @@ var BoardsResource = class {
404
404
  * @returns Array of comments (always an array, never null/undefined)
405
405
  */
406
406
  async listComments(postId) {
407
- const response = await this.http.getList(`/public/posts/${postId}/comments`);
407
+ const response = await this.http.getList(`/posts/${postId}/comments`);
408
408
  return response.data;
409
409
  }
410
410
  /**
@@ -437,26 +437,26 @@ var BlogResource = class {
437
437
  * @returns ListResponse with data array (always defined) and pagination meta
438
438
  */
439
439
  async list(params) {
440
- return this.http.getList("/public/blog", params);
440
+ return this.http.getList("/blog", params);
441
441
  }
442
442
  /**
443
443
  * Get blog post by slug
444
444
  */
445
445
  async get(slug) {
446
- return this.http.get(`/public/blog/${slug}`);
446
+ return this.http.get(`/blog/${slug}`);
447
447
  }
448
448
  /**
449
449
  * Get blog post by ID
450
450
  */
451
451
  async getById(id) {
452
- return this.http.get(`/public/blog/id/${id}`);
452
+ return this.http.get(`/blog/id/${id}`);
453
453
  }
454
454
  /**
455
455
  * Get featured blog posts
456
456
  * @returns Array of featured posts (always an array, never null/undefined)
457
457
  */
458
458
  async featured(limit = 5) {
459
- const response = await this.http.getList("/public/blog", {
459
+ const response = await this.http.getList("/blog", {
460
460
  per_page: limit,
461
461
  featured: true
462
462
  });
@@ -467,7 +467,7 @@ var BlogResource = class {
467
467
  * @returns ListResponse with data array and pagination meta
468
468
  */
469
469
  async byCategory(category, params) {
470
- return this.http.getList("/public/blog", {
470
+ return this.http.getList("/blog", {
471
471
  ...params,
472
472
  category
473
473
  });
@@ -477,7 +477,7 @@ var BlogResource = class {
477
477
  * @returns ListResponse with data array and pagination meta
478
478
  */
479
479
  async byTag(tag, params) {
480
- return this.http.getList("/public/blog", {
480
+ return this.http.getList("/blog", {
481
481
  ...params,
482
482
  tag
483
483
  });
@@ -487,7 +487,7 @@ var BlogResource = class {
487
487
  * @returns ListResponse with data array and pagination meta
488
488
  */
489
489
  async search(query, params) {
490
- return this.http.getList("/public/blog", {
490
+ return this.http.getList("/blog", {
491
491
  ...params,
492
492
  search: query
493
493
  });
@@ -497,7 +497,7 @@ var BlogResource = class {
497
497
  * @returns Array of category names (always an array)
498
498
  */
499
499
  async categories() {
500
- const response = await this.http.get("/public/blog/categories");
500
+ const response = await this.http.get("/blog/categories");
501
501
  return Array.isArray(response) ? response : response?.data ?? [];
502
502
  }
503
503
  /**
@@ -505,7 +505,7 @@ var BlogResource = class {
505
505
  * @returns Array of tag names (always an array)
506
506
  */
507
507
  async tags() {
508
- const response = await this.http.get("/public/blog/tags");
508
+ const response = await this.http.get("/blog/tags");
509
509
  return Array.isArray(response) ? response : response?.data ?? [];
510
510
  }
511
511
  };
@@ -520,19 +520,19 @@ var FormsResource = class {
520
520
  * @returns ListResponse with data array and pagination meta
521
521
  */
522
522
  async list(params) {
523
- return this.http.getList("/public/forms", params);
523
+ return this.http.getList("/forms", params);
524
524
  }
525
525
  /**
526
526
  * Get form by ID or slug
527
527
  */
528
528
  async get(idOrSlug) {
529
- return this.http.get(`/public/forms/${idOrSlug}`);
529
+ return this.http.get(`/forms/${idOrSlug}`);
530
530
  }
531
531
  /**
532
532
  * Submit form data
533
533
  */
534
534
  async submit(formIdOrSlug, data) {
535
- return this.http.post(`/public/forms/${formIdOrSlug}/submit`, data);
535
+ return this.http.post(`/forms/${formIdOrSlug}/submit`, data);
536
536
  }
537
537
  // ============================================
538
538
  // Protected endpoints (requires auth)
@@ -565,20 +565,20 @@ var ShopResource = class {
565
565
  * @returns ListResponse with data array and pagination meta
566
566
  */
567
567
  async listProducts(params) {
568
- return this.http.getList("/public/products", params);
568
+ return this.http.getList("/products", params);
569
569
  }
570
570
  /**
571
571
  * Get product by ID or slug
572
572
  */
573
573
  async getProduct(idOrSlug) {
574
- return this.http.get(`/public/products/${idOrSlug}`);
574
+ return this.http.get(`/products/${idOrSlug}`);
575
575
  }
576
576
  /**
577
577
  * Get featured products
578
578
  * @returns Array of featured products (always an array)
579
579
  */
580
580
  async featuredProducts(limit = 8) {
581
- const response = await this.http.getList("/public/products", {
581
+ const response = await this.http.getList("/products", {
582
582
  per_page: limit,
583
583
  is_featured: true
584
584
  });
@@ -589,7 +589,7 @@ var ShopResource = class {
589
589
  * @returns ListResponse with data array and pagination meta
590
590
  */
591
591
  async searchProducts(query, params) {
592
- return this.http.getList("/public/products", {
592
+ return this.http.getList("/products", {
593
593
  ...params,
594
594
  search: query
595
595
  });
@@ -602,21 +602,21 @@ var ShopResource = class {
602
602
  * @returns Array of categories (always an array)
603
603
  */
604
604
  async listCategories() {
605
- const response = await this.http.getList("/public/categories");
605
+ const response = await this.http.getList("/categories");
606
606
  return response.data;
607
607
  }
608
608
  /**
609
609
  * Get category by ID or slug
610
610
  */
611
611
  async getCategory(idOrSlug) {
612
- return this.http.get(`/public/categories/${idOrSlug}`);
612
+ return this.http.get(`/categories/${idOrSlug}`);
613
613
  }
614
614
  /**
615
615
  * Get products in category
616
616
  * @returns ListResponse with data array and pagination meta
617
617
  */
618
618
  async categoryProducts(categoryIdOrSlug, params) {
619
- return this.http.getList(`/public/categories/${categoryIdOrSlug}/products`, params);
619
+ return this.http.getList(`/categories/${categoryIdOrSlug}/products`, params);
620
620
  }
621
621
  // ============================================
622
622
  // Cart
@@ -776,36 +776,101 @@ var EntitiesResource = class {
776
776
  this.http = http;
777
777
  }
778
778
  // ============================================
779
- // Entities (Public)
779
+ // Entity Definitions CRUD
780
780
  // ============================================
781
781
  /**
782
- * List all active custom entities
783
- * @returns Array of entities (always an array)
782
+ * List all custom entities
783
+ * @returns Array of entities
784
784
  *
785
785
  * @example
786
786
  * ```typescript
787
787
  * const entities = await client.entities.list();
788
- * // [{ id: 1, name: 'Customer', slug: 'customer', ... }]
788
+ * // [{ id: 1, name: 'Customer', slug: 'customer', records_count: 150, ... }]
789
789
  * ```
790
790
  */
791
791
  async list() {
792
- const response = await this.http.getList("/public/entities");
792
+ const response = await this.http.getList("/entities");
793
793
  return response.data;
794
794
  }
795
795
  /**
796
- * Get entity schema by slug
796
+ * Create a new entity definition
797
797
  *
798
798
  * @example
799
799
  * ```typescript
800
- * const schema = await client.entities.getSchema('customer');
801
- * // { fields: [{ name: 'company', label: '회사명', type: 'text', ... }] }
800
+ * const entity = await client.entities.create({
801
+ * name: '고객',
802
+ * slug: 'customers', // optional, auto-generated from name
803
+ * description: '고객 관리',
804
+ * schema: {
805
+ * fields: [
806
+ * { name: 'company', label: '회사명', type: 'text', required: true },
807
+ * { name: 'email', label: '이메일', type: 'email', required: true },
808
+ * { name: 'status', label: '상태', type: 'select', options: [
809
+ * { value: 'active', label: '활성' },
810
+ * { value: 'inactive', label: '비활성' }
811
+ * ]}
812
+ * ]
813
+ * },
814
+ * icon: 'users'
815
+ * });
816
+ * ```
817
+ */
818
+ async create(data) {
819
+ return this.http.post("/entities", data);
820
+ }
821
+ /**
822
+ * Get entity definition by slug (includes schema)
823
+ *
824
+ * @example
825
+ * ```typescript
826
+ * const entity = await client.entities.get('customers');
827
+ * console.log(entity.schema.fields);
828
+ * ```
829
+ */
830
+ async get(slug) {
831
+ return this.http.get(`/entities/${slug}`);
832
+ }
833
+ /**
834
+ * Update an entity definition
835
+ *
836
+ * @example
837
+ * ```typescript
838
+ * const updated = await client.entities.update('customers', {
839
+ * name: '고객사',
840
+ * description: '고객사 관리'
841
+ * });
802
842
  * ```
803
843
  */
844
+ async update(slug, data) {
845
+ return this.http.put(`/entities/${slug}`, data);
846
+ }
847
+ /**
848
+ * Delete an entity definition
849
+ * If entity has records, use force=true to delete anyway
850
+ *
851
+ * @example
852
+ * ```typescript
853
+ * // Will fail if entity has records
854
+ * await client.entities.delete('customers');
855
+ *
856
+ * // Force delete with all records
857
+ * await client.entities.delete('customers', true);
858
+ * ```
859
+ */
860
+ async delete(slug, force = false) {
861
+ const params = force ? { force: "true" } : void 0;
862
+ return this.http.delete(`/entities/${slug}`, params);
863
+ }
864
+ /**
865
+ * Get entity schema (convenience method)
866
+ * @deprecated Use get(slug) instead - it includes schema
867
+ */
804
868
  async getSchema(slug) {
805
- return this.http.get(`/public/entities/${slug}/schema`);
869
+ const entity = await this.get(slug);
870
+ return entity.schema;
806
871
  }
807
872
  // ============================================
808
- // Records (Public Read)
873
+ // Records CRUD
809
874
  // ============================================
810
875
  /**
811
876
  * List records for an entity
@@ -814,82 +879,79 @@ var EntitiesResource = class {
814
879
  * @example
815
880
  * ```typescript
816
881
  * // Basic listing
817
- * const customers = await client.entities.listRecords('customer');
882
+ * const customers = await client.entities.listRecords('customers');
818
883
  *
819
- * // With pagination
820
- * const customers = await client.entities.listRecords('customer', {
884
+ * // With pagination and search
885
+ * const customers = await client.entities.listRecords('customers', {
821
886
  * page: 1,
822
887
  * per_page: 20,
823
- * status: 'active',
888
+ * search: 'ACME',
889
+ * sort: 'company',
890
+ * dir: 'asc'
824
891
  * });
825
892
  *
826
- * // With filtering by data fields
827
- * const vipCustomers = await client.entities.listRecords('customer', {
828
- * 'data.tier': 'vip',
893
+ * // With filtering
894
+ * const vipCustomers = await client.entities.listRecords('customers', {
895
+ * filters: JSON.stringify({ tier: 'vip' })
829
896
  * });
830
897
  * ```
831
898
  */
832
899
  async listRecords(slug, params) {
833
- return this.http.getList(`/public/entities/${slug}`, params);
900
+ return this.http.getList(`/entities/${slug}/records`, params);
834
901
  }
835
902
  /**
836
903
  * Get a single record by ID
837
904
  *
838
905
  * @example
839
906
  * ```typescript
840
- * const customer = await client.entities.getRecord('customer', 1);
907
+ * const customer = await client.entities.getRecord('customers', 1);
841
908
  * console.log(customer.data.company); // 'ABC Corp'
842
909
  * ```
843
910
  */
844
911
  async getRecord(slug, id) {
845
- return this.http.get(`/public/entities/${slug}/${id}`);
912
+ return this.http.get(`/entities/${slug}/records/${id}`);
846
913
  }
847
- // ============================================
848
- // Records (Protected - requires auth)
849
- // ============================================
850
914
  /**
851
915
  * Create a new record
916
+ * Request body fields are defined by entity schema
852
917
  *
853
918
  * @example
854
919
  * ```typescript
855
- * const newCustomer = await client.entities.createRecord('customer', {
856
- * data: {
857
- * company: 'ABC Corp',
858
- * email: 'contact@abc.com',
859
- * tier: 'standard',
860
- * },
861
- * status: 'active',
920
+ * const newCustomer = await client.entities.createRecord('customers', {
921
+ * company: 'ABC Corp',
922
+ * email: 'contact@abc.com',
923
+ * tier: 'standard',
862
924
  * });
863
925
  * ```
864
926
  */
865
927
  async createRecord(slug, data) {
866
- return this.http.post(`/entities/${slug}`, data);
928
+ return this.http.post(`/entities/${slug}/records`, data);
867
929
  }
868
930
  /**
869
931
  * Update a record
932
+ * Only provided fields will be updated, existing data is preserved
870
933
  *
871
934
  * @example
872
935
  * ```typescript
873
- * const updated = await client.entities.updateRecord('customer', 1, {
874
- * data: {
875
- * tier: 'vip',
876
- * },
936
+ * const updated = await client.entities.updateRecord('customers', 1, {
937
+ * tier: 'vip',
938
+ * email: 'new@abc.com'
877
939
  * });
878
940
  * ```
879
941
  */
880
942
  async updateRecord(slug, id, data) {
881
- return this.http.put(`/entities/${slug}/${id}`, data);
943
+ return this.http.put(`/entities/${slug}/records/${id}`, data);
882
944
  }
883
945
  /**
884
946
  * Delete a record
885
947
  *
886
948
  * @example
887
949
  * ```typescript
888
- * await client.entities.deleteRecord('customer', 1);
950
+ * await client.entities.deleteRecord('customers', 1);
889
951
  * ```
890
952
  */
891
953
  async deleteRecord(slug, id) {
892
- return this.http.delete(`/entities/${slug}/${id}`);
954
+ return this.http.delete(`/entities/${slug}/records/${id}`);
893
955
  }
894
956
  // ============================================
895
957
  // Helper Methods
@@ -899,7 +961,7 @@ var EntitiesResource = class {
899
961
  *
900
962
  * @example
901
963
  * ```typescript
902
- * const record = await client.entities.getRecord('customer', 1);
964
+ * const record = await client.entities.getRecord('customers', 1);
903
965
  * const company = client.entities.getValue(record, 'company');
904
966
  * ```
905
967
  */
@@ -917,7 +979,7 @@ var EntitiesResource = class {
917
979
  * tier: 'standard' | 'vip';
918
980
  * }
919
981
  *
920
- * const customers = client.entities.typed<Customer>('customer');
982
+ * const customers = client.entities.typed<Customer>('customers');
921
983
  * const list = await customers.list(); // Typed records
922
984
  * const record = await customers.get(1);
923
985
  * console.log(record.data.company); // TypeScript knows this is string
@@ -936,12 +998,12 @@ var EntitiesResource = class {
936
998
  const record = await this.getRecord(slug, id);
937
999
  return record;
938
1000
  },
939
- create: async (data, status) => {
940
- const record = await this.createRecord(slug, { data, status });
1001
+ create: async (data) => {
1002
+ const record = await this.createRecord(slug, data);
941
1003
  return record;
942
1004
  },
943
- update: async (id, data, status) => {
944
- const record = await this.updateRecord(slug, id, { data, status });
1005
+ update: async (id, data) => {
1006
+ const record = await this.updateRecord(slug, id, data);
945
1007
  return record;
946
1008
  },
947
1009
  delete: (id) => this.deleteRecord(slug, id)
@@ -962,14 +1024,14 @@ var ReservationResource = class {
962
1024
  * @returns Reservation settings for the tenant
963
1025
  */
964
1026
  async getSettings() {
965
- return this.http.get("/public/reservation/settings");
1027
+ return this.http.get("/reservation/settings");
966
1028
  }
967
1029
  /**
968
1030
  * List available services
969
1031
  * @returns Array of services (always an array)
970
1032
  */
971
1033
  async listServices() {
972
- const response = await this.http.getList("/public/reservation/services");
1034
+ const response = await this.http.getList("/reservation/services");
973
1035
  return response.data;
974
1036
  }
975
1037
  /**
@@ -979,7 +1041,7 @@ var ReservationResource = class {
979
1041
  */
980
1042
  async listStaff(serviceId) {
981
1043
  const params = serviceId ? { service_id: serviceId } : void 0;
982
- const response = await this.http.getList("/public/reservation/staffs", params);
1044
+ const response = await this.http.getList("/reservation/staffs", params);
983
1045
  return response.data;
984
1046
  }
985
1047
  /**
@@ -987,7 +1049,7 @@ var ReservationResource = class {
987
1049
  * @returns Array of available date strings (YYYY-MM-DD)
988
1050
  */
989
1051
  async getAvailableDates(params) {
990
- const response = await this.http.get("/public/reservation/available-dates", params);
1052
+ const response = await this.http.get("/reservation/available-dates", params);
991
1053
  return Array.isArray(response) ? response : response?.data ?? [];
992
1054
  }
993
1055
  /**
@@ -995,7 +1057,7 @@ var ReservationResource = class {
995
1057
  * @returns Array of available slots (always an array)
996
1058
  */
997
1059
  async getAvailableSlots(params) {
998
- const response = await this.http.get("/public/reservation/available-slots", params);
1060
+ const response = await this.http.get("/reservation/available-slots", params);
999
1061
  return Array.isArray(response) ? response : response?.data ?? [];
1000
1062
  }
1001
1063
  // ============================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@back23/promptly-sdk",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
4
4
  "description": "Promptly AI CMS SDK for JavaScript/TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",