@gls_spain/gps-common 35.20.0 → 35.21.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/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## [35.21.1](https://github.com/GLS-Spain/gps-common/compare/v35.21.0...v35.21.1) (2026-10-27)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * cambios address ([cd05621](https://github.com/GLS-Spain/gps-common/commit/cd056212a78adaa3c361541e2c6e09e480bffe66))
7
+ * delete comments ([655a5e9](https://github.com/GLS-Spain/gps-common/commit/655a5e9d5610a8725b9406190211ba6786f494d1))
8
+ * fix set.locker no admite null ([e9c4ad9](https://github.com/GLS-Spain/gps-common/commit/e9c4ad9bdf2482032a75b7ff9d9b97f99d62bc45))
9
+
10
+ # [35.21.0](https://github.com/GLS-Spain/gps-common/compare/v35.20.0...v35.21.0) (2026-10-26)
11
+
12
+
13
+ ### Features
14
+
15
+ * esquemas de funciones de tienda y operaciones masivas ([10e9c96](https://github.com/GLS-Spain/gps-common/commit/10e9c9650f97dd7cb92487bd1e9af58e56266470))
16
+
1
17
  # [35.20.0](https://github.com/GLS-Spain/gps-common/compare/v35.19.4...v35.20.0) (2026-10-21)
2
18
 
3
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gls_spain/gps-common",
3
- "version": "35.20.0",
3
+ "version": "35.21.1",
4
4
  "description": "Errors, schemas and documentation for the Parcel Shops project",
5
5
  "keywords": [
6
6
  "gls"
@@ -149,6 +149,14 @@ const shopActivity = () => ({
149
149
  ],
150
150
  });
151
151
 
152
+ // Funciones que se activan o desactivan por tienda desde el admin; el shop solo muestra las que están a true
153
+ const OPTIONS_FEATURES = Object.freeze(['printLabels', 'analytics', 'billing', 'labelReplenishment']);
154
+
155
+ const optionsFeatures = () => ({
156
+ type: 'object',
157
+ properties: Object.fromEntries(OPTIONS_FEATURES.map(feature => [feature, { type: 'boolean', default: false }])),
158
+ additionalProperties: false,
159
+ });
152
160
  function channelingType() {
153
161
  return ['postalCode', 'parcelShop'];
154
162
  }
@@ -274,6 +282,7 @@ const shop = () => ({
274
282
  radical: { type: 'boolean', default: false },
275
283
  operations: { type: ['boolean', 'string'], trim: true },
276
284
  reverseLogistic: { type: 'boolean', default: false },
285
+ optionsFeatures: optionsFeatures(),
277
286
  // 2023-01-12 JL están definidos como string
278
287
  // TODO en el momento que el frontend sea capaz de mandar integer, se quita "string"
279
288
  squareCode: { type: ['integer', 'string'], minimum: 0, maximum: 32767, description: 'agency code' },
@@ -339,7 +348,7 @@ const setShopRepresentative = () => ({
339
348
  additionalProperties: false,
340
349
  });
341
350
 
342
- const createShopRequest = () =>
351
+ const createShopRequest =(address = shop().properties.address) =>
343
352
  createRequest({
344
353
  type: 'object',
345
354
  properties: {
@@ -366,11 +375,13 @@ const createShopRequest = () =>
366
375
  'radical',
367
376
  'operations',
368
377
  'reverseLogistic',
378
+ 'optionsFeatures',
369
379
  'capacity',
370
380
  'squareCode',
371
381
  'clientCode',
372
382
  'channelingAgencyCode',
373
383
  ]),
384
+ address,
374
385
  }, // Shop
375
386
  required: ['network', 'status', 'name', 'address', 'openingSchedule', 'timezone'],
376
387
  additionalProperties: false,
@@ -468,12 +479,24 @@ const findShopsResponse = () => findResponse(shop());
468
479
  // Se usa pattern en vez de minLength porque Ajv valida minLength antes de que trim modifique el dato.
469
480
  const nonEmpty = () => ({ pattern: '\\S' });
470
481
 
482
+ // INN-1333: el backend construye street con streetType + streetName + streetNumber (varchar 255 = 50 + 183 + 20 + 2 espacios)
483
+ const salesforceAddress = baseAddress => ({
484
+ ...baseAddress,
485
+ properties: {
486
+ ...baseAddress.properties,
487
+ streetType: mergeSchemas(baseAddress.properties.streetType, nonEmpty(), { maxLength: 50 }),
488
+ streetName: mergeSchemas(baseAddress.properties.streetName, nonEmpty(), { maxLength: 183 }),
489
+ streetNumber: mergeSchemas(baseAddress.properties.streetNumber, nonEmpty(), { maxLength: 20 }),
490
+ },
491
+ required: [...baseAddress.required.filter(key => key !== 'street'), 'streetType', 'streetName', 'streetNumber'],
492
+ });
493
+
471
494
  const updateShopAddress = () =>
472
495
  mergeSchemas(addressWithRequiredLocation(), {
473
496
  properties: { street: nonEmpty(), postalCode: nonEmpty(), locality: nonEmpty(), country: nonEmpty() },
474
497
  });
475
498
 
476
- const updateShopRequest = () =>
499
+ const updateShopRequest =(address = updateShopAddress()) =>
477
500
  updateRequest(
478
501
  findById(),
479
502
  {
@@ -498,6 +521,7 @@ const updateShopRequest = () =>
498
521
  'radical',
499
522
  'operations',
500
523
  'reverseLogistic',
524
+ 'optionsFeatures',
501
525
  'capacity',
502
526
  'squareCode',
503
527
  'clientCode',
@@ -506,7 +530,7 @@ const updateShopRequest = () =>
506
530
  ['fiscal', 'activity', 'notes', 'derivationSettings', 'expirationSettings'],
507
531
  ),
508
532
  name: mergeSchemas(shop().properties.name, nonEmpty()),
509
- address: updateShopAddress(),
533
+ address,
510
534
  squareCode: mergeSchemas(shop().properties.squareCode, nonEmpty()),
511
535
  clientCode: mergeSchemas(shop().properties.clientCode, nonEmpty()),
512
536
  },
@@ -521,6 +545,9 @@ const updateShopRequest = () =>
521
545
  },
522
546
  );
523
547
 
548
+ const createShopSalesforceRequest = () => createShopRequest(salesforceAddress(shop().properties.address));
549
+ const updateShopSalesforceRequest = () => updateShopRequest(salesforceAddress(updateShopAddress()));
550
+
524
551
  const updateShopResponse = () => updateResponse(shop());
525
552
 
526
553
  const deleteShopRequest = () => deleteRequest(findById());
@@ -590,7 +617,7 @@ const upsertShopResponse = () => ({
590
617
  // lockerNxt() → schema del sub-objeto NXT (provider + location + features + carrier)
591
618
  // lockerNxtUpdate()→ variante de lockerNxt sin lockerId en required (para updates)
592
619
  // createLockerRequest → pickProperties(locker(), [...]) + setShopRepresentative()
593
- // updateLockerRequest → findByStringId() + pickProperties(locker(), [...]) con schemaOrNull
620
+ // updateLockerRequest → findByStringId() + set { parcelshop, locker }
594
621
  // ─────────────────────────────────────────────────────────────────────────────
595
622
 
596
623
  const locker = () => ({
@@ -786,6 +813,7 @@ const createLockerRequest = () =>
786
813
  'capacity_locker',
787
814
  'access_descript_locker',
788
815
  ]),
816
+ address: salesforceAddress(lockerAddress()),
789
817
  },
790
818
  required: [
791
819
  'network',
@@ -813,9 +841,9 @@ const createLockerResponse = () => createResponse(locker());
813
841
  // ── updateLockerRequest ───────────────────────────────────────────────────────
814
842
  // Mismo patrón que updateShopRequest:
815
843
  // - findByStringId() como find (el _id del locker es string numérico, no UUID)
816
- // - pickProperties(locker(), [...]) con schemaOrNull para el set parcial
844
+ // - set.parcelshop: pickProperties(locker(), [...]) con schemaOrNull para el set parcial
817
845
  // - setShopRepresentative() / setShopStatus() para representantes y status
818
- // - lockerNxtUpdate() para el sub-objeto hardware (lockerId no obligatorio)
846
+ // - set.locker: sub-objeto hardware NXT
819
847
 
820
848
  const updateLockerRequest = () =>
821
849
  updateRequest(
@@ -826,65 +854,168 @@ const updateLockerRequest = () =>
826
854
  {
827
855
  type: 'object',
828
856
  properties: {
829
- // relaciones y representantes con helpers reutilizados de shop
830
- network: schemaOrNull(objectWithUuid()),
831
- zone: schemaOrNull(objectWithUuid()),
832
- openingRepresentative: schemaOrNull(setShopRepresentative()),
833
- managingRepresentative: schemaOrNull(setShopRepresentative()),
834
- status: setShopStatus(),
857
+ parcelshop: {
858
+ type: 'object',
859
+ properties: {
860
+ // relaciones y representantes con helpers reutilizados de shop
861
+ network: schemaOrNull(objectWithUuid()),
862
+ zone: schemaOrNull(objectWithUuid()),
863
+ openingRepresentative: schemaOrNull(setShopRepresentative()),
864
+ managingRepresentative: schemaOrNull(setShopRepresentative()),
865
+ // updateLocker también envía status.code
866
+ status: mergeSchemas(setShopStatus(), { properties: { code: shop().properties.status.properties.code } }),
835
867
 
836
- // campos actualizables del schema base locker() — todos con schemaOrNull
837
- ...Object.fromEntries(
838
- Object.entries(
839
- pickProperties(locker(), [
840
- 'name',
841
- 'address',
842
- 'openingSchedule',
843
- 'timezone',
844
- 'activity',
845
- 'eco',
846
- 'fiscal',
847
- 'nxt',
848
- 'direccion_locker',
849
- 'codpostal_locker',
850
- 'ciudad_locker',
851
- 'longitud_locker',
852
- 'latitud_locker',
853
- 'capacity_locker',
854
- 'access_descript_locker',
855
- ]),
856
- ).map(([key, schema]) => [key, schemaOrNull(schema)]),
857
- ),
868
+ // campos actualizables del schema base locker() — todos con schemaOrNull
869
+ ...Object.fromEntries(
870
+ Object.entries(
871
+ pickProperties(locker(), [
872
+ 'name',
873
+ 'openingSchedule',
874
+ 'timezone',
875
+ 'activity',
876
+ 'eco',
877
+ 'fiscal',
878
+ 'nxt',
879
+ 'direccion_locker',
880
+ 'codpostal_locker',
881
+ 'ciudad_locker',
882
+ 'longitud_locker',
883
+ 'latitud_locker',
884
+ 'capacity_locker',
885
+ 'access_descript_locker',
886
+ ]),
887
+ ).map(([key, schema]) => [key, schemaOrNull(schema)]),
888
+ ),
889
+ address: schemaOrNull(salesforceAddress(lockerAddress())),
858
890
 
859
- // capabilities: array, no nullable — va sin schemaOrNull
860
- capabilities: {
861
- type: 'array',
862
- items: { type: 'string', enum: ['deliver', 'pickup', 'sell', 'sellplus'] },
863
- uniqueItems: true,
891
+ // capabilities: array, no nullable — va sin schemaOrNull
892
+ capabilities: {
893
+ type: 'array',
894
+ items: { type: 'string', enum: ['deliver', 'pickup', 'sell', 'sellplus'] },
895
+ uniqueItems: true,
896
+ },
897
+ },
898
+ additionalProperties: false,
864
899
  },
865
900
 
866
- // sub-objeto hardware NXT con variante update (lockerId no obligatorio)
867
- locker: schemaOrNull(lockerNxtUpdate()),
901
+ // sub-objeto hardware NXT: no se validan sus campos
902
+ locker: { type: 'object' },
868
903
  },
869
- minProperties: 0, // permite updates parciales — ningún campo es obligatorio en el set
904
+ minProperties: 0,
870
905
  additionalProperties: false,
871
906
  },
872
907
  );
873
908
 
874
909
  const updateLockerResponse = () => updateResponse(locker());
875
910
 
911
+ // Máximo de tiendas en una lista explícita (buscador o Excel de IDs)
912
+ const PRINT_LABELS_BULK_MAX_SHOP_IDS = 10000;
913
+
914
+ // Id de tienda en las operaciones masivas: no se exige uuid porque hay tiendas antiguas con _id que no lo es, y el
915
+ // backend ya se queda solo con las que existen
916
+ const printLabelsShopId = () => ({ type: 'string', minLength: 1, maxLength: 100 });
917
+
918
+ const printLabelsGroupOf = (type, properties) => ({
919
+ type: 'object',
920
+ properties: { type: { const: type }, ...properties },
921
+ required: ['type', ...Object.keys(properties)],
922
+ additionalProperties: false,
923
+ });
924
+
925
+ // Grupo de tiendas sobre el que se activa o desactiva la impresión de etiquetas
926
+ const printLabelsGroup = () => ({
927
+ oneOf: [
928
+ printLabelsGroupOf('networks', { networkIds: { type: 'array', items: uuid(), minItems: 1, uniqueItems: true } }),
929
+ printLabelsGroupOf('zone', { zoneId: uuid() }),
930
+ printLabelsGroupOf('representative', { representativeIds: { type: 'array', items: uuid(), minItems: 1, uniqueItems: true } }),
931
+ printLabelsGroupOf('shops', {
932
+ shopIds: { type: 'array', items: printLabelsShopId(), minItems: 1, maxItems: PRINT_LABELS_BULK_MAX_SHOP_IDS, uniqueItems: true },
933
+ }),
934
+ ],
935
+ });
936
+
937
+ const printLabelsExcludedShopIds = () => ({ type: 'array', items: printLabelsShopId(), maxItems: PRINT_LABELS_BULK_MAX_SHOP_IDS, uniqueItems: true });
938
+
939
+ // Sin feature/value solo se cuenta el grupo; con ellos, los recuentos y las tiendas de esa función
940
+ const previewPrintLabelsBulkRequest = () => ({
941
+ type: 'object',
942
+ properties: {
943
+ group: printLabelsGroup(),
944
+ feature: { type: 'string', enum: [...OPTIONS_FEATURES] },
945
+ value: { type: 'boolean' },
946
+ excludedShopIds: printLabelsExcludedShopIds(),
947
+ skip: { type: 'integer', minimum: 0, default: 0 },
948
+ limit: { type: 'integer', minimum: 1, maximum: 100, default: 25 },
949
+ },
950
+ required: ['group'],
951
+ dependencies: { feature: ['value'], value: ['feature'] },
952
+ additionalProperties: false,
953
+ });
954
+
955
+ // Valor que se quiere aplicar a cada función ({ printLabels: true, analytics: false }); las que no vienen no se tocan
956
+ const updatePrintLabelsBulkRequest = () => ({
957
+ type: 'object',
958
+ properties: {
959
+ group: printLabelsGroup(),
960
+ features: {
961
+ type: 'object',
962
+ properties: Object.fromEntries(OPTIONS_FEATURES.map(feature => [feature, { type: 'boolean' }])),
963
+ minProperties: 1,
964
+ additionalProperties: false,
965
+ },
966
+ excludedShopIds: printLabelsExcludedShopIds(),
967
+ // Nombre legible del grupo ("Zona Norte", "3 redes"...) para el historial de operaciones
968
+ groupLabel: { type: 'string', trim: true, maxLength: 500 },
969
+ },
970
+ required: ['group', 'features'],
971
+ additionalProperties: false,
972
+ });
973
+
974
+ // Identificadores leídos de un Excel (UUID, ID internacional, código de cliente o CIF/NIF) para traducirlos a tiendas
975
+ const resolvePrintLabelsShopsRequest = () => ({
976
+ type: 'object',
977
+ properties: {
978
+ identifiers: {
979
+ type: 'array',
980
+ items: { type: 'string', trim: true, minLength: 1, maxLength: 100 },
981
+ minItems: 1,
982
+ maxItems: PRINT_LABELS_BULK_MAX_SHOP_IDS,
983
+ },
984
+ },
985
+ required: ['identifiers'],
986
+ additionalProperties: false,
987
+ });
988
+
989
+ // Estado de una operación masiva en curso o terminada (el asistente la consulta para mostrar el progreso)
990
+ const getPrintLabelsBulkOperationRequest = () => ({
991
+ type: 'object',
992
+ properties: {
993
+ operation: {
994
+ type: 'object',
995
+ properties: { _id: uuid() },
996
+ required: ['_id'],
997
+ additionalProperties: false,
998
+ },
999
+ },
1000
+ required: ['operation'],
1001
+ additionalProperties: false,
1002
+ });
1003
+
876
1004
  module.exports = {
1005
+ OPTIONS_FEATURES,
877
1006
  shop,
878
1007
  locker,
879
1008
  lockerNxt,
880
1009
  lockerNxtUpdate,
881
1010
  objectWithShopId,
882
1011
  createShopRequest,
1012
+ createShopSalesforceRequest,
883
1013
  createShopResponse,
884
1014
  findShopsSuperAdminRequest,
885
1015
  findShopsNetworkAdminRequest,
886
1016
  findShopsResponse,
887
1017
  updateShopRequest,
1018
+ updateShopSalesforceRequest,
888
1019
  updateShopResponse,
889
1020
  deleteShopRequest,
890
1021
  deleteShopResponse,
@@ -894,4 +1025,9 @@ module.exports = {
894
1025
  createLockerResponse,
895
1026
  updateLockerRequest,
896
1027
  updateLockerResponse,
1028
+ PRINT_LABELS_BULK_MAX_SHOP_IDS,
1029
+ previewPrintLabelsBulkRequest,
1030
+ updatePrintLabelsBulkRequest,
1031
+ resolvePrintLabelsShopsRequest,
1032
+ getPrintLabelsBulkOperationRequest,
897
1033
  };
package/schemas/index.js CHANGED
@@ -50,11 +50,13 @@ const {
50
50
  } = require('./definitions/networks');
51
51
  const {
52
52
  createShopRequest,
53
+ createShopSalesforceRequest,
53
54
  createShopResponse,
54
55
  findShopsSuperAdminRequest,
55
56
  findShopsNetworkAdminRequest,
56
57
  findShopsResponse,
57
58
  updateShopRequest,
59
+ updateShopSalesforceRequest,
58
60
  updateShopResponse,
59
61
  deleteShopRequest,
60
62
  deleteShopResponse,
@@ -64,6 +66,10 @@ const {
64
66
  createLockerRequest,
65
67
  updateLockerRequest,
66
68
  locker,
69
+ previewPrintLabelsBulkRequest,
70
+ updatePrintLabelsBulkRequest,
71
+ resolvePrintLabelsShopsRequest,
72
+ getPrintLabelsBulkOperationRequest,
67
73
  } = require('./definitions/shops');
68
74
  const {
69
75
  createExpeditionRequest,
@@ -197,14 +203,20 @@ const networkAdminsDeleteRequest = request(deleteNetworkAdminRequest(), 'network
197
203
  const networkAdminsDeleteResponse = response(deleteNetworkAdminResponse(), 'networkAdminsDeleteResponse');
198
204
 
199
205
  const shopsCreateRequest = request(createShopRequest(), 'shopsCreateRequest');
206
+ const shopsSalesforceCreateRequest = request(createShopSalesforceRequest(), 'shopsSalesforceCreateRequest');
200
207
  const shopsCreateResponse = response(createShopResponse(), 'shopsCreateResponse');
201
208
  const shopsFindSuperAdminRequest = request(findShopsSuperAdminRequest(), 'shopsFindSuperAdminRequest');
202
209
  const shopsFindNetworkAdminRequest = request(findShopsNetworkAdminRequest(), 'shopsFindNetworkAdminRequest');
203
210
  const shopsFindResponse = response(findShopsResponse(), 'shopsFindResponse');
204
211
  const shopsUpdateRequest = request(updateShopRequest(), 'shopsUpdateRequest');
212
+ const shopsSalesforceUpdateRequest = request(updateShopSalesforceRequest(), 'shopsSalesforceUpdateRequest');
205
213
  const shopsUpdateResponse = response(updateShopResponse(), 'shopsUpdateResponse');
206
214
  const shopsDeleteRequest = request(deleteShopRequest(), 'shopsDeleteRequest');
207
215
  const shopsDeleteResponse = response(deleteShopResponse(), 'shopsDeleteResponse');
216
+ const shopsPrintLabelsPreviewRequest = request(previewPrintLabelsBulkRequest(), 'shopsPrintLabelsPreviewRequest');
217
+ const shopsPrintLabelsBulkRequest = request(updatePrintLabelsBulkRequest(), 'shopsPrintLabelsBulkRequest');
218
+ const shopsPrintLabelsResolveRequest = request(resolvePrintLabelsShopsRequest(), 'shopsPrintLabelsResolveRequest');
219
+ const shopsPrintLabelsOperationRequest = request(getPrintLabelsBulkOperationRequest(), 'shopsPrintLabelsOperationRequest');
208
220
 
209
221
  const shopUsersCreateRequest = request(createShopUserRequest(), 'shopUsersCreateRequest');
210
222
  const shopUsersCreateResponse = response(createShopUserResponse(), 'shopUsersCreateResponse');
@@ -363,14 +375,20 @@ module.exports = {
363
375
  networkAdminsDeleteResponse,
364
376
 
365
377
  shopsCreateRequest,
378
+ shopsSalesforceCreateRequest,
366
379
  shopsCreateResponse,
367
380
  shopsFindSuperAdminRequest,
368
381
  shopsFindNetworkAdminRequest,
369
382
  shopsFindResponse,
370
383
  shopsUpdateRequest,
384
+ shopsSalesforceUpdateRequest,
371
385
  shopsUpdateResponse,
372
386
  shopsDeleteRequest,
373
387
  shopsDeleteResponse,
388
+ shopsPrintLabelsPreviewRequest,
389
+ shopsPrintLabelsBulkRequest,
390
+ shopsPrintLabelsResolveRequest,
391
+ shopsPrintLabelsOperationRequest,
374
392
 
375
393
  lockersCreateRequest,
376
394
  lockersUpdateRequest,