@proveanything/smartlinks 2.1.16 → 2.1.18

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.
Files changed (60) hide show
  1. package/dist/adminViews.d.ts +85 -0
  2. package/dist/adminViews.js +259 -0
  3. package/dist/api/errors.d.ts +10 -0
  4. package/dist/api/errors.js +17 -0
  5. package/dist/api/index.d.ts +3 -0
  6. package/dist/api/index.js +3 -0
  7. package/dist/api/operations.d.ts +36 -0
  8. package/dist/api/operations.js +56 -0
  9. package/dist/api/order.d.ts +12 -1
  10. package/dist/api/order.js +15 -0
  11. package/dist/api/partner.d.ts +7 -1
  12. package/dist/api/partner.js +9 -0
  13. package/dist/api/userGroups.d.ts +78 -0
  14. package/dist/api/userGroups.js +124 -0
  15. package/dist/docs/API_SUMMARY.md +699 -46
  16. package/dist/docs/admin-views.md +125 -0
  17. package/dist/docs/app-manifest.md +2 -0
  18. package/dist/docs/app-objects.md +23 -0
  19. package/dist/docs/operations.md +281 -0
  20. package/dist/docs/overview.md +3 -0
  21. package/dist/docs/server-functions.md +106 -0
  22. package/dist/docs/tag-ranges.md +8 -0
  23. package/dist/docs/user-groups.md +168 -0
  24. package/dist/docs/utils.md +17 -0
  25. package/dist/http.js +4 -0
  26. package/dist/iframeResponder.d.ts +15 -0
  27. package/dist/iframeResponder.js +39 -1
  28. package/dist/index.d.ts +2 -0
  29. package/dist/index.js +2 -0
  30. package/dist/openapi.yaml +1426 -276
  31. package/dist/testing/index.d.ts +29 -0
  32. package/dist/testing/index.js +178 -1
  33. package/dist/types/appManifest.d.ts +170 -0
  34. package/dist/types/appObjects.d.ts +22 -1
  35. package/dist/types/claimSet.d.ts +2 -0
  36. package/dist/types/clientLog.d.ts +46 -0
  37. package/dist/types/clientLog.js +1 -0
  38. package/dist/types/containers.d.ts +8 -0
  39. package/dist/types/iframeResponder.d.ts +16 -1
  40. package/dist/types/index.d.ts +3 -0
  41. package/dist/types/index.js +3 -0
  42. package/dist/types/operations.d.ts +598 -0
  43. package/dist/types/operations.js +8 -0
  44. package/dist/types/order.d.ts +35 -6
  45. package/dist/types/userGroups.d.ts +103 -0
  46. package/dist/types/userGroups.js +5 -0
  47. package/dist/utils/conditions.d.ts +7 -0
  48. package/dist/utils/conditions.js +16 -9
  49. package/docs/API_SUMMARY.md +699 -46
  50. package/docs/admin-views.md +125 -0
  51. package/docs/app-manifest.md +2 -0
  52. package/docs/app-objects.md +23 -0
  53. package/docs/operations.md +281 -0
  54. package/docs/overview.md +3 -0
  55. package/docs/server-functions.md +106 -0
  56. package/docs/tag-ranges.md +8 -0
  57. package/docs/user-groups.md +168 -0
  58. package/docs/utils.md +17 -0
  59. package/openapi.yaml +1426 -276
  60. package/package.json +1 -1
@@ -10,16 +10,38 @@
10
10
  export interface OrderItem {
11
11
  id: string;
12
12
  orderId: string;
13
- itemType: 'tag' | 'proof' | 'serial';
13
+ itemType: 'tag' | 'proof' | 'serial' | 'product';
14
14
  itemId: string;
15
15
  collectionId?: string;
16
16
  productId?: string;
17
17
  variantId?: string | null;
18
18
  batchId?: string | null;
19
+ quantity: number;
20
+ unit?: string | null;
21
+ quantityDone: number;
22
+ dueAt?: string | null;
19
23
  metadata: Record<string, any>;
20
24
  createdAt: string;
21
25
  order?: OrderSummary;
22
26
  }
27
+ /** Which way an order goes: 'sales' = someone wants it from us; 'purchase' = we want it from a supplier. */
28
+ export type OrderDirection = 'sales' | 'purchase';
29
+ /** One identified thing on an order. */
30
+ export interface OrderItemInput {
31
+ itemType: 'tag' | 'proof' | 'serial';
32
+ itemId: string;
33
+ metadata?: Record<string, any>;
34
+ }
35
+ /** A line of quantity: so many of a product. */
36
+ export interface OrderQuantityLineInput {
37
+ itemType?: 'product';
38
+ productId: string;
39
+ variantId?: string;
40
+ quantity: number;
41
+ unit?: string;
42
+ dueAt?: string;
43
+ metadata?: Record<string, any>;
44
+ }
23
45
  /**
24
46
  * Summary of order details (included with items when requested).
25
47
  */
@@ -40,6 +62,9 @@ export interface Order {
40
62
  orderRef?: string;
41
63
  customerId?: string;
42
64
  status: string;
65
+ direction: OrderDirection;
66
+ partyId?: string | null;
67
+ dueAt?: string | null;
43
68
  itemCount: number;
44
69
  metadata: {
45
70
  productSummary?: Record<string, number>;
@@ -53,11 +78,10 @@ export interface Order {
53
78
  * Request to create a new order with items.
54
79
  */
55
80
  export interface CreateOrderRequest {
56
- items: Array<{
57
- itemType: 'tag' | 'proof' | 'serial';
58
- itemId: string;
59
- metadata?: Record<string, any>;
60
- }>;
81
+ items: Array<OrderItemInput | OrderQuantityLineInput>;
82
+ direction?: OrderDirection;
83
+ partyId?: string;
84
+ dueAt?: string;
61
85
  orderRef?: string;
62
86
  customerId?: string;
63
87
  status?: string;
@@ -84,6 +108,9 @@ export interface GetOrderResponse extends Order {
84
108
  * Items are managed separately via add/remove endpoints.
85
109
  */
86
110
  export interface UpdateOrderRequest {
111
+ direction?: OrderDirection;
112
+ partyId?: string | null;
113
+ dueAt?: string | null;
87
114
  orderRef?: string;
88
115
  customerId?: string;
89
116
  status?: string;
@@ -109,6 +136,8 @@ export interface ListOrdersRequest {
109
136
  status?: string;
110
137
  orderRef?: string;
111
138
  customerId?: string;
139
+ direction?: OrderDirection;
140
+ partyId?: string;
112
141
  includeItems?: boolean;
113
142
  }
114
143
  /**
@@ -0,0 +1,103 @@
1
+ /**
2
+ * User groups: named lists of people in a collection ("QC Controllers", "Warehouse", "Approved
3
+ * partners"), used to say who may do what. See docs/user-groups.md.
4
+ */
5
+ /** A user group. Apps may keep extra fields on it; the ones below are the platform's. */
6
+ export interface UserGroup {
7
+ /** Random id. Never changes. */
8
+ id: string;
9
+ collectionId?: string;
10
+ /**
11
+ * The short stable name code uses: `'qc-controller'`. Lowercase letters, digits and hyphens, unique in
12
+ * the collection. Set when the user group is created and kept through a rename. A user group made
13
+ * before keys existed has none until it is next saved.
14
+ */
15
+ key?: string;
16
+ /** What people see. Free to change. */
17
+ name: string;
18
+ description?: string;
19
+ /** User ids of the people in it. */
20
+ members?: string[];
21
+ createdAt?: string;
22
+ updatedAt?: string;
23
+ deleted?: boolean;
24
+ deletedAt?: string | null;
25
+ [extra: string]: any;
26
+ }
27
+ export interface CreateUserGroupRequest {
28
+ name: string;
29
+ /** Optional. Made from the name when absent ("QC Controllers" → `qc-controllers`). */
30
+ key?: string;
31
+ description?: string;
32
+ members?: string[];
33
+ [extra: string]: any;
34
+ }
35
+ /** Any fields to change. `key` can't be changed once set. */
36
+ export interface UpdateUserGroupRequest {
37
+ name?: string;
38
+ description?: string;
39
+ members?: string[];
40
+ [extra: string]: any;
41
+ }
42
+ /** One member, as the admin member list shows them. */
43
+ export interface UserGroupMember {
44
+ uid: string;
45
+ name?: string | null;
46
+ email?: string | null;
47
+ }
48
+ /** Who to add: an existing user id, or an email (found in the collection's logins, or added to them). */
49
+ export type AddUserGroupMemberRequest = {
50
+ userId: string;
51
+ } | {
52
+ email: string;
53
+ name?: string;
54
+ };
55
+ /** A user group a person is in, as `userGroups.ofUser` lists it. */
56
+ export interface UserGroupRef {
57
+ id: string;
58
+ key: string | null;
59
+ name: string | null;
60
+ }
61
+ /** What a signed-in person learns about their own membership (`userGroups.mine`). */
62
+ export interface MyUserGroups {
63
+ /** Keys of the user groups they are in. Use these in code. */
64
+ userGroups: string[];
65
+ /** Ids of the same user groups (older saved conditions refer to ids). */
66
+ userGroupIds: string[];
67
+ }
68
+ /** What kind of change a history entry records. */
69
+ export type UserGroupChangeType = 'usergroup.created' | 'usergroup.renamed' | 'usergroup.deleted' | 'usergroup.member-added' | 'usergroup.member-removed';
70
+ /** One recorded change to a user group (`userGroups.history`). Ids only: no names or emails of people. */
71
+ export interface UserGroupChange {
72
+ id: string;
73
+ /** When it happened (ISO 8601). */
74
+ at: string;
75
+ type: UserGroupChangeType;
76
+ /** The user group's id. */
77
+ entityId: string | null;
78
+ data: {
79
+ userGroupId: string;
80
+ key: string | null;
81
+ name: string | null;
82
+ /** `member-added` / `member-removed`: the person. */
83
+ userId?: string;
84
+ /** `renamed`: what it was called before. */
85
+ previousName?: string | null;
86
+ /** `deleted`: who was in it at the time. */
87
+ members?: string[];
88
+ };
89
+ actorType: string | null;
90
+ /** The admin who made the change, when known. */
91
+ actorId: string | null;
92
+ }
93
+ export interface UserGroupHistoryParams {
94
+ /** Only this user group. */
95
+ userGroupId?: string;
96
+ /** Only changes about this person. */
97
+ userId?: string;
98
+ /** ISO dates. Default: the last 30 days. At most 400 days apart. */
99
+ from?: string;
100
+ to?: string;
101
+ /** Default 100, at most 1000. */
102
+ limit?: number;
103
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * User groups: named lists of people in a collection ("QC Controllers", "Warehouse", "Approved
3
+ * partners"), used to say who may do what. See docs/user-groups.md.
4
+ */
5
+ export {};
@@ -59,6 +59,9 @@ export interface NestedCondition extends BaseCondition {
59
59
  export interface UserCondition extends BaseCondition {
60
60
  type: 'user';
61
61
  userType: 'valid' | 'invalid' | 'owner' | 'admin' | 'group';
62
+ /** `group` only: the user must be in at least one of these user groups (ids or keys). */
63
+ groupIds?: string[];
64
+ /** `group` only: a single user group (id or key). Same as `groupIds: [groupId]`. */
62
65
  groupId?: string;
63
66
  }
64
67
  /**
@@ -232,6 +235,10 @@ export interface UserInfo {
232
235
  valid: boolean;
233
236
  uid?: string;
234
237
  location?: UserLocation;
238
+ /**
239
+ * The user groups this person is in: keys and/or ids. Fill it from `userGroups.mine(collectionId)`
240
+ * (`[...userGroups, ...userGroupIds]`) so a `group` condition can be checked.
241
+ */
235
242
  groups?: string[];
236
243
  }
237
244
  /**
@@ -505,20 +505,27 @@ async function validateUser(condition, params) {
505
505
  hasRoles: !!((_t = params.collection) === null || _t === void 0 ? void 0 : _t.roles),
506
506
  },
507
507
  };
508
- case 'group':
509
- // User is member of specific group
510
- // TODO: Implement group membership check
508
+ case 'group': {
509
+ // The user is signed in and in at least one of the named user groups (matched by id or key).
510
+ // A condition that names no user group passes nobody. This only shows or hides: what must be
511
+ // protected is limited on the server (a function's `userGroups`).
512
+ const wanted = [
513
+ ...(Array.isArray(condition.groupIds) ? condition.groupIds : []),
514
+ ...(condition.groupId ? [condition.groupId] : []),
515
+ ].filter((g) => typeof g === 'string' && g);
516
+ const mine = Array.isArray((_u = params.user) === null || _u === void 0 ? void 0 : _u.groups) ? params.user.groups : [];
511
517
  return {
512
- passed: !!(params.collection &&
513
- ((_u = params.user) === null || _u === void 0 ? void 0 : _u.valid) &&
514
- params.user.groups),
515
- detail: 'Group condition currently checks only that groups are present on the user.',
518
+ passed: !!(((_v = params.user) === null || _v === void 0 ? void 0 : _v.valid) && wanted.length && wanted.some((g) => mine.includes(g))),
519
+ detail: wanted.length
520
+ ? 'Group check passes when the signed-in user is in at least one of the named user groups.'
521
+ : 'Group condition names no user group, so nobody passes.',
516
522
  context: {
517
- groupId: condition.groupId,
518
- groups: (_v = params.user) === null || _v === void 0 ? void 0 : _v.groups,
523
+ groupIds: wanted,
524
+ groups: mine,
519
525
  userValid: (_x = (_w = params.user) === null || _w === void 0 ? void 0 : _w.valid) !== null && _x !== void 0 ? _x : false,
520
526
  },
521
527
  };
528
+ }
522
529
  default:
523
530
  return {
524
531
  passed: true,